mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-28 19:38:13 +00:00
Bug 996749 - Kill PrefsSource. r=rnewman
========6ced7b05cd
Author: Nick Alexander <nalexander@mozilla.com> Bug 996749 - Part 3: Finally kill PrefsSource. ========b37547fbd8
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. ========42e8fe761f
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.
This commit is contained in:
parent
acb00db975
commit
086431af3b
@ -690,7 +690,6 @@ sync_java_files = [
|
||||
'sync/NullClusterURLException.java',
|
||||
'sync/PersistedMetaGlobal.java',
|
||||
'sync/PrefsBackoffHandler.java',
|
||||
'sync/PrefsSource.java',
|
||||
'sync/receivers/SyncAccountDeletedReceiver.java',
|
||||
'sync/receivers/SyncAccountDeletedService.java',
|
||||
'sync/receivers/UpgradeReceiver.java',
|
||||
|
@ -5,13 +5,11 @@
|
||||
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;
|
||||
@ -25,16 +23,12 @@ 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
|
||||
|
@ -20,8 +20,6 @@ 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;
|
||||
@ -35,7 +33,6 @@ 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;
|
||||
@ -380,8 +377,9 @@ public class FxAccountSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
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);
|
||||
@ -391,7 +389,6 @@ public class FxAccountSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
@Override
|
||||
public void handleFailure(TokenServerException e) {
|
||||
debugAssertion(audience, assertion);
|
||||
handleError(e);
|
||||
}
|
||||
|
||||
@ -616,34 +613,4 @@ public class FxAccountSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +57,9 @@ 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;
|
||||
@ -277,14 +276,6 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* PrefsSource methods.
|
||||
*/
|
||||
@Override
|
||||
public SharedPreferences getPrefs(String name, int mode) {
|
||||
return this.getContext().getSharedPreferences(name, mode);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -261,14 +261,6 @@ public class SyncConfiguration {
|
||||
|
||||
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;
|
||||
|
@ -9,18 +9,13 @@ 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);
|
||||
}
|
||||
@ -145,6 +140,6 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
|
||||
}
|
||||
|
||||
protected SyncConfiguration newSyncConfiguration() {
|
||||
return new SyncConfiguration(null, null, TEST_PREFS_NAME, this);
|
||||
return new SyncConfiguration(null, null, getPrefs(TEST_PREFS_NAME, 0));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user