Replaced Threads with AsyncTasks
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 11 Oct 2011 11:11:38 -0700
changeset 83144 ba4595cf553e729b46161c9082d80b6b5fcb8856
parent 83143 5406124e5f8ae87c39b98532537aea745369aaa8
child 83145 a7a700a9069916e61bd1efce7d30bf6d46854839
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Replaced Threads with AsyncTasks
embedding/android/GeckoApp.java
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -301,21 +301,19 @@ abstract public class GeckoApp
     // Returns true when the intent is going to be handled by gecko launch
     boolean launch(Intent intent)
     {
         Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - launch");
 
         if (!checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
             return false;
 
-        if (intent == null)
-            intent = getIntent();
-        final Intent i = intent;
-        new Thread() {
-            public void run() {
+        class GeckoTask extends AsyncTask<Intent, Void, Void> {
+            protected Void doInBackground(Intent... intents) {
+                Intent intent = intents[0];
                 File cacheFile = GeckoAppShell.getCacheDir();
                 File libxulFile = new File(cacheFile, "libxul.so");
 
                 if ((!libxulFile.exists() ||
                      new File(getApplication().getPackageResourcePath()).lastModified() >= libxulFile.lastModified())) {
                     File[] libs = cacheFile.listFiles(new FilenameFilter() {
                             public boolean accept(File dir, String name) {
                                 return name.endsWith(".so");
@@ -338,28 +336,35 @@ abstract public class GeckoApp
                 Configuration config = res.getConfiguration();
                 config.locale = locale;
                 res.updateConfiguration(config, res.getDisplayMetrics());
 
                 Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - runGecko");
 
                 // and then fire us up
                 try {
-                    String env = i.getStringExtra("env0");
+                    String env = intent.getStringExtra("env0");
                     GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
-                                           i.getStringExtra("args"),
-                                           i.getDataString());
+                                           intent.getStringExtra("args"),
+                                           intent.getDataString());
                 } catch (Exception e) {
                     Log.e(LOG_FILE_NAME, "top level exception", e);
                     StringWriter sw = new StringWriter();
                     e.printStackTrace(new PrintWriter(sw));
                     GeckoAppShell.reportJavaCrash(sw.toString());
                 }
+                return null;
             }
-        }.start();
+        }
+
+        if (intent == null)
+            intent = getIntent();
+
+        new GeckoTask().execute(intent);
+
         return true;
     }
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu)
     {
         final Activity self = this;
 
@@ -484,32 +489,38 @@ abstract public class GeckoApp
 
                 if (false) {
                     checkAndLaunchUpdate();
                 }
             }
         }, 50);
     }
 
+
     public static void addHistoryEntry(final HistoryEntry entry) {
-        new Thread(new Runnable() {
-            public void run() {
+
+        class HistoryEntryTask extends AsyncTask<HistoryEntry, Void, Void> {
+            protected Void doInBackground(HistoryEntry... entries) {
+                HistoryEntry entry = entries[0];
                 Log.d("GeckoApp", "adding uri=" + entry.uri + ", title=" + entry.title + " to history");
                 ContentValues values = new ContentValues();
                 values.put("url", entry.uri);
                 values.put("title", entry.title);
                 if (sessionHistory.empty() || !sessionHistory.peek().uri.equals(entry.uri))
                     sessionHistory.push(entry);
                 mDb = mDbHelper.getWritableDatabase();
                 long id = mDb.insertWithOnConflict("moz_places", null, values, SQLiteDatabase.CONFLICT_REPLACE);
                 values = new ContentValues();
                 values.put("place_id", id);
                 mDb.insertWithOnConflict("moz_historyvisits", null, values, SQLiteDatabase.CONFLICT_REPLACE);
+                return null;
             }
-        }).start();
+        }
+
+        new HistoryEntryTask().execute(entry);
     }
 
     @Override
     protected void onNewIntent(Intent intent) {
         Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onNewIntent");
 
         if (checkLaunchState(LaunchState.GeckoExiting)) {
             // We're exiting and shouldn't try to do anything else just incase