From f57c029329e874399199259b5e69f4d0b8a12a38 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 21 Jul 2011 18:15:39 -0700 Subject: Startup optimization Bug: 5019676 Save one thread by letting CrashRecoveryHandler re-use the BrowserSettings startup thread Lazy initialize the wake lock only if we need it (avoids IPC overhead at startup) Slight ordering shuffle in BrowserActivity to maximize the usefulness of the BrowserSettings startup thread Change-Id: I1fc7412d492f93e0630008fa6030da9e0d726ebb --- src/com/android/browser/BrowserSettings.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 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 97769fce3..a4f0f044b 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Build; +import android.os.Looper; import android.os.Message; import android.preference.PreferenceManager; import android.provider.Browser; @@ -103,6 +104,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private AutofillHandler mAutofillHandler; private WeakHashMap mCustomUserAgents; private boolean mInitialized = 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 + private Looper mBackgroundLooper; // Cached values private int mPageCacheCapacity = 1; @@ -127,7 +132,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, mCustomUserAgents = new WeakHashMap(); mPrefs.registerOnSharedPreferenceChangeListener(this); mAutofillHandler.asyncLoadFromDb(); - new Thread(mInitialization, "BrowserSettingsInitialization").start(); + new Thread(mSetupAndLoop, "BackgroundLooper").start(); } public void setController(Controller controller) { @@ -139,6 +144,11 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } } + public Looper getBackgroundLooper() { + requireInitialization(); + return mBackgroundLooper; + } + public void startManagingSettings(WebSettings settings) { synchronized (mManagedSettings) { syncStaticSettings(settings); @@ -147,7 +157,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } } - private Runnable mInitialization = new Runnable() { + private Runnable mSetupAndLoop = new Runnable() { @Override public void run() { @@ -189,10 +199,13 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); } + Looper.prepare(); + mBackgroundLooper = Looper.myLooper(); synchronized (BrowserSettings.this) { mInitialized = true; BrowserSettings.this.notifyAll(); } + Looper.loop(); } }; -- cgit v1.2.3