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
This commit is contained in:
Jim Chen 2014-09-30 18:19:25 -04:00
parent 1303551d3c
commit 12d7d71d8f
2 changed files with 23 additions and 7 deletions

View File

@ -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 <http://code.google.com/p/android/issues/detail?id=20915>.
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);

View File

@ -157,7 +157,7 @@ public class SuggestedSites {
final Context context;
final Distribution distribution;
final File file;
private File cachedFile;
private Map<String, Site> cachedSites;
private Set<String> 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<String, Site> 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) {