Merge mozilla-central to mozilla-inbound
authorEd Morley <emorley@mozilla.com>
Mon, 08 Oct 2012 10:02:28 +0100
changeset 113258 6d20b416c2b750d864f0200415a9d08d70b298de
parent 113257 a4bc614f4092a8ca98ec95694d7720fcc1d3651e (current diff)
parent 113227 d3113617c43ade21e70f543e74fe975575f3a1ef (diff)
child 113259 e330290d261fb178300bbcbfaa1142fef0ecfbec
push id2248
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 19:23:44 +0000
treeherdermozilla-aurora@118a3b748323 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone18.0a1
Merge mozilla-central to mozilla-inbound
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -542,17 +542,17 @@ public class AwesomeBar extends GeckoAct
                 final EditText locationText = ((EditText) editView.findViewById(R.id.edit_bookmark_location));
                 final EditText keywordText = ((EditText) editView.findViewById(R.id.edit_bookmark_keyword));
                 nameText.setText(title);
                 locationText.setText(url);
                 keywordText.setText(keyword);
 
                 editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int whichButton) {
-                        (new GeckoAsyncTask<Void, Void, Void>() {
+                        (new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
                             @Override
                             public Void doInBackground(Void... params) {
                                 String newUrl = locationText.getText().toString().trim();
                                 BrowserDB.updateBookmark(mResolver, id, newUrl, nameText.getText().toString(),
                                                          keywordText.getText().toString());
                                 return null;
                             }
 
@@ -618,17 +618,17 @@ public class AwesomeBar extends GeckoAct
                         }
 
                         Toast.makeText(AwesomeBar.this, messageId, Toast.LENGTH_SHORT).show();
                     }
                 }).execute();
                 break;
             }
             case R.id.remove_history: {
-                (new GeckoAsyncTask<Void, Void, Void>() {
+                (new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
                     @Override
                     public Void doInBackground(Void... params) {
                         BrowserDB.removeHistoryEntry(mResolver, id);
                         return null;
                     }
 
                     @Override
                     public void onPostExecute(Void result) {
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -912,17 +912,17 @@ abstract public class BrowserApp extends
      */ 
     @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
 
         if (!Intent.ACTION_MAIN.equals(intent.getAction()))
             return;
 
-        (new GeckoAsyncTask<Void, Void, Boolean>() {
+        (new GeckoAsyncTask<Void, Void, Boolean>(mAppContext, GeckoAppShell.getHandler()) {
             @Override
             public synchronized Boolean doInBackground(Void... params) {
                 // Check to see how many times the app has been launched.
                 SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
                 String keyName = getPackageName() + ".feedback_launch_count";
                 int launchCount = settings.getInt(keyName, 0);
                 if (launchCount >= FEEDBACK_LAUNCH_COUNT)
                     return false;
@@ -949,17 +949,17 @@ abstract public class BrowserApp extends
             public synchronized void run() {
                 SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
                 settings.edit().putInt(getPackageName() + ".feedback_launch_count", 0).commit();
             }
         });
     }
 
     private void getLastUrl() {
-        (new GeckoAsyncTask<Void, Void, String>() {
+        (new GeckoAsyncTask<Void, Void, String>(mAppContext, GeckoAppShell.getHandler()) {
             @Override
             public synchronized String doInBackground(Void... params) {
                 // Get the most recent URL stored in browser history.
                 String url = "";
                 Cursor c = BrowserDB.getRecentHistory(getContentResolver(), 1);
                 if (c.moveToFirst()) {
                     url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
                 }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -770,17 +770,17 @@ abstract public class GeckoApp
         final Tab tab = Tabs.getInstance().getTab(tabId);
         if (tab == null)
             return;
 
         tab.setReaderEnabled(true);
     }
 
     void handleFaviconRequest(final String url) {
-        (new GeckoAsyncTask<Void, Void, String>() {
+        (new GeckoAsyncTask<Void, Void, String>(mAppContext, GeckoAppShell.getHandler()) {
             @Override
             public String doInBackground(Void... params) {
                 return getFavicons().getFaviconUrlForPageUrl(url);
             }
 
             @Override
             public void onPostExecute(String faviconUrl) {
                 JSONObject args = new JSONObject();
--- a/mobile/android/base/GeckoAsyncTask.java
+++ b/mobile/android/base/GeckoAsyncTask.java
@@ -1,54 +1,56 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * 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.util;
 
+import android.app.Activity;
 import android.os.Handler;
 
-// GeckoAsyncTask runs onPostExecute on the thread it is constructed on.
-// To ensure that onPostExecute() runs on UI thread, do either of these:
-//   1. construct GeckoAsyncTask on the UI thread
-//   2. post to the view's UI thread, in onPostExecute()
+// AsyncTask runs onPostExecute on the thread it is constructed on
+// We construct these off of the main thread, and we want that to run
+// on the main UI thread, so this is a convenience class to do that
 public abstract class GeckoAsyncTask<Params, Progress, Result> {
     public enum Priority { NORMAL, HIGH };
 
-    private final Handler mHandler;
+    private final Activity mActivity;
+    private final Handler mBackgroundThreadHandler;
     private Priority mPriority = Priority.NORMAL;
 
-    public GeckoAsyncTask() {
-        mHandler = new Handler();
+    public GeckoAsyncTask(Activity activity, Handler backgroundThreadHandler) {
+        mActivity = activity;
+        mBackgroundThreadHandler = backgroundThreadHandler;
     }
 
     private final class BackgroundTaskRunnable implements Runnable {
         private Params[] mParams;
 
         public BackgroundTaskRunnable(Params... params) {
             mParams = params;
         }
 
         public void run() {
             final Result result = doInBackground(mParams);
-            mHandler.post(new Runnable() {
+            mActivity.runOnUiThread(new Runnable() {
                 public void run() {
                     onPostExecute(result);
                 }
             });
         }
     }
 
     public final void execute(final Params... params) {
         BackgroundTaskRunnable runnable = new BackgroundTaskRunnable(params);
         if (mPriority == Priority.HIGH)
-            GeckoBackgroundThread.getHandler().postAtFrontOfQueue(runnable);
+            mBackgroundThreadHandler.postAtFrontOfQueue(runnable);
         else
-            GeckoBackgroundThread.getHandler().post(runnable);
+            mBackgroundThreadHandler.post(runnable);
     }
 
     public final GeckoAsyncTask<Params, Progress, Result> setPriority(Priority priority) {
         mPriority = priority;
         return this;
     }
 
     protected abstract Result doInBackground(Params... params);
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -373,17 +373,17 @@ public final class Tab {
         });
     }
 
     private void updateBookmark() {
         final String url = getURL();
         if (url == null)
             return;
 
-        (new GeckoAsyncTask<Void, Void, Void>() {
+        (new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
             @Override
             public Void doInBackground(Void... params) {
                 if (url.equals(getURL())) {
                     mBookmark = BrowserDB.isBookmark(mContentResolver, url);
                     mReadingListItem = BrowserDB.isReadingListItem(mContentResolver, url);
                 }
                 return null;
             }
--- a/mobile/android/base/TabsAccessor.java
+++ b/mobile/android/base/TabsAccessor.java
@@ -66,17 +66,17 @@ public final class TabsAccessor {
         public void areAvailable(boolean available);
     }
 
     // Helper method to check if there are any clients available
     public static void areClientsAvailable(final Context context, final OnClientsAvailableListener listener) {
         if (listener == null)
             return;
 
-        (new GeckoAsyncTask<Void, Void, Boolean>() {
+        (new GeckoAsyncTask<Void, Void, Boolean>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
             @Override
             protected Boolean doInBackground(Void... unused) {
                 Uri uri = BrowserContract.Tabs.CONTENT_URI;
                 uri = uri.buildUpon()
                          .appendQueryParameter(BrowserContract.PARAM_LIMIT, "1")
                          .build();
 
                 Cursor cursor = context.getContentResolver().query(uri,
@@ -110,17 +110,17 @@ public final class TabsAccessor {
 
     // This method returns limited number of tabs from all remote clients, 
     // ordered by most recent client first, most recent tab first 
     public static void getTabs(final Context context, final int limit, final OnQueryTabsCompleteListener listener) {
         // If there is no listener, no point in doing work.
         if (listener == null)
             return;
 
-        (new GeckoAsyncTask<Void, Void, List<RemoteTab>>() {
+        (new GeckoAsyncTask<Void, Void, List<RemoteTab>>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
             @Override
             protected List<RemoteTab> doInBackground(Void... unused) {
                 Uri uri = BrowserContract.Tabs.CONTENT_URI;
                 
                 if (limit > 0) {
                     uri = uri.buildUpon()
                              .appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit))
                              .build();