Bug 957131 - Synced bookmarks appear in guest mode but not in default profile. r=rnewman, a=lsblakk
authorWesley Johnston <wjohnston@mozilla.com>
Tue, 14 Jan 2014 21:45:59 -0800
changeset 175762 e3ed25347ea3c65651b49d6b2b4eb5c2dba4c926
parent 175761 a8246d76fff7e670c4c78ea3905f04b19d966929
child 175763 3f0b920677460be8b4432729bda84691e793df92
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs957131
milestone28.0a2
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/base/tests/DatabaseHelper.java
mobile/android/base/tests/testBrowserProviderPerf.java
mobile/android/base/tests/testImportFromAndroid.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
@@ -2504,17 +2504,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
@@ -1176,17 +1176,17 @@ public abstract 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
@@ -21,16 +21,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 String mName;
     private File mProfileDir;
     public static boolean sIsUsingCustomProfile = false;
 
@@ -108,17 +109,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);
                 profile.setDir(profileDir);
--- a/mobile/android/base/sync/receivers/UpgradeReceiver.java
+++ b/mobile/android/base/sync/receivers/UpgradeReceiver.java
@@ -62,17 +62,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/base/tests/DatabaseHelper.java
+++ b/mobile/android/base/tests/DatabaseHelper.java
@@ -29,17 +29,17 @@ class DatabaseHelper {
 
     protected Uri buildUri(BrowserDataType dataType) {
         Uri uri = null;
         if (dataType == BrowserDataType.BOOKMARKS || dataType == BrowserDataType.HISTORY) {
             uri = Uri.parse("content://" + TestConstants.ANDROID_PACKAGE_NAME + ".db.browser/" + dataType.toString().toLowerCase());
         } else {
            mAsserter.ok(false, "The wrong data type has been provided = " + dataType.toString(), "Please provide the correct data type");
         }
-        uri = uri.buildUpon().appendQueryParameter("profile", "default")
+        uri = uri.buildUpon().appendQueryParameter("profile", GeckoProfile.DEFAULT_PROFILE)
                              .appendQueryParameter("sync", "true").build();
         return uri;
     }
 
     /**
      * Adds a bookmark, or updates the bookmark title if the url already exists.
      *
      * The LocalBrowserDB.addBookmark implementation handles updating existing bookmarks.
--- a/mobile/android/base/tests/testBrowserProviderPerf.java
+++ b/mobile/android/base/tests/testBrowserProviderPerf.java
@@ -3,16 +3,17 @@ package org.mozilla.gecko.tests;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.SystemClock;
 import java.util.UUID;
 import java.util.Random;
 
+import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.db.BrowserDB;
 
 /*
  * This test is meant to exercise the performance of Fennec's
  * history and bookmarks content provider.
  */
 public class testBrowserProviderPerf extends ContentProviderTest {
     private final int NUMBER_OF_BASIC_HISTORY_URLS = 10000;
@@ -236,17 +237,17 @@ public class testBrowserProviderPerf ext
         super.setUp("org.mozilla.gecko.db.BrowserProvider", "AUTHORITY");
 
         mGenerator = new Random(19580427);
 
         loadContractInfo();
     }
 
     public void testBrowserProviderPerf() throws Exception {
-        BrowserDB.initialize("default");
+        BrowserDB.initialize(GeckoProfile.DEFAULT_PROFILE);
 
         loadMobileFolderId();
         addTonsOfUrls();
 
         long start = SystemClock.uptimeMillis();
 
         final Cursor c = BrowserDB.filter(mResolver, KNOWN_PREFIX, 100);
         c.getCount(); // ensure query is not lazy loaded
--- a/mobile/android/base/tests/testImportFromAndroid.java
+++ b/mobile/android/base/tests/testImportFromAndroid.java
@@ -112,17 +112,17 @@ public class testImportFromAndroid exten
             if ((androidBookmarks.indexOf(url) % 3) == 0) {
                 mDatabaseHelper.addOrUpdateMobileBookmark("Bookmark Number" + String.valueOf(androidBookmarks.indexOf(url)), url);
             }
         }
 
         // Add a few history items in Firefox Mobile
         ContentResolver resolver = getActivity().getContentResolver();
         Uri uri = Uri.parse("content://" + TestConstants.ANDROID_PACKAGE_NAME + ".db.browser/history");
-        uri = uri.buildUpon().appendQueryParameter("profile", "default")
+        uri = uri.buildUpon().appendQueryParameter("profile", GeckoProfile.DEFAULT_PROFILE)
                              .appendQueryParameter("sync", "true").build();
         for (String url:androidData) {
             // Add every 3rd website from Android History to Firefox Mobile
             if ((androidData.indexOf(url) % 3) == 0) {
                  ContentValues values = new ContentValues();
                  values.put("title", "Page" + url);
                  values.put("url", url);
                  values.put("date", System.currentTimeMillis());
--- 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.