Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
16daed86
Unverified
Commit
16daed86
authored
Nov 06, 2020
by
Gary Roumanis
Committed by
GitHub
Nov 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Persist Chrome Default Directory (#69921)
parent
a2fd69cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
48 deletions
+33
-48
chrome.dart
packages/flutter_tools/lib/src/web/chrome.dart
+25
-30
chrome_test.dart
...ges/flutter_tools/test/general.shard/web/chrome_test.dart
+8
-18
No files found.
packages/flutter_tools/lib/src/web/chrome.dart
View file @
16daed86
...
...
@@ -296,60 +296,55 @@ class ChromiumLauncher {
}
}
// This is a directory which Chrome uses to store cookies, preferences and
// other session data.
String
get
_chromeDefaultPath
=>
_fileSystem
.
path
.
join
(
'Default'
);
// This is a JSON file which contains configuration from the browser session,
// such as window position. It is located under the Chrome data-dir folder.
String
get
_preferencesPath
=>
_fileSystem
.
path
.
join
(
'Default'
,
'preferences'
);
// The directory that Chrome uses to store local storage information for web apps.
String
get
_localStoragePath
=>
_fileSystem
.
path
.
join
(
'Default'
,
'Local Storage'
);
/// Copy Chrome user information from a Chrome session into a per-project
/// cache.
///
/// Note: more detailed docs of the Chrome user preferences store exists here:
/// https://www.chromium.org/developers/design-documents/preferences.
void
_cacheUserSessionInformation
(
Directory
userDataDir
,
Directory
cacheDir
)
{
final
File
targetPreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_preferencesPath
));
final
File
sourcePreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_preferencesPath
));
final
Directory
targetLocalStorageDir
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_localStoragePath
));
final
Directory
sourceLocalStorageDir
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_localStoragePath
));
final
Directory
targetChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_chromeDefaultPath
));
final
Directory
sourceChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_chromeDefaultPath
));
if
(
sourcePreferencesFile
.
existsSync
())
{
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
.
replaceFirst
(
'"exit_type":"Crashed"'
,
'"exit_type":"Normal"'
));
}
if
(
sourceLocalStorageDir
.
existsSync
())
{
targetLocalStorageDir
.
createSync
(
recursive:
true
);
if
(
sourceChromeDefault
.
existsSync
())
{
targetChromeDefault
.
createSync
(
recursive:
true
);
try
{
_fileSystemUtils
.
copyDirectorySync
(
source
LocalStorageDir
,
targetLocalStorageDir
);
_fileSystemUtils
.
copyDirectorySync
(
source
ChromeDefault
,
targetChromeDefault
);
}
on
FileSystemException
catch
(
err
)
{
// This is a best-effort update. Display the message in case the failure is relevant.
// one possible example is a file lock due to multiple running chrome instances.
_logger
.
printError
(
'Failed to save Chrome preferences:
$err
'
);
}
}
final
File
targetPreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
cacheDir
?.
path
??
''
,
_preferencesPath
));
final
File
sourcePreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_preferencesPath
));
if
(
sourcePreferencesFile
.
existsSync
())
{
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
.
replaceFirst
(
'"exit_type":"Crashed"'
,
'"exit_type":"Normal"'
));
}
}
/// Restore Chrome user information from a per-project cache into Chrome's
/// user data directory.
void
_restoreUserSessionInformation
(
Directory
cacheDir
,
Directory
userDataDir
)
{
final
File
sourcePreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
??
''
,
_preferencesPath
));
final
File
targetPreferencesFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_preferencesPath
));
final
Directory
sourceLocalStorageDir
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
??
''
,
_localStoragePath
));
final
Directory
targetLocalStorageDir
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_localStoragePath
));
if
(
sourcePreferencesFile
.
existsSync
())
{
targetPreferencesFile
.
parent
.
createSync
(
recursive:
true
);
sourcePreferencesFile
.
copySync
(
targetPreferencesFile
.
path
);
}
final
Directory
sourceChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
cacheDir
.
path
??
''
,
_chromeDefaultPath
));
final
Directory
targetChromeDefault
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
userDataDir
.
path
,
_chromeDefaultPath
));
if
(
source
LocalStorageDir
.
existsSync
())
{
target
LocalStorageDir
.
createSync
(
recursive:
true
);
_fileSystemUtils
.
copyDirectorySync
(
source
LocalStorageDir
,
targetLocalStorageDir
);
if
(
source
ChromeDefault
.
existsSync
())
{
target
ChromeDefault
.
createSync
(
recursive:
true
);
_fileSystemUtils
.
copyDirectorySync
(
source
ChromeDefault
,
targetChromeDefault
);
}
}
...
...
packages/flutter_tools/test/general.shard/web/chrome_test.dart
View file @
16daed86
...
...
@@ -5,7 +5,6 @@
import
'dart:async'
;
import
'package:file/memory.dart'
;
import
'package:file_testing/file_testing.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
...
...
@@ -201,13 +200,10 @@ void main() {
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'"exit_type":"Crashed"'
);
final
Directory
localStorageContents
Directory
=
dataDir
final
Directory
defaultContent
Directory
=
dataDir
.
childDirectory
(
'Default'
)
.
childDirectory
(
'Local Storage'
)
.
childDirectory
(
'leveldb'
);
localStorageContentsDirectory
.
createSync
(
recursive:
true
);
localStorageContentsDirectory
.
childFile
(
'LOCK'
).
writeAsBytesSync
(<
int
>[]);
localStorageContentsDirectory
.
childFile
(
'LOG'
).
writeAsStringSync
(
'contents'
);
.
childDirectory
(
'Foo'
);
defaultContentDirectory
.
createSync
(
recursive:
true
);
processManager
.
addCommand
(
FakeCommand
(
command:
const
<
String
>[
...
...
@@ -233,20 +229,14 @@ void main() {
// writes non-crash back to dart_tool
expect
(
preferencesFile
.
readAsStringSync
(),
'"exit_type":"Normal"'
);
// validate local storage
final
Directory
storageDir
=
fileSystem
// validate any Default content is copied
final
Directory
defaultContentDir
=
fileSystem
.
directory
(
'.tmp_rand0/flutter_tools_chrome_device.rand0'
)
.
childDirectory
(
'Default'
)
.
childDirectory
(
'Local Storage'
)
.
childDirectory
(
'leveldb'
);
expect
(
storageDir
.
existsSync
(),
true
);
expect
(
storageDir
.
childFile
(
'LOCK'
),
exists
);
expect
(
storageDir
.
childFile
(
'LOCK'
).
readAsBytesSync
(),
hasLength
(
0
));
.
childDirectory
(
'Foo'
);
expect
(
storageDir
.
childFile
(
'LOG'
),
exists
);
expect
(
storageDir
.
childFile
(
'LOG'
).
readAsStringSync
(),
'contents'
);
expect
(
defaultContentDir
.
existsSync
(),
true
);
});
testWithoutContext
(
'can retry launch when glibc bug happens'
,
()
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment