Skip to content

save and restore the chrome session local storage information#53030

Merged
devoncarew merged 3 commits intoflutter:masterfrom
devoncarew:chrome_session_local_storage
Mar 24, 2020
Merged

save and restore the chrome session local storage information#53030
devoncarew merged 3 commits intoflutter:masterfrom
devoncarew:chrome_session_local_storage

Conversation

@devoncarew
Copy link
Contributor

Description

This PR saves and restores the chrome session local storage information for flutter web chrome devices. When running chrome devices, we already save and restore the userDataDir preferences file, containing things like the window size and location. This PR also saves are restores the local storage info for web apps, allowing the local storage info to persist across app runs.

Related Issues

None, but this addresses an issue found while developing DevTools. I'll link the PR in here once that work is complete.

Tests

I updated the following tests:

  • flutter_tools/test/general.shard/web/chrome_test.dart: 'can seed chrome temp directory with existing preferences' (renamed to 'can seed chrome temp directory with existing session data')

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 22, 2020
destinationFile.parent.createSync(recursive: true);
savedPreferencesFile.copySync(destinationFile.path);
}
final Directory userDataDir = _fileSystem.systemTempDirectory.createTempSync('flutter_tool.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool already creates a few other temp directories with the prefix flutter_tool or flutter_tools, so it might be helpful to have a more specific name for this. Maybe 'flutter_tools_chrome_device.'? Longer term, we can have a more organized way of writing to system temp. I filed #53104 to track.

Copy link
Contributor Author

@devoncarew devoncarew Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change the name (note however that this is the name used by the existing code).

targetPreferencesFile.parent.createSync(recursive: true);
// If the file contains a crash string, remove it to hide the popup on next run.
final String contents = sourcePreferencesFile.readAsStringSync();
targetPreferencesFile.writeAsStringSync(contents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a link you can add in a comment either describing the schema of this file, or at least of this field?

Also, is there a test for the find/replace?

Copy link
Contributor Author

@devoncarew devoncarew Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe there's a schema. The existing test (this portion of the PR is existing code) does contain a check for the find / replace for the crash string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one of file locations by reading chrome source, we could link to that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link it here, and I'll add to the PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find it, It might have just been grepping the user data dir for strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some info here: https://www.chromium.org/developers/design-documents/preferences; will in-line into the source code.

@devoncarew
Copy link
Contributor Author

ptal - updated based on review comments

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@devoncarew devoncarew merged commit d6614db into flutter:master Mar 24, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants