Bug 957131 - Synced bookmarks appear in guest mode but not in default profile. r=rnewman a=lsblakk
authorWes Johnston <wjohnston@mozilla.com>
Fri, 17 Jan 2014 16:03:22 -0800
changeset 167949 b7d7ea54a6d233eea656cd28b99001514e7e72e6
parent 167948 ca6f65a22d6224a3dfc371f5e7030dc02e076d8f
child 167950 c26f88fa740f4781ed1f57fcb6a3bf1869581e7b
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs957131
milestone27.0
Bug 957131 - Synced bookmarks appear in guest mode but not in default profile. r=rnewman a=lsblakk
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoProfile.java
mobile/android/base/sync/receivers/UpgradeReceiver.java
mobile/android/base/sync/repositories/android/BrowserContractHelpers.java
mobile/android/base/sync/repositories/android/ClientsDatabaseAccessor.java
mobile/android/tests/background/junit3/src/db/TestCachedSQLiteOpenHelper.java
mobile/android/tests/background/junit3/src/db/TestClientsDatabase.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -2415,17 +2415,17 @@ abstract public class BrowserApp extends
     }
 
     @Override
     public int getLayout() { return R.layout.gecko_app; }
 
     @Override
     protected String getDefaultProfileName() {
         String profile = GeckoProfile.findDefaultProfile(this);
-        return (profile != null ? profile : "default");
+        return (profile != null ? profile : GeckoProfile.DEFAULT_PROFILE);
     }
 
     /**
      * Launch UI that lets the user update Firefox.
      *
      * This depends on the current channel: Release and Beta both direct to the
      * Google Play Store.  If updating is enabled, Aurora, Nightly, and custom
      * builds open about:, which provides an update interface.
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1169,17 +1169,17 @@ abstract public class GeckoApp
                     Pattern p = Pattern.compile("(?:-profile\\s*)(\\S*)(\\s*)");
                     Matcher m = p.matcher(args);
                     if (m.find()) {
                         profilePath =  m.group(1);
                     }
                     if (profileName == null) {
                         profileName = getDefaultProfileName();
                         if (profileName == null)
-                            profileName = "default";
+                            profileName = GeckoProfile.DEFAULT_PROFILE;
                     }
                     GeckoProfile.sIsUsingCustomProfile = true;
                 }
 
                 if (profileName != null || profilePath != null) {
                     mProfile = GeckoProfile.get(this, profileName, profilePath);
                 }
             }
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -22,16 +22,17 @@ import java.nio.charset.Charset;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
 
 public final class GeckoProfile {
     private static final String LOGTAG = "GeckoProfile";
     // Used to "lock" the guest profile, so that we'll always restart in it
     private static final String LOCK_FILE_NAME = ".active_lock";
+    public static final String DEFAULT_PROFILE = "default";
 
     private static HashMap<String, GeckoProfile> sProfileCache = new HashMap<String, GeckoProfile>();
     private static String sDefaultProfileName = null;
 
     private final Context mContext;
     private final String mName;
     private File mMozDir;
     private File mDir;
@@ -110,17 +111,17 @@ public final class GeckoProfile {
             throw new IllegalArgumentException("context must be non-null");
         }
 
         // if no profile was passed in, look for the default profile listed in profiles.ini
         // if that doesn't exist, look for a profile called 'default'
         if (TextUtils.isEmpty(profileName) && profileDir == null) {
             profileName = GeckoProfile.findDefaultProfile(context);
             if (profileName == null)
-                profileName = "default";
+                profileName = DEFAULT_PROFILE;
         }
 
         // actually try to look up the profile
         synchronized (sProfileCache) {
             GeckoProfile profile = sProfileCache.get(profileName);
             if (profile == null) {
                 profile = new GeckoProfile(context, profileName, profileDir);
                 sProfileCache.put(profileName, profile);
--- a/mobile/android/base/sync/receivers/UpgradeReceiver.java
+++ b/mobile/android/base/sync/receivers/UpgradeReceiver.java
@@ -61,17 +61,17 @@ public class UpgradeReceiver extends Bro
           } catch (CredentialException e) {
             Logger.warn(LOG_TAG, "Caught exception fetching account parameters while trying to migrate preferences; ignoring.", e);
             continue;
           }
 
           final String product = GlobalConstants.BROWSER_INTENT_PACKAGE;
           final String username = params.username;
           final String serverURL = params.serverURL;
-          final String profile = "default";
+          final String profile = Constants.DEFAULT_PROFILE;
           try {
             ConfigurationMigrator.ensurePrefsAreVersion(SyncConfiguration.CURRENT_PREFS_VERSION, context, accountManager, account,
                 product, username, serverURL, profile);
           } catch (Exception e) {
             Logger.warn(LOG_TAG, "Caught exception trying to migrate preferences; ignoring.", e);
             continue;
           }
         }
--- a/mobile/android/base/sync/repositories/android/BrowserContractHelpers.java
+++ b/mobile/android/base/sync/repositories/android/BrowserContractHelpers.java
@@ -4,42 +4,45 @@
 
 package org.mozilla.gecko.sync.repositories.android;
 
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.mozilla.gecko.db.BrowserContract;
+import org.mozilla.gecko.sync.setup.Constants;
 
 import android.net.Uri;
 
 public class BrowserContractHelpers extends BrowserContract {
 
-  protected static Uri withSyncAndDeleted(Uri u) {
+  protected static Uri withSyncAndDeletedAndProfile(Uri u) {
     return u.buildUpon()
+            .appendQueryParameter(PARAM_PROFILE, Constants.DEFAULT_PROFILE)
             .appendQueryParameter(PARAM_IS_SYNC, "true")
             .appendQueryParameter(PARAM_SHOW_DELETED, "true")
             .build();
   }
-  protected static Uri withSync(Uri u) {
+  protected static Uri withSyncAndProfile(Uri u) {
     return u.buildUpon()
+        .appendQueryParameter(PARAM_PROFILE, Constants.DEFAULT_PROFILE)
         .appendQueryParameter(PARAM_IS_SYNC, "true")
         .build();
   }
 
-  public static final Uri BOOKMARKS_CONTENT_URI            = withSyncAndDeleted(Bookmarks.CONTENT_URI);
-  public static final Uri BOOKMARKS_PARENTS_CONTENT_URI    = withSyncAndDeleted(Bookmarks.PARENTS_CONTENT_URI);
-  public static final Uri BOOKMARKS_POSITIONS_CONTENT_URI  = withSyncAndDeleted(Bookmarks.POSITIONS_CONTENT_URI);
-  public static final Uri HISTORY_CONTENT_URI              = withSyncAndDeleted(History.CONTENT_URI);
-  public static final Uri SCHEMA_CONTENT_URI               = withSyncAndDeleted(Schema.CONTENT_URI);
-  public static final Uri PASSWORDS_CONTENT_URI            = withSyncAndDeleted(Passwords.CONTENT_URI);
-  public static final Uri DELETED_PASSWORDS_CONTENT_URI    = withSyncAndDeleted(DeletedPasswords.CONTENT_URI);
-  public static final Uri FORM_HISTORY_CONTENT_URI         = withSync(FormHistory.CONTENT_URI);
-  public static final Uri DELETED_FORM_HISTORY_CONTENT_URI = withSync(DeletedFormHistory.CONTENT_URI);
+  public static final Uri BOOKMARKS_CONTENT_URI            = withSyncAndDeletedAndProfile(Bookmarks.CONTENT_URI);
+  public static final Uri BOOKMARKS_PARENTS_CONTENT_URI    = withSyncAndDeletedAndProfile(Bookmarks.PARENTS_CONTENT_URI);
+  public static final Uri BOOKMARKS_POSITIONS_CONTENT_URI  = withSyncAndDeletedAndProfile(Bookmarks.POSITIONS_CONTENT_URI);
+  public static final Uri HISTORY_CONTENT_URI              = withSyncAndDeletedAndProfile(History.CONTENT_URI);
+  public static final Uri SCHEMA_CONTENT_URI               = withSyncAndDeletedAndProfile(Schema.CONTENT_URI);
+  public static final Uri PASSWORDS_CONTENT_URI            = withSyncAndDeletedAndProfile(Passwords.CONTENT_URI);
+  public static final Uri DELETED_PASSWORDS_CONTENT_URI    = withSyncAndDeletedAndProfile(DeletedPasswords.CONTENT_URI);
+  public static final Uri FORM_HISTORY_CONTENT_URI         = withSyncAndProfile(FormHistory.CONTENT_URI);
+  public static final Uri DELETED_FORM_HISTORY_CONTENT_URI = withSyncAndProfile(DeletedFormHistory.CONTENT_URI);
 
   public static final String[] PasswordColumns = new String[] {
     Passwords.ID,
     Passwords.HOSTNAME,
     Passwords.HTTP_REALM,
     Passwords.FORM_SUBMIT_URL,
     Passwords.USERNAME_FIELD,
     Passwords.PASSWORD_FIELD,
--- a/mobile/android/base/sync/repositories/android/ClientsDatabaseAccessor.java
+++ b/mobile/android/base/sync/repositories/android/ClientsDatabaseAccessor.java
@@ -7,26 +7,27 @@ package org.mozilla.gecko.sync.repositor
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.json.simple.JSONArray;
+
 import org.mozilla.gecko.sync.CommandProcessor.Command;
 import org.mozilla.gecko.sync.repositories.NullCursorException;
 import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
+import org.mozilla.gecko.sync.setup.Constants;
 
 import android.content.Context;
 import android.database.Cursor;
 
 public class ClientsDatabaseAccessor {
 
-  public static final String PROFILE_ID = "default";     // Generic profile id for now, until multiple profiles are implemented.
   public static final String LOG_TAG = "ClientsDatabaseAccessor";
 
   private ClientsDatabase db;
 
   // Need this so we can properly stub out the class for testing.
   public ClientsDatabaseAccessor() {}
 
   public ClientsDatabaseAccessor(Context context) {
@@ -142,17 +143,17 @@ public class ClientsDatabaseAccessor {
       }
     } catch (NullCursorException e) {
       return 0;
     }
 
   }
 
   private String getProfileId() {
-    return ClientsDatabaseAccessor.PROFILE_ID;
+    return Constants.DEFAULT_PROFILE;
   }
 
   public void wipeDB() {
     db.wipeDB();
   }
 
   public void wipeClientsTable() {
     db.wipeClientsTable();
--- a/mobile/android/tests/background/junit3/src/db/TestCachedSQLiteOpenHelper.java
+++ b/mobile/android/tests/background/junit3/src/db/TestCachedSQLiteOpenHelper.java
@@ -5,16 +5,17 @@ package org.mozilla.gecko.background.db;
 
 import org.mozilla.gecko.background.sync.helpers.HistoryHelpers;
 import org.mozilla.gecko.sync.repositories.NullCursorException;
 import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender;
 import org.mozilla.gecko.sync.repositories.android.ClientsDatabase;
 import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
 import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
 import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
+import org.mozilla.gecko.sync.setup.Constants;
 
 import android.database.Cursor;
 import android.test.AndroidTestCase;
 
 public class TestCachedSQLiteOpenHelper extends AndroidTestCase {
 
   protected ClientsDatabase clientsDB;
   protected AndroidBrowserHistoryDataExtender extender;
@@ -28,17 +29,17 @@ public class TestCachedSQLiteOpenHelper 
     clientsDB.close();
     extender.close();
   }
 
   public void testUnclosedDatabasesDontInteract() throws NullCursorException {
     // clientsDB gracefully does its thing and closes.
     clientsDB.wipeClientsTable();
     ClientRecord record = new ClientRecord();
-    String profileConst = ClientsDatabaseAccessor.PROFILE_ID;
+    String profileConst = Constants.DEFAULT_PROFILE;
     clientsDB.store(profileConst, record);
     clientsDB.close();
 
     // extender does its thing but still hasn't closed.
     HistoryRecord h = HistoryHelpers.createHistory1();
     extender.store(h.guid, h.visits);
 
     // Ensure items in the clientsDB are still accessible nonetheless.
--- a/mobile/android/tests/background/junit3/src/db/TestClientsDatabase.java
+++ b/mobile/android/tests/background/junit3/src/db/TestClientsDatabase.java
@@ -7,32 +7,33 @@ import java.util.ArrayList;
 
 import org.json.simple.JSONArray;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.repositories.NullCursorException;
 import org.mozilla.gecko.sync.repositories.android.ClientsDatabase;
 import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
 import org.mozilla.gecko.sync.repositories.android.RepoUtils;
 import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
+import org.mozilla.gecko.sync.setup.Constants;
 
 import android.database.Cursor;
 import android.test.AndroidTestCase;
 
 public class TestClientsDatabase extends AndroidTestCase {
 
   protected ClientsDatabase db;
 
   public void setUp() {
     db = new ClientsDatabase(mContext);
     db.wipeDB();
   }
 
   public void testStoreAndFetch() {
     ClientRecord record = new ClientRecord();
-    String profileConst = ClientsDatabaseAccessor.PROFILE_ID;
+    String profileConst = Constants.DEFAULT_PROFILE;
     db.store(profileConst, record);
 
     Cursor cur = null;
     try {
       // Test stored item gets fetched correctly.
       cur = db.fetchClientsCursor(record.guid, profileConst);
       assertTrue(cur.moveToFirst());
       assertEquals(1, cur.getCount());
@@ -119,17 +120,17 @@ public class TestClientsDatabase extends
         cur.close();
       }
     }
   }
 
   public void testDelete() {
     ClientRecord record1 = new ClientRecord();
     ClientRecord record2 = new ClientRecord();
-    String profileConst = ClientsDatabaseAccessor.PROFILE_ID;
+    String profileConst = Constants.DEFAULT_PROFILE;
 
     db.store(profileConst, record1);
     db.store(profileConst, record2);
 
     Cursor cur = null;
     try {
       // Test record doesn't exist after delete.
       db.deleteClient(record1.guid, profileConst);
@@ -158,17 +159,17 @@ public class TestClientsDatabase extends
         cur.close();
       }
     }
   }
 
   public void testWipe() {
     ClientRecord record1 = new ClientRecord();
     ClientRecord record2 = new ClientRecord();
-    String profileConst = ClientsDatabaseAccessor.PROFILE_ID;
+    String profileConst = Constants.DEFAULT_PROFILE;
 
     db.store(profileConst, record1);
     db.store(profileConst, record2);
 
 
     Cursor cur = null;
     try {
       // Test before wipe the records are there.