diff options
author | John Reck <jreck@google.com> | 2011-07-21 13:54:03 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-07-21 13:54:03 -0700 |
commit | 78a6a1d7c2f5666f90222ecc28fcc26740807cb7 (patch) | |
tree | 4bec763bd501a861bbdae9fecd69f72745f0573b | |
parent | 30b065e9c311ab1a8973caeb85a0861c8802b043 (diff) | |
download | packages_apps_Browser-78a6a1d7c2f5666f90222ecc28fcc26740807cb7.zip packages_apps_Browser-78a6a1d7c2f5666f90222ecc28fcc26740807cb7.tar.gz packages_apps_Browser-78a6a1d7c2f5666f90222ecc28fcc26740807cb7.tar.bz2 |
Initialize settings in a thread
Bug: 5062581
Change-Id: I6f10b829918cec1d57eeda3958ef9f76216fcd3a
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 120 |
1 files changed, 76 insertions, 44 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index dcc3269..97769fc 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -102,6 +102,11 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private WebStorageSizeManager mWebStorageSizeManager; private AutofillHandler mAutofillHandler; private WeakHashMap<WebSettings, String> mCustomUserAgents; + private boolean mInitialized = false; + + // Cached values + private int mPageCacheCapacity = 1; + private String mAppCachePath; // Cached settings private SearchEngine mSearchEngine; @@ -117,43 +122,12 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private BrowserSettings(Context context) { mContext = context; mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); - if (Build.VERSION.CODENAME.equals("REL")) { - // This is a release build, always startup with debug disabled - setDebugEnabled(false); - } - if (mPrefs.contains(PREF_TEXT_SIZE)) { - /* - * Update from TextSize enum to zoom percent - * SMALLEST is 50% - * SMALLER is 75% - * NORMAL is 100% - * LARGER is 150% - * LARGEST is 200% - */ - switch (getTextSize()) { - case SMALLEST: - setTextZoom(50); - break; - case SMALLER: - setTextZoom(75); - break; - case LARGER: - setTextZoom(150); - break; - case LARGEST: - setTextZoom(200); - break; - } - mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); - } mAutofillHandler = new AutofillHandler(mContext); mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); mCustomUserAgents = new WeakHashMap<WebSettings, String>(); - mWebStorageSizeManager = new WebStorageSizeManager(mContext, - new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), - new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); mPrefs.registerOnSharedPreferenceChangeListener(this); mAutofillHandler.asyncLoadFromDb(); + new Thread(mInitialization, "BrowserSettingsInitialization").start(); } public void setController(Controller controller) { @@ -173,6 +147,66 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } } + private Runnable mInitialization = new Runnable() { + + @Override + public void run() { + // the cost of one cached page is ~3M (measured using nytimes.com). For + // low end devices, we only cache one page. For high end devices, we try + // to cache more pages, currently choose 5. + if (ActivityManager.staticGetMemoryClass() > 16) { + mPageCacheCapacity = 5; + } + mWebStorageSizeManager = new WebStorageSizeManager(mContext, + new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()), + new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath())); + if (Build.VERSION.CODENAME.equals("REL")) { + // This is a release build, always startup with debug disabled + setDebugEnabled(false); + } + if (mPrefs.contains(PREF_TEXT_SIZE)) { + /* + * Update from TextSize enum to zoom percent + * SMALLEST is 50% + * SMALLER is 75% + * NORMAL is 100% + * LARGER is 150% + * LARGEST is 200% + */ + switch (getTextSize()) { + case SMALLEST: + setTextZoom(50); + break; + case SMALLER: + setTextZoom(75); + break; + case LARGER: + setTextZoom(150); + break; + case LARGEST: + setTextZoom(200); + break; + } + mPrefs.edit().remove(PREF_TEXT_SIZE).apply(); + } + synchronized (BrowserSettings.this) { + mInitialized = true; + BrowserSettings.this.notifyAll(); + } + } + }; + + void requireInitialization() { + synchronized (BrowserSettings.this) { + while (!mInitialized) { + try { + BrowserSettings.this.wait(); + } catch (InterruptedException e) { + } + } + } + } + /** * Syncs all the settings that have a Preference UI */ @@ -236,7 +270,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, settings.setWorkersEnabled(true); // This only affects V8. // HTML5 configuration parametersettings. - settings.setAppCacheMaxSize(mWebStorageSizeManager.getAppCacheMaxSize()); + settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize()); settings.setAppCachePath(getAppCachePath()); settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); @@ -314,25 +348,21 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return layoutAlgorithm; } - // TODO: Cache public int getPageCacheCapacity() { - // the cost of one cached page is ~3M (measured using nytimes.com). For - // low end devices, we only cache one page. For high end devices, we try - // to cache more pages, currently choose 5. - if (ActivityManager.staticGetMemoryClass() > 16) { - return 5; - } else { - return 1; - } + requireInitialization(); + return mPageCacheCapacity; } public WebStorageSizeManager getWebStorageSizeManager() { + requireInitialization(); return mWebStorageSizeManager; } - // TODO: Cache private String getAppCachePath() { - return mContext.getDir("appcache", 0).getPath(); + if (mAppCachePath == null) { + mAppCachePath = mContext.getDir("appcache", 0).getPath(); + } + return mAppCachePath; } private void updateSearchEngine(boolean force) { @@ -366,6 +396,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } public boolean isDebugEnabled() { + requireInitialization(); return mPrefs.getBoolean(PREF_DEBUG_MENU, false); } @@ -496,6 +527,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } public int getTextZoom() { + requireInitialization(); int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10); return getAdjustedTextZoom(textZoom); } |