Bug 996749 - Kill PrefsSource. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Tue, 15 Apr 2014 10:59:00 -0700
changeset 179027 67bcfa1fe3c9e9a30318dadfa89fc420de9818eb
parent 179026 c0e6f3b758b4d072f28b849ca8481f856a775c95
child 179028 6edb3b4eba0c68077705157f1bf13ea86118417b
push id6388
push usernalexander@mozilla.com
push dateThu, 17 Apr 2014 18:55:53 +0000
treeherderfx-team@3b4a911abb02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs996749
milestone31.0a1
Bug 996749 - Kill PrefsSource. r=rnewman ======== https://github.com/mozilla-services/android-sync/commit/6ced7b05cd2aafe3d54cdd81d6e19caafad2913b Author: Nick Alexander <nalexander@mozilla.com> Bug 996749 - Part 3: Finally kill PrefsSource. ======== https://github.com/mozilla-services/android-sync/commit/b37547fbd82ec4b0c0dab5a4502bff29b82d7adf Author: Nick Alexander <nalexander@mozilla.com> Date: Tue Apr 15 10:47:11 2014 -0700 Bug 996749 - Part 2: Remove storageEndpoint from FxAccountGlobalSession constructor. This is just a separation of concerns: let's inject our dependency as configured as possible. ======== https://github.com/mozilla-services/android-sync/commit/42e8fe761f1626c5d36575591c89ff493abaf22d Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Apr 14 12:30:21 2014 -0700 Bug 996749 - Part 1: Remove debugAssertion. This is no longer valuable, since we're not getting timestamp HAWK errors from the server.
mobile/android/base/android-services.mozbuild
mobile/android/base/fxa/sync/FxAccountGlobalSession.java
mobile/android/base/fxa/sync/FxAccountSyncAdapter.java
mobile/android/base/sync/GlobalSession.java
mobile/android/base/sync/PrefsSource.java
mobile/android/base/sync/SyncConfiguration.java
mobile/android/tests/background/junit3/src/sync/TestSyncConfiguration.java
--- a/mobile/android/base/android-services.mozbuild
+++ b/mobile/android/base/android-services.mozbuild
@@ -685,17 +685,16 @@ sync_java_files = [
     'sync/net/WBORequestDelegate.java',
     'sync/NoCollectionKeysSetException.java',
     'sync/NodeAuthenticationException.java',
     'sync/NonArrayJSONException.java',
     'sync/NonObjectJSONException.java',
     'sync/NullClusterURLException.java',
     'sync/PersistedMetaGlobal.java',
     'sync/PrefsBackoffHandler.java',
-    'sync/PrefsSource.java',
     'sync/receivers/SyncAccountDeletedReceiver.java',
     'sync/receivers/SyncAccountDeletedService.java',
     'sync/receivers/UpgradeReceiver.java',
     'sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java',
     'sync/repositories/android/AndroidBrowserBookmarksRepository.java',
     'sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java',
     'sync/repositories/android/AndroidBrowserHistoryDataAccessor.java',
     'sync/repositories/android/AndroidBrowserHistoryDataExtender.java',
--- a/mobile/android/base/fxa/sync/FxAccountGlobalSession.java
+++ b/mobile/android/base/fxa/sync/FxAccountGlobalSession.java
@@ -1,45 +1,39 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.fxa.sync;
 
 import java.io.IOException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.HashMap;
 
 import org.json.simple.parser.ParseException;
-import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.sync.GlobalSession;
 import org.mozilla.gecko.sync.NonObjectJSONException;
 import org.mozilla.gecko.sync.SyncConfiguration;
 import org.mozilla.gecko.sync.SyncConfigurationException;
 import org.mozilla.gecko.sync.delegates.BaseGlobalSessionCallback;
 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
 import org.mozilla.gecko.sync.stage.CheckPreconditionsStage;
 import org.mozilla.gecko.sync.stage.GlobalSyncStage;
 import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
 
 import android.content.Context;
 
 public class FxAccountGlobalSession extends GlobalSession {
-  private static final String LOG_TAG = FxAccountGlobalSession.class.getSimpleName();
-
-  public FxAccountGlobalSession(String storageEndpoint, SyncConfiguration config, BaseGlobalSessionCallback callback,
-      Context context, ClientsDataDelegate clientsDelegate)
-      throws SyncConfigurationException, IllegalArgumentException, IOException,
-      ParseException, NonObjectJSONException, URISyntaxException {
+  public FxAccountGlobalSession(SyncConfiguration config,
+                                BaseGlobalSessionCallback callback,
+                                Context context,
+                                ClientsDataDelegate clientsDelegate)
+                                    throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException, URISyntaxException {
     super(config, callback, context, clientsDelegate, null);
-    URI storageURI = new URI(storageEndpoint);
-    this.config.setClusterURL(storageURI);
-    FxAccountConstants.pii(LOG_TAG, "clusterURL is " + config.getClusterURLString());
   }
 
   @Override
   public void prepareStages() {
     super.prepareStages();
     HashMap<Stage, GlobalSyncStage> stages = new HashMap<Stage, GlobalSyncStage>();
     stages.putAll(this.stages);
     stages.put(Stage.ensureClusterURL, new CheckPreconditionsStage());
--- a/mobile/android/base/fxa/sync/FxAccountSyncAdapter.java
+++ b/mobile/android/base/fxa/sync/FxAccountSyncAdapter.java
@@ -15,32 +15,29 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountClient;
 import org.mozilla.gecko.background.fxa.FxAccountClient20;
 import org.mozilla.gecko.background.fxa.SkewHandler;
 import org.mozilla.gecko.browserid.BrowserIDKeyPair;
 import org.mozilla.gecko.browserid.JSONWebTokenUtils;
-import org.mozilla.gecko.browserid.verifier.BrowserIDRemoteVerifierClient;
-import org.mozilla.gecko.browserid.verifier.BrowserIDVerifierDelegate;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.authenticator.AccountPickler;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
 import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine;
 import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.LoginStateMachineDelegate;
 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.Transition;
 import org.mozilla.gecko.fxa.login.Married;
 import org.mozilla.gecko.fxa.login.State;
 import org.mozilla.gecko.fxa.login.State.StateLabel;
 import org.mozilla.gecko.fxa.login.StateFactory;
 import org.mozilla.gecko.sync.BackoffHandler;
-import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.GlobalSession;
 import org.mozilla.gecko.sync.PrefsBackoffHandler;
 import org.mozilla.gecko.sync.SharedPreferencesClientsDataDelegate;
 import org.mozilla.gecko.sync.SyncConfiguration;
 import org.mozilla.gecko.sync.ThreadPool;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.sync.crypto.KeyBundle;
 import org.mozilla.gecko.sync.delegates.BaseGlobalSessionCallback;
@@ -375,28 +372,28 @@ public class FxAccountSyncAdapter extend
           final boolean includePayloadVerificationHash = false;
           final AuthHeaderProvider authHeaderProvider = new HawkAuthHeaderProvider(token.id, token.key.getBytes("UTF-8"), includePayloadVerificationHash, storageServerSkew);
 
           final Context context = getContext();
           final SyncConfiguration syncConfig = new SyncConfiguration(token.uid, authHeaderProvider, sharedPrefs, syncKeyBundle);
 
           Collection<String> knownStageNames = SyncConfiguration.validEngineNames();
           syncConfig.stagesToSync = Utils.getStagesToSyncFromBundle(knownStageNames, extras);
+          syncConfig.setClusterURL(storageServerURI);
 
-          globalSession = new FxAccountGlobalSession(token.endpoint, syncConfig, callback, context, clientsDataDelegate);
+          globalSession = new FxAccountGlobalSession(syncConfig, callback, context, clientsDataDelegate);
           globalSession.start();
         } catch (Exception e) {
           callback.handleError(globalSession, e);
           return;
         }
       }
 
       @Override
       public void handleFailure(TokenServerException e) {
-        debugAssertion(audience, assertion);
         handleError(e);
       }
 
       @Override
       public void handleError(Exception e) {
         Logger.error(LOG_TAG, "Failed to get token.", e);
         callback.handleError(null, e);
       }
@@ -611,39 +608,9 @@ public class FxAccountSyncAdapter extend
     } catch (Exception e) {
       Logger.error(LOG_TAG, "Got error syncing.", e);
       syncDelegate.handleError(e);
     }
 
     Logger.info(LOG_TAG, "Syncing done.");
     lastSyncRealtimeMillis = SystemClock.elapsedRealtime();
   }
-
-  protected void debugAssertion(String audience, String assertion) {
-    final CountDownLatch verifierLatch = new CountDownLatch(1);
-    BrowserIDRemoteVerifierClient client = new BrowserIDRemoteVerifierClient(URI.create(BrowserIDRemoteVerifierClient.DEFAULT_VERIFIER_URL));
-    client.verify(audience, assertion, new BrowserIDVerifierDelegate() {
-      @Override
-      public void handleSuccess(ExtendedJSONObject response) {
-        Logger.info(LOG_TAG, "Remote verifier returned success: " + response.toJSONString());
-        verifierLatch.countDown();
-      }
-
-      @Override
-      public void handleFailure(ExtendedJSONObject response) {
-        Logger.warn(LOG_TAG, "Remote verifier returned failure: " + response.toJSONString());
-        verifierLatch.countDown();
-      }
-
-      @Override
-      public void handleError(Exception e) {
-        Logger.error(LOG_TAG, "Remote verifier returned error.", e);
-        verifierLatch.countDown();
-      }
-    });
-
-    try {
-      verifierLatch.await();
-    } catch (InterruptedException e) {
-      Logger.error(LOG_TAG, "Got error.", e);
-    }
-  }
 }
--- a/mobile/android/base/sync/GlobalSession.java
+++ b/mobile/android/base/sync/GlobalSession.java
@@ -52,20 +52,19 @@ import org.mozilla.gecko.sync.stage.Form
 import org.mozilla.gecko.sync.stage.GlobalSyncStage;
 import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
 import org.mozilla.gecko.sync.stage.NoSuchStageException;
 import org.mozilla.gecko.sync.stage.PasswordsServerSyncStage;
 import org.mozilla.gecko.sync.stage.SyncClientsEngineStage;
 import org.mozilla.gecko.sync.stage.UploadMetaGlobalStage;
 
 import android.content.Context;
-import android.content.SharedPreferences;
 import ch.boye.httpclientandroidlib.HttpResponse;
 
-public class GlobalSession implements PrefsSource, HttpResponseObserver {
+public class GlobalSession implements HttpResponseObserver {
   private static final String LOG_TAG = "GlobalSession";
 
   public static final long STORAGE_VERSION = 5;
 
   public SyncConfiguration config = null;
 
   protected Map<Stage, GlobalSyncStage> stages;
   public Stage currentState = Stage.idle;
@@ -272,24 +271,16 @@ public class GlobalSession implements Pr
       nextStage.execute(this);
     } catch (Exception ex) {
       Logger.warn(LOG_TAG, "Caught exception " + ex + " running stage " + next);
       this.abort(ex, "Uncaught exception in stage.");
       return;
     }
   }
 
-  /*
-   * PrefsSource methods.
-   */
-  @Override
-  public SharedPreferences getPrefs(String name, int mode) {
-    return this.getContext().getSharedPreferences(name, mode);
-  }
-
   public Context getContext() {
     return this.context;
   }
 
   /**
    * Begin a sync.
    * <p>
    * The caller is responsible for:
deleted file mode 100644
--- a/mobile/android/base/sync/PrefsSource.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.sync;
-
-import android.content.SharedPreferences;
-
-/**
- * Implement PrefsSource to allow other components to fetch a SharedPreferences
- * instance via a Context that you provide.
- *
- * This allows components to use SharedPreferences without being tightly
- * coupled to an Activity.
- *
- * @author rnewman
- *
- */
-public interface PrefsSource {
-  /**
-   * Return a SharedPreferences instance.
-   * @param name
-   *        A String, used to identify a preferences 'branch'. Must not be null.
-   * @param mode
-   *        A bitmask mode, as described in http://developer.android.com/reference/android/content/Context.html#getSharedPreferences%28java.lang.String,%20int%29.
-   * @return
-   *        A new or existing SharedPreferences instance.
-   */
-  public SharedPreferences getPrefs(String name, int mode);
-}
--- a/mobile/android/base/sync/SyncConfiguration.java
+++ b/mobile/android/base/sync/SyncConfiguration.java
@@ -256,24 +256,16 @@ public class SyncConfiguration {
   public static final String PREF_CLUSTER_URL_IS_STALE = "clusterurlisstale";
 
   public static final String PREF_ACCOUNT_GUID = "account.guid";
   public static final String PREF_CLIENT_NAME = "account.clientName";
   public static final String PREF_NUM_CLIENTS = "account.numClients";
 
   private static final String API_VERSION = "1.5";
 
-  /**
-   * Create a new SyncConfiguration instance. Pass in a PrefsSource to
-   * provide access to preferences.
-   */
-  public SyncConfiguration(String username, AuthHeaderProvider authHeaderProvider, String prefsPath, PrefsSource prefsSource) {
-    this(username, authHeaderProvider, prefsSource.getPrefs(prefsPath, Utils.SHARED_PREFERENCES_MODE));
-  }
-
   public SyncConfiguration(String username, AuthHeaderProvider authHeaderProvider, SharedPreferences prefs) {
     this.username = username;
     this.authHeaderProvider = authHeaderProvider;
     this.prefs = prefs;
     this.loadFromPrefs(prefs);
   }
 
   public SyncConfiguration(String username, AuthHeaderProvider authHeaderProvider, SharedPreferences prefs, KeyBundle syncKeyBundle) {
--- a/mobile/android/tests/background/junit3/src/sync/TestSyncConfiguration.java
+++ b/mobile/android/tests/background/junit3/src/sync/TestSyncConfiguration.java
@@ -4,28 +4,23 @@
 package org.mozilla.gecko.background.sync;
 
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
-import org.mozilla.gecko.sync.PrefsSource;
 import org.mozilla.gecko.sync.SyncConfiguration;
 
 import android.content.SharedPreferences;
 
-public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsSource {
+public class TestSyncConfiguration extends AndroidSyncTestCase {
   public static final String TEST_PREFS_NAME = "test";
 
-  /*
-   * PrefsSource methods.
-   */
-  @Override
   public SharedPreferences getPrefs(String name, int mode) {
     return this.getApplicationContext().getSharedPreferences(name, mode);
   }
 
   /**
    * Ensure that declined engines persist through prefs.
    */
   public void testDeclinedEngineNames() {
@@ -140,11 +135,11 @@ public class TestSyncConfiguration exten
     SyncConfiguration config = null;
     config = newSyncConfiguration();
     config.loadFromPrefs(prefs);
     // Forms should not be selected if history is not present.
     assertTrue(config.userSelectedEngines.isEmpty());
   }
 
   protected SyncConfiguration newSyncConfiguration() {
-    return new SyncConfiguration(null, null, TEST_PREFS_NAME, this);
+    return new SyncConfiguration(null, null, getPrefs(TEST_PREFS_NAME, 0));
   }
 }