Bug 721776 - Don't remove bookmark from DB in the main thread (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 07 Feb 2012 14:47:54 +0000
changeset 86447 870a1156baf066162755c05665a9b1ad9fbafbeb
parent 86446 7fa9d642fe74ef563ab428b171ade21d1a683003
child 86448 d9999729e539b849df93390a10b811dabef818b9
push id94
push userbturner@mozilla.com
push dateWed, 08 Feb 2012 05:39:15 +0000
reviewersmfinkle
bugs721776
milestone13.0a1
Bug 721776 - Don't remove bookmark from DB in the main thread (r=mfinkle)
mobile/android/base/AwesomeBar.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -439,17 +439,17 @@ public class AwesomeBar extends Activity
         menu.setHeaderTitle(title);
     }
 
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         if (mContextMenuSubject == null)
             return false;
 
-        String url = "";
+        final String url;
         byte[] b = null;
         String title = "";
         if (mContextMenuSubject instanceof Cursor) {
             Cursor cursor = (Cursor)mContextMenuSubject;
             url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
             b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
             title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
         } else if (mContextMenuSubject instanceof Map) {
@@ -465,19 +465,29 @@ public class AwesomeBar extends Activity
 
         switch (item.getItemId()) {
             case R.id.open_new_tab: {
                 GeckoApp.mAppContext.loadUrl(url, AwesomeBar.Type.ADD);
                 Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
                 break;
             }
             case R.id.remove_bookmark: {
-                ContentResolver resolver = Tabs.getInstance().getContentResolver();
-                BrowserDB.removeBookmark(resolver, url);
-                Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
+                GeckoAppShell.getHandler().post(new Runnable() {
+                    public void run() {
+                        ContentResolver resolver = Tabs.getInstance().getContentResolver();
+                        BrowserDB.removeBookmark(resolver, url);
+
+                        GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
+                            public void run() {
+                                Toast.makeText(this, R.string.bookmark_removed,
+                                        Toast.LENGTH_SHORT).show();
+                            }
+                        });
+                    }
+                });
                 break;
             }
             case R.id.add_to_launcher: {
                 Bitmap bitmap = null;
                 if (b != null)
                     bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
     
                 GeckoAppShell.createShortcut(title, url, bitmap, "");