Bug 723841 - Generalize code to create or update special folders (r=rnewman)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 20 Feb 2012 19:28:27 +0000
changeset 87242 06b31e6330c6273f677c0d62cc4aa2684a814bcb
parent 87241 2094fc0fc224761062a20c44398ef40e8d8f0db7
child 87243 0ffb3b233fcedae835ffcbd2a4f696852255c0fd
push id22103
push userbmo@edmorley.co.uk
push dateTue, 21 Feb 2012 12:01:45 +0000
treeherdermozilla-central@4038ffaa5d82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs723841
milestone13.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
Bug 723841 - Generalize code to create or update special folders (r=rnewman)
mobile/android/base/db/BrowserProvider.java.in
--- a/mobile/android/base/db/BrowserProvider.java.in
+++ b/mobile/android/base/db/BrowserProvider.java.in
@@ -336,38 +336,45 @@ public class BrowserProvider extends Con
 
             createBookmarksTable(db);
             createHistoryTable(db);
             createImagesTable(db);
 
             createBookmarksWithImagesView(db);
             createHistoryWithImagesView(db);
 
-            createMobileBookmarksFolder(db);
+            createOrUpdateSpecialFolder(db, Bookmarks.MOBILE_FOLDER_GUID,
+                R.string.bookmarks_folder_mobile, 0);
 
             // FIXME: Create default bookmarks here
         }
 
-        private void createMobileBookmarksFolder(SQLiteDatabase db) {
+        private void createOrUpdateSpecialFolder(SQLiteDatabase db,
+                String guid, int titleId, int position) {
             ContentValues values = new ContentValues();
-            values.put(Bookmarks.GUID, Bookmarks.MOBILE_FOLDER_GUID);
+            values.put(Bookmarks.GUID, guid);
             values.put(Bookmarks.IS_FOLDER, 1);
-            values.put(Bookmarks.POSITION, 0);
+            values.put(Bookmarks.POSITION, position);
 
             // Set the parent to 0, which sync assumes is the root
             values.put(Bookmarks.PARENT, 0);
 
-            String title = mContext.getResources().getString(R.string.bookmarks_folder_mobile);
+            String title = mContext.getResources().getString(titleId);
             values.put(Bookmarks.TITLE, title);
 
             long now = System.currentTimeMillis();
             values.put(Bookmarks.DATE_CREATED, now);
             values.put(Bookmarks.DATE_MODIFIED, now);
 
-            db.insertOrThrow(TABLE_BOOKMARKS, Bookmarks.GUID, values);
+            int updated = db.update(TABLE_BOOKMARKS, values,
+                                    Bookmarks.GUID + " = ?",
+                                    new String[] { guid });
+
+            if (updated == 0)
+                db.insert(TABLE_BOOKMARKS, Bookmarks.GUID, values);
         }
 
         @Override
         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
             debug("Upgrading browser.db: " + db.getPath() + " from " +
                     oldVersion + " to " + newVersion);
 
             // Do nothing for now