mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-15 11:13:29 +00:00
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)
This commit is contained in:
parent
3ea6ec9560
commit
9a69325425
@ -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 <http://code.google.com/p/android/issues/detail?id=20915>.
|
||||
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);
|
||||
|
@ -146,7 +146,7 @@ public class SuggestedSites {
|
||||
|
||||
final Context context;
|
||||
final Distribution distribution;
|
||||
private File cachedFile;
|
||||
final File file;
|
||||
private Map<String, Site> cachedSites;
|
||||
private Set<String> 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<String, Site> 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) {
|
||||
|
@ -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<Handler> mHandlerQueue = new SynchronousQueue<Handler>();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user