Bug 1234315 - Convert getMobileFolderId into getFolderIDForGuid r?rnewman draft
authorAndrzej Hunt <ahunt@mozilla.com>
Thu, 11 Feb 2016 19:34:16 -0800
changeset 341327 144e5608017066c4c75f9284eefedc53a65c38e3
parent 341326 c4bf986fb35e3a804c7bfcf8e7aa9ef38df536fc
child 341328 8f23129e23c9b8f442c764c049871d194425ca38
push id13191
push userahunt@mozilla.com
push dateWed, 16 Mar 2016 21:46:58 +0000
reviewersrnewman
bugs1234315
milestone48.0a1
Bug 1234315 - Convert getMobileFolderId into getFolderIDForGuid r?rnewman We only use this in one location, so there's little advantage to storing our parameters as static final. Allowing arbitrary guids will allow us to retrieve e.g. the reading list folder id easily in future. MozReview-Commit-ID: JnLsgKAr1Y0
mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
@@ -71,19 +71,16 @@ public final class BrowserDatabaseHelper
 
     static final String TABLE_HISTORY_JOIN_FAVICONS = TABLE_HISTORY + " LEFT OUTER JOIN " +
             TABLE_FAVICONS + " ON " + qualifyColumn(TABLE_HISTORY, History.FAVICON_ID) + " = " +
             qualifyColumn(TABLE_FAVICONS, Favicons._ID);
 
     static final String TABLE_BOOKMARKS_TMP = TABLE_BOOKMARKS + "_tmp";
     static final String TABLE_HISTORY_TMP = TABLE_HISTORY + "_tmp";
 
-    private static final String[] mobileIdColumns = new String[] { Bookmarks._ID };
-    private static final String[] mobileIdSelectionArgs = new String[] { Bookmarks.MOBILE_FOLDER_GUID };
-
     public BrowserDatabaseHelper(Context context, String databasePath) {
         super(context, databasePath, null, DATABASE_VERSION);
         mContext = context;
     }
 
     private void createBookmarksTable(SQLiteDatabase db) {
         debug("Creating " + TABLE_BOOKMARKS + " table");
 
@@ -693,17 +690,17 @@ public final class BrowserDatabaseHelper
                 c.close();
         }
 
         // At this point is safe to assume that the mobile folder is
         // in the new table given that we've always created it on
         // database creation time.
         final int nInvalidSpecialEntries = invalidSpecialEntries.size();
         if (nInvalidSpecialEntries > 0) {
-            Integer mobileFolderId = getMobileFolderId(db);
+            Integer mobileFolderId = getBookmarkIdForGuid(db, Bookmarks.MOBILE_FOLDER_GUID);
             if (mobileFolderId == null) {
                 Log.e(LOGTAG, "Error migrating invalid special folder entries: mobile folder id is null");
                 return;
             }
 
             debug("Found " + nInvalidSpecialEntries + " invalid special folder entries");
             for (int i = 0; i < nInvalidSpecialEntries; i++) {
                 ContentValues values = invalidSpecialEntries.get(i);
@@ -1303,24 +1300,24 @@ public final class BrowserDatabaseHelper
     }
 
     protected static void debug(String message) {
         if (logDebug) {
             Log.d(LOGTAG, message);
         }
     }
 
-    private Integer getMobileFolderId(SQLiteDatabase db) {
+    private Integer getBookmarkIdForGuid(SQLiteDatabase db, final String guid) {
         Cursor c = null;
 
         try {
             c = db.query(TABLE_BOOKMARKS,
-                         mobileIdColumns,
+                         new String[] { Bookmarks._ID },
                          Bookmarks.GUID + " = ?",
-                         mobileIdSelectionArgs,
+                         new String[] { guid },
                          null, null, null);
 
             if (c == null || !c.moveToFirst())
                 return null;
 
             return c.getInt(c.getColumnIndex(Bookmarks._ID));
         } finally {
             if (c != null)