From 12d7d71d8f5b8951536eac66a436926f8e970598 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 30 Sep 2014 18:19:25 -0400 Subject: [PATCH] Bug 1062377 - Try loading profile.ini in background; r=mfinkle r=rnewman We can move our profile accessing code to later in the startup process. The benefit of that is in early startup, we can prefetch the profile.ini file in the background and not block the UI thread --- mobile/android/base/GeckoApp.java | 12 ++++++++++-- mobile/android/base/db/SuggestedSites.java | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index c7222399a03d..2234097499fa 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1163,7 +1163,13 @@ public abstract class GeckoApp } } - BrowserDB.initialize(getProfile().getName()); + // Speculatively pre-fetch the profile in the background. + ThreadUtils.postToBackgroundThread(new Runnable() { + @Override + public void run() { + getProfile(); + } + }); // Workaround for . try { @@ -1425,6 +1431,8 @@ public abstract class GeckoApp initializeChrome(); + BrowserDB.initialize(getProfile().getName()); + // If we are doing a restore, read the session data and send it to Gecko if (!mIsRestoringActivity) { String restoreMessage = null; @@ -1647,7 +1655,7 @@ public abstract class GeckoApp } } - public GeckoProfile getProfile() { + public synchronized GeckoProfile getProfile() { // fall back to default profile if we didn't load a specific one if (mProfile == null) { mProfile = GeckoProfile.get(this); diff --git a/mobile/android/base/db/SuggestedSites.java b/mobile/android/base/db/SuggestedSites.java index d6cf7b630e10..2a1b88f730dc 100644 --- a/mobile/android/base/db/SuggestedSites.java +++ b/mobile/android/base/db/SuggestedSites.java @@ -157,7 +157,7 @@ public class SuggestedSites { final Context context; final Distribution distribution; - final File file; + private File cachedFile; private Map cachedSites; private Set cachedBlacklist; @@ -166,14 +166,20 @@ public class SuggestedSites { } public SuggestedSites(Context appContext, Distribution distribution) { - this(appContext, distribution, - GeckoProfile.get(appContext).getFile(FILENAME)); + this(appContext, distribution, null); } public SuggestedSites(Context appContext, Distribution distribution, File file) { this.context = appContext; this.distribution = distribution; - this.file = file; + this.cachedFile = file; + } + + synchronized File getFile() { + if (cachedFile == null) { + cachedFile = GeckoProfile.get(context).getFile(FILENAME); + } + return cachedFile; } private static boolean isNewLocale(Context context, Locale requestedLocale) { @@ -306,6 +312,7 @@ public class SuggestedSites { setCachedSites(sites); // Save the result to disk. + final File file = getFile(); synchronized (file) { saveSites(file, sites); } @@ -349,6 +356,7 @@ public class SuggestedSites { private Map loadFromProfile() { try { + final File file = getFile(); synchronized (file) { return loadSites(file); } @@ -462,7 +470,7 @@ public class SuggestedSites { // Force the suggested sites file in profile dir to be re-generated // if the locale has changed. if (isNewLocale) { - file.delete(); + getFile().delete(); } if (cachedSites == null || isNewLocale) {