From aaa1f375bc9d6a6a175819fac34d39202f69a166 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Mon, 25 Jul 2011 15:40:58 +0100 Subject: 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 --- src/com/android/browser/BrowserSettings.java | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/com/android/browser/BrowserSettings.java') diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index a4f0f044b..2023ee61e 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -103,7 +103,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private WebStorageSizeManager mWebStorageSizeManager; private AutofillHandler mAutofillHandler; private WeakHashMap 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 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, // Cached settings private SearchEngine mSearchEngine; + private static String sFactoryResetUrl; + public static void initialize(final Context context) { sInstance = new BrowserSettings(context); } @@ -199,21 +201,28 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } 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 class BrowserSettings implements OnSharedPreferenceChangeListener, } 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() { -- cgit v1.2.3