Bug 743153 - Use ContentUris.parseId instead of RepoUtils.getAndroidIdFromUri. r=rnewman, a=blocking-fennec (dependency)
authorNick Alexander <nalexander@mozilla.com>
Mon, 30 Apr 2012 13:40:27 -0700
changeset 92747 269c9f8b7fa190c609cf675795a4a6078b7f1434
parent 92746 dbdda755fc5111a71db4665574591e749917893e
child 92748 f88ff3ed9668d6a154e136290b173a9a0c7f0fbf
push id8853
push userrnewman@mozilla.com
push dateMon, 30 Apr 2012 20:41:48 +0000
treeherdermozilla-inbound@4ef64adfb6a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, blocking-fennec
bugs743153
milestone15.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 743153 - Use ContentUris.parseId instead of RepoUtils.getAndroidIdFromUri. r=rnewman, a=blocking-fennec (dependency)
mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java
mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java
mobile/android/base/sync/repositories/android/RepoUtils.java
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
@@ -11,16 +11,17 @@ import java.util.Map;
 
 import org.json.simple.JSONArray;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.sync.Logger;
 import org.mozilla.gecko.sync.repositories.NullCursorException;
 import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord;
 import org.mozilla.gecko.sync.repositories.domain.Record;
 
+import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 
 public class AndroidBrowserBookmarksDataAccessor extends AndroidBrowserRepositoryDataAccessor {
 
   private static final String LOG_TAG = "BookmarksDataAccessor";
@@ -244,17 +245,17 @@ public class AndroidBrowserBookmarksData
     }
   }
 
   private long insertSpecialFolder(String guid, long parentId) {
     BookmarkRecord record = new BookmarkRecord(guid);
     record.title = AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.get(guid);
     record.type = "folder";
     record.androidParentID = parentId;
-    return(RepoUtils.getAndroidIdFromUri(insert(record)));
+    return ContentUris.parseId(insert(record));
   }
 
   @Override
   protected ContentValues getContentValues(Record record) {
     BookmarkRecord rec = (BookmarkRecord) record;
 
     if (rec.deleted) {
       ContentValues cv = new ContentValues();
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserRepositorySession.java
@@ -21,16 +21,17 @@ import org.mozilla.gecko.sync.repositori
 import org.mozilla.gecko.sync.repositories.Repository;
 import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
 import org.mozilla.gecko.sync.repositories.domain.Record;
 
+import android.content.ContentUris;
 import android.database.Cursor;
 import android.net.Uri;
 
 /**
  * You'll notice that all delegate calls *either*:
  *
  * - request a deferred delegate with the appropriate work queue, then
  *   make the appropriate call, or
@@ -528,17 +529,17 @@ public abstract class AndroidBrowserRepo
     // in order to support syncing to multiple destinations. Bug 722607.
     dbHelper.purgeGuid(record.guid);
     delegate.onRecordStoreSucceeded(record);
   }
 
   protected Record insert(Record record) throws NoGuidForIdException, NullCursorException, ParentNotFoundException {
     Record toStore = prepareRecord(record);
     Uri recordURI = dbHelper.insert(toStore);
-    long id = RepoUtils.getAndroidIdFromUri(recordURI);
+    long id = ContentUris.parseId(recordURI);
     Logger.debug(LOG_TAG, "Inserted as " + id);
 
     toStore.androidID = id;
     updateBookkeeping(toStore);
     Logger.debug(LOG_TAG, "insert() returning record " + toStore.guid);
     return toStore;
   }
 
--- a/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java
@@ -23,16 +23,17 @@ import org.mozilla.gecko.sync.repositori
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate;
 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate;
 import org.mozilla.gecko.sync.repositories.domain.PasswordRecord;
 import org.mozilla.gecko.sync.repositories.domain.Record;
 
 import android.content.ContentProviderClient;
+import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.RemoteException;
 
 public class PasswordsRepositorySession extends
     StoreTrackingRepositorySession {
@@ -440,17 +441,20 @@ public class PasswordsRepositorySession 
    */
   public PasswordRecord insert(PasswordRecord record) throws RemoteException {
     record.timePasswordChanged = now();
     // TODO: are these necessary for Fennec autocomplete?
     // record.timesUsed = 1;
     // record.timeLastUsed = now();
     ContentValues cv = getContentValues(record);
     Uri insertedUri = passwordsProvider.insert(BrowserContractHelpers.PASSWORDS_CONTENT_URI, cv);
-    record.androidID = RepoUtils.getAndroidIdFromUri(insertedUri);
+    if (insertedUri == null) {
+      throw new RemoteException(); // Not much to be done here, save throw.
+    }
+    record.androidID = ContentUris.parseId(insertedUri);
     return record;
   }
 
   public Record replace(Record origRecord, Record newRecord) throws RemoteException {
     PasswordRecord newPasswordRecord = (PasswordRecord) newRecord;
     PasswordRecord origPasswordRecord = (PasswordRecord) origRecord;
     propagateTimes(newPasswordRecord, origPasswordRecord);
     ContentValues cv = getContentValues(newPasswordRecord);
--- a/mobile/android/base/sync/repositories/android/RepoUtils.java
+++ b/mobile/android/base/sync/repositories/android/RepoUtils.java
@@ -114,24 +114,16 @@ public class RepoUtils {
     try {
       return (JSONArray) new JSONParser().parse(getStringFromCursor(cur, colId));
     } catch (ParseException e) {
       Logger.error(LOG_TAG, "JSON parsing error for " + colId, e);
       return null;
     }
   }
 
-  // Returns android id from the URI that we get after inserting a
-  // bookmark into the local Android store.
-  public static long getAndroidIdFromUri(Uri uri) {
-    String path = uri.getPath();
-    int lastSlash = path.lastIndexOf('/');
-    return Long.parseLong(path.substring(lastSlash + 1));
-  }
-
   //Create a HistoryRecord object from a cursor on a row with a Moz History record in it
   public static HistoryRecord historyFromMirrorCursor(Cursor cur) {
 
     String guid = getStringFromCursor(cur, BrowserContract.SyncColumns.GUID);
     String collection = "history";
     long lastModified = getLongFromCursor(cur, BrowserContract.SyncColumns.DATE_MODIFIED);
     boolean deleted = getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1 ? true : false;
     HistoryRecord rec = new HistoryRecord(guid, collection, lastModified, deleted);