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-09 14:03:53 -04:00
Родитель cd02e570d5
Коммит 1bfe9e31be
2 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@ -1169,7 +1169,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 {
@ -1439,6 +1445,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;
@ -1667,7 +1675,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);

Просмотреть файл

@ -146,7 +146,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;
@ -155,14 +155,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) {
@ -295,6 +301,7 @@ public class SuggestedSites {
setCachedSites(sites);
// Save the result to disk.
final File file = getFile();
synchronized (file) {
saveSites(file, sites);
}
@ -338,6 +345,7 @@ public class SuggestedSites {
private Map<String, Site> loadFromProfile() {
try {
final File file = getFile();
synchronized (file) {
return loadSites(file);
}
@ -451,7 +459,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) {