From 9a693254258dbe30d5e4deda5dffb979cefd69cc Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Tue, 9 Sep 2014 16:52:51 -0400 Subject: [PATCH] Backed out 3 changesets (bug 1062377) for troboprovider bustage. Backed out changeset e34198954c2c (bug 1062377) Backed out changeset 8f323dfa4f0f (bug 1062377) Backed out changeset ec9b51158d34 (bug 1062377) --- mobile/android/base/GeckoApp.java | 12 +--- mobile/android/base/db/SuggestedSites.java | 18 ++---- .../base/util/GeckoBackgroundThread.java | 61 ++++++------------- mobile/android/base/util/ThreadUtils.java | 2 - mobile/android/tests/browser/junit3/moz.build | 3 - .../junit3/src/TestGeckoBackgroundThread.java | 55 ----------------- 6 files changed, 27 insertions(+), 124 deletions(-) delete mode 100644 mobile/android/tests/browser/junit3/src/TestGeckoBackgroundThread.java diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 01e0da2d535c..36bdfc785ae8 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1169,13 +1169,7 @@ public abstract class GeckoApp } } - // Speculatively pre-fetch the profile in the background. - ThreadUtils.postToBackgroundThread(new Runnable() { - @Override - public void run() { - getProfile(); - } - }); + BrowserDB.initialize(getProfile().getName()); // Workaround for . try { @@ -1445,8 +1439,6 @@ 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; @@ -1675,7 +1667,7 @@ public abstract class GeckoApp } } - public synchronized GeckoProfile getProfile() { + public GeckoProfile getProfile() { // fall back to default profile if we didn't load a specific one if (mProfile == null) { mProfile = GeckoProfile.get(this); diff --git a/mobile/android/base/db/SuggestedSites.java b/mobile/android/base/db/SuggestedSites.java index 890738526c36..c421ee9cfdc5 100644 --- a/mobile/android/base/db/SuggestedSites.java +++ b/mobile/android/base/db/SuggestedSites.java @@ -146,7 +146,7 @@ public class SuggestedSites { final Context context; final Distribution distribution; - private File cachedFile; + final File file; private Map cachedSites; private Set cachedBlacklist; @@ -155,20 +155,14 @@ public class SuggestedSites { } public SuggestedSites(Context appContext, Distribution distribution) { - this(appContext, distribution, null); + this(appContext, distribution, + GeckoProfile.get(appContext).getFile(FILENAME)); } public SuggestedSites(Context appContext, Distribution distribution, File file) { this.context = appContext; this.distribution = distribution; - this.cachedFile = file; - } - - synchronized File getFile() { - if (cachedFile == null) { - cachedFile = GeckoProfile.get(context).getFile(FILENAME); - } - return cachedFile; + this.file = file; } private static boolean isNewLocale(Context context, Locale requestedLocale) { @@ -301,7 +295,6 @@ public class SuggestedSites { setCachedSites(sites); // Save the result to disk. - final File file = getFile(); synchronized (file) { saveSites(file, sites); } @@ -345,7 +338,6 @@ public class SuggestedSites { private Map loadFromProfile() { try { - final File file = getFile(); synchronized (file) { return loadSites(file); } @@ -459,7 +451,7 @@ public class SuggestedSites { // Force the suggested sites file in profile dir to be re-generated // if the locale has changed. if (isNewLocale) { - getFile().delete(); + file.delete(); } if (cachedSites == null || isNewLocale) { diff --git a/mobile/android/base/util/GeckoBackgroundThread.java b/mobile/android/base/util/GeckoBackgroundThread.java index 442f782e2f52..bdd64d096d23 100644 --- a/mobile/android/base/util/GeckoBackgroundThread.java +++ b/mobile/android/base/util/GeckoBackgroundThread.java @@ -12,65 +12,44 @@ import java.util.concurrent.SynchronousQueue; final class GeckoBackgroundThread extends Thread { private static final String LOOPER_NAME = "GeckoBackgroundThread"; - // Guarded by 'GeckoBackgroundThread.class'. - private static Handler handler; - private static Thread thread; - - // The initial Runnable to run on the new thread. Its purpose - // is to avoid us having to wait for the new thread to start. - private Runnable initialRunnable; + // Guarded by 'this'. + private static Handler sHandler; + private SynchronousQueue mHandlerQueue = new SynchronousQueue(); // Singleton, so private constructor. - private GeckoBackgroundThread(final Runnable initialRunnable) { - this.initialRunnable = initialRunnable; + private GeckoBackgroundThread() { + super(); } @Override public void run() { setName(LOOPER_NAME); Looper.prepare(); - - synchronized (GeckoBackgroundThread.class) { - handler = new Handler(); - GeckoBackgroundThread.class.notify(); - } - - if (initialRunnable != null) { - initialRunnable.run(); - initialRunnable = null; - } + try { + mHandlerQueue.put(new Handler()); + } catch (InterruptedException ie) {} Looper.loop(); } - private static void startThread(final Runnable initialRunnable) { - thread = new GeckoBackgroundThread(initialRunnable); - ThreadUtils.setBackgroundThread(thread); - - thread.setDaemon(true); - thread.start(); - } - // Get a Handler for a looper thread, or create one if it doesn't yet exist. /*package*/ static synchronized Handler getHandler() { - if (thread == null) { - startThread(null); - } - - while (handler == null) { + if (sHandler == null) { + GeckoBackgroundThread lt = new GeckoBackgroundThread(); + ThreadUtils.setBackgroundThread(lt); + lt.start(); try { - GeckoBackgroundThread.class.wait(); - } catch (final InterruptedException e) { - } + sHandler = lt.mHandlerQueue.take(); + } catch (InterruptedException ie) {} } - return handler; + return sHandler; } - /*package*/ static synchronized void post(final Runnable runnable) { - if (thread == null) { - startThread(runnable); - return; + /*package*/ static void post(Runnable runnable) { + Handler handler = getHandler(); + if (handler == null) { + throw new IllegalStateException("No handler! Must have been interrupted. Not posting."); } - getHandler().post(runnable); + handler.post(runnable); } } diff --git a/mobile/android/base/util/ThreadUtils.java b/mobile/android/base/util/ThreadUtils.java index ae55120b1932..3f069ad4c795 100644 --- a/mobile/android/base/util/ThreadUtils.java +++ b/mobile/android/base/util/ThreadUtils.java @@ -182,7 +182,6 @@ public final class ThreadUtils { return isOnThread(getUiThread()); } - @RobocopTarget public static boolean isOnBackgroundThread() { if (sBackgroundThread == null) { return false; @@ -191,7 +190,6 @@ public final class ThreadUtils { return isOnThread(sBackgroundThread); } - @RobocopTarget public static boolean isOnThread(Thread thread) { return (Thread.currentThread().getId() == thread.getId()); } diff --git a/mobile/android/tests/browser/junit3/moz.build b/mobile/android/tests/browser/junit3/moz.build index 79f6d4198cd4..2e1935031e91 100644 --- a/mobile/android/tests/browser/junit3/moz.build +++ b/mobile/android/tests/browser/junit3/moz.build @@ -12,9 +12,6 @@ jar.sources += [ 'src/harness/BrowserInstrumentationTestRunner.java', 'src/harness/BrowserTestListener.java', 'src/TestDistribution.java', - 'src/TestGeckoBackgroundThread.java', - 'src/TestGeckoMenu.java', - 'src/TestGeckoProfilesProvider.java', 'src/TestGeckoSharedPrefs.java', 'src/TestImageDownloader.java', 'src/TestJarReader.java', diff --git a/mobile/android/tests/browser/junit3/src/TestGeckoBackgroundThread.java b/mobile/android/tests/browser/junit3/src/TestGeckoBackgroundThread.java deleted file mode 100644 index a2bec3d6122b..000000000000 --- a/mobile/android/tests/browser/junit3/src/TestGeckoBackgroundThread.java +++ /dev/null @@ -1,55 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.gecko; - -import org.mozilla.gecko.util.ThreadUtils; - -public class TestGeckoBackgroundThread extends BrowserTestCase { - - private boolean finishedTest; - private boolean ranFirstRunnable; - - public void testGeckoBackgroundThread() throws InterruptedException { - - final Thread testThread = Thread.currentThread(); - - ThreadUtils.postToBackgroundThread(new Runnable() { - @Override - public void run() { - // Must *not* be on thread that posted the Runnable. - assertFalse(ThreadUtils.isOnThread(testThread)); - - // Must be on background thread. - assertTrue(ThreadUtils.isOnBackgroundThread()); - - ranFirstRunnable = true; - } - }); - - // Post a second Runnable to make sure it still runs on the background thread, - // and it only runs after the first Runnable has run. - ThreadUtils.postToBackgroundThread(new Runnable() { - @Override - public void run() { - // Must still be on background thread. - assertTrue(ThreadUtils.isOnBackgroundThread()); - - // This Runnable must be run after the first Runnable had finished. - assertTrue(ranFirstRunnable); - - synchronized (TestGeckoBackgroundThread.this) { - finishedTest = true; - TestGeckoBackgroundThread.this.notify(); - } - } - }); - - synchronized (this) { - while (!finishedTest) { - wait(); - } - } - } -}