Cache the factory reset URL.
Hitting the browser provider for the factory reset url is one of
our most common strict mode violations, and triggers sqlite disk
io. So now read it once in a background thread and cache it for
future accesses.
Needed to make the requireInitialization() function static, so we
now wait/notify on BrowserSettings.class rather than the instance.
Bug:5072979
Change-Id: I78550965887e32b4f8ad0eaf0013753e63d6f602
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index a4f0f04..2023ee6 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -103,7 +103,7 @@
private WebStorageSizeManager mWebStorageSizeManager;
private AutofillHandler mAutofillHandler;
private WeakHashMap<WebSettings, String> mCustomUserAgents;
- private boolean mInitialized = false;
+ private static boolean sInitialized = false;
// Looper shared between some lightweight background operations
// Specifically, this is created on the thread that initializes browser settings
// and is then reused by CrashRecoveryHandler
@@ -116,6 +116,8 @@
// Cached settings
private SearchEngine mSearchEngine;
+ private static String sFactoryResetUrl;
+
public static void initialize(final Context context) {
sInstance = new BrowserSettings(context);
}
@@ -199,21 +201,28 @@
}
mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
}
+
+ sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
+ if (sFactoryResetUrl.indexOf("{CID}") != -1) {
+ sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
+ BrowserProvider.getClientId(mContext.getContentResolver()));
+ }
+
Looper.prepare();
mBackgroundLooper = Looper.myLooper();
- synchronized (BrowserSettings.this) {
- mInitialized = true;
- BrowserSettings.this.notifyAll();
+ synchronized (BrowserSettings.class) {
+ sInitialized = true;
+ BrowserSettings.class.notifyAll();
}
Looper.loop();
}
};
- void requireInitialization() {
- synchronized (BrowserSettings.this) {
- while (!mInitialized) {
+ private static void requireInitialization() {
+ synchronized (BrowserSettings.class) {
+ while (!sInitialized) {
try {
- BrowserSettings.this.wait();
+ BrowserSettings.class.wait();
} catch (InterruptedException e) {
}
}
@@ -334,12 +343,8 @@
}
public static String getFactoryResetHomeUrl(Context context) {
- String url = context.getResources().getString(R.string.homepage_base);
- if (url.indexOf("{CID}") != -1) {
- url = url.replace("{CID}",
- BrowserProvider.getClientId(context.getContentResolver()));
- }
- return url;
+ requireInitialization();
+ return sFactoryResetUrl;
}
public LayoutAlgorithm getLayoutAlgorithm() {