diff options
author | hartmanng <hartmanng@chromium.org> | 2015-11-27 11:20:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-27 19:21:11 +0000 |
commit | f70d99783581291fcac5c603c7862d360caa7b3d (patch) | |
tree | 3f2a72ec007e6dd0fcb914e97ec6fb0134a17d2b | |
parent | 3cd861f0b7d1a8edb3327bf6552f4343e01cd610 (diff) | |
download | chromium_src-f70d99783581291fcac5c603c7862d360caa7b3d.zip chromium_src-f70d99783581291fcac5c603c7862d360caa7b3d.tar.gz chromium_src-f70d99783581291fcac5c603c7862d360caa7b3d.tar.bz2 |
Fix strict mode violation on document mode initialization.
Loading shared prefs requires an async disk access. If it
doesn't finish in time, it can cause the UI thread to block,
violating strict mode. This patch pre-loads the document-mode
shared prefs, as we already do for the main Chrome default
shared prefs, to ensure that it's ready before we need it.
BUG=543201
Review URL: https://codereview.chromium.org/1464313010
Cr-Commit-Position: refs/heads/master@{#362031}
2 files changed, 19 insertions, 2 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java b/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java index f241d57..56ce9ee 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java @@ -22,6 +22,7 @@ import org.chromium.chrome.browser.ChromeStrictMode; import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.FileProviderHelper; import org.chromium.chrome.browser.device.DeviceClassManager; +import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl; import org.chromium.content.app.ContentApplication; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.DeviceUtils; @@ -102,6 +103,15 @@ public class ChromeBrowserInitializer { } + /** + * Pre-load shared prefs to avoid being blocked on the + * disk access async task in the future. + */ + private void warmUpSharedPrefs() { + PreferenceManager.getDefaultSharedPreferences(mApplication); + DocumentTabModelImpl.warmUpSharedPrefs(mApplication); + } + private void preInflationStartup() { ThreadUtils.assertOnUiThread(); if (mPreInflationStartupComplete) return; @@ -113,8 +123,7 @@ public class ChromeBrowserInitializer { waitForDebuggerIfNeeded(); ChromeStrictMode.configureStrictMode(); - // Warm up the shared prefs stored. - PreferenceManager.getDefaultSharedPreferences(mApplication); + warmUpSharedPrefs(); DeviceUtils.addDeviceSpecificUserAgentSwitch(mApplication); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java index e44979e..96fc165 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java @@ -136,6 +136,14 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT private int mLastShownTabId = Tab.INVALID_TAB_ID; /** + * Pre-load shared prefs to avoid being blocked on the + * disk access async task in the future. + */ + public static void warmUpSharedPrefs(Context context) { + context.getSharedPreferences(PREF_PACKAGE, Context.MODE_PRIVATE); + } + + /** * Construct a DocumentTabModel. * @param activityDelegate Delegate to use for accessing the ActivityManager. * @param storageDelegate Delegate to use for accessing persistent storage. |