Backed out changeset 569d58c88da3 (bug 922147)

This commit is contained in:
Nick Alexander 2013-11-13 17:03:18 -08:00
parent de986f8d9a
commit 694c8edb52
29 changed files with 187 additions and 186 deletions

View File

@ -552,6 +552,7 @@ sync_java_files = [
'sync/config/ClientRecordTerminator.java', 'sync/config/ClientRecordTerminator.java',
'sync/config/ConfigurationMigrator.java', 'sync/config/ConfigurationMigrator.java',
'sync/CredentialException.java', 'sync/CredentialException.java',
'sync/CredentialsSource.java',
'sync/crypto/CryptoException.java', 'sync/crypto/CryptoException.java',
'sync/crypto/CryptoInfo.java', 'sync/crypto/CryptoInfo.java',
'sync/crypto/HKDF.java', 'sync/crypto/HKDF.java',
@ -786,8 +787,8 @@ sync_java_files = [
] ]
sync_generated_java_files = [ sync_generated_java_files = [
'background/common/GlobalConstants.java', 'org/mozilla/gecko/background/announcements/AnnouncementsConstants.java',
'sync/SyncConstants.java', 'org/mozilla/gecko/background/common/GlobalConstants.java',
'background/announcements/AnnouncementsConstants.java', 'org/mozilla/gecko/background/healthreport/HealthReportConstants.java',
'background/healthreport/HealthReportConstants.java', 'org/mozilla/gecko/sync/SyncConstants.java',
] ]

View File

@ -44,7 +44,7 @@ public class GlobalConstants {
// Fennec's prefs branch and pref name. // Fennec's prefs branch and pref name.
// Eventually Fennec might listen to startup notifications and // Eventually Fennec might listen to startup notifications and
// do this automatically, but this will do for now. See Bug 800244. // do this automatically, but this will do for now. See Bug 800244.
public static String GECKO_PREFERENCES_CLASS = "org.mozilla.gecko.GeckoPreferences"; public static String GECKO_PREFERENCES_CLASS = "org.mozilla.gecko.preferences.GeckoPreferences";
public static String GECKO_BROADCAST_ANNOUNCEMENTS_PREF_METHOD = "broadcastAnnouncementsPref"; public static String GECKO_BROADCAST_ANNOUNCEMENTS_PREF_METHOD = "broadcastAnnouncementsPref";
public static String GECKO_BROADCAST_HEALTHREPORT_UPLOAD_PREF_METHOD = "broadcastHealthReportUploadPref"; public static String GECKO_BROADCAST_HEALTHREPORT_UPLOAD_PREF_METHOD = "broadcastHealthReportUploadPref";
public static String GECKO_BROADCAST_HEALTHREPORT_PRUNE_METHOD = "broadcastHealthReportPrune"; public static String GECKO_BROADCAST_HEALTHREPORT_PRUNE_METHOD = "broadcastHealthReportPrune";

View File

@ -29,7 +29,6 @@ import org.mozilla.gecko.sync.delegates.JSONRecordFetchDelegate;
import org.mozilla.gecko.sync.delegates.KeyUploadDelegate; import org.mozilla.gecko.sync.delegates.KeyUploadDelegate;
import org.mozilla.gecko.sync.delegates.MetaGlobalDelegate; import org.mozilla.gecko.sync.delegates.MetaGlobalDelegate;
import org.mozilla.gecko.sync.delegates.WipeServerDelegate; import org.mozilla.gecko.sync.delegates.WipeServerDelegate;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BaseResource; import org.mozilla.gecko.sync.net.BaseResource;
import org.mozilla.gecko.sync.net.HttpResponseObserver; import org.mozilla.gecko.sync.net.HttpResponseObserver;
import org.mozilla.gecko.sync.net.SyncResponse; import org.mozilla.gecko.sync.net.SyncResponse;
@ -59,7 +58,7 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import ch.boye.httpclientandroidlib.HttpResponse; import ch.boye.httpclientandroidlib.HttpResponse;
public class GlobalSession implements PrefsSource, HttpResponseObserver { public class GlobalSession implements CredentialsSource, PrefsSource, HttpResponseObserver {
private static final String LOG_TAG = "GlobalSession"; private static final String LOG_TAG = "GlobalSession";
public static final String API_VERSION = "1.1"; public static final String API_VERSION = "1.1";
@ -90,17 +89,39 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
/* /*
* Config passthrough for convenience. * Config passthrough for convenience.
*/ */
public AuthHeaderProvider getAuthHeaderProvider() { @Override
return config.getAuthHeaderProvider(); public String credentials() {
return config.credentials();
} }
public URI wboURI(String collection, String id) throws URISyntaxException { public URI wboURI(String collection, String id) throws URISyntaxException {
return config.wboURI(collection, id); return config.wboURI(collection, id);
} }
public GlobalSession(String serverURL, /*
* Validators.
*/
private static boolean isInvalidString(String s) {
return s == null ||
s.trim().length() == 0;
}
private static boolean anyInvalidStrings(String s, String...strings) {
if (isInvalidString(s)) {
return true;
}
for (String str : strings) {
if (isInvalidString(str)) {
return true;
}
}
return false;
}
public GlobalSession(String userAPI,
String serverURL,
String username, String username,
AuthHeaderProvider authHeaderProvider, String password,
String prefsPath, String prefsPath,
KeyBundle syncKeyBundle, KeyBundle syncKeyBundle,
GlobalSessionCallback callback, GlobalSessionCallback callback,
@ -108,13 +129,14 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
Bundle extras, Bundle extras,
ClientsDataDelegate clientsDelegate) ClientsDataDelegate clientsDelegate)
throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException { throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException {
if (username == null) {
throw new IllegalArgumentException("username must not be null.");
}
if (callback == null) { if (callback == null) {
throw new IllegalArgumentException("Must provide a callback to GlobalSession constructor."); throw new IllegalArgumentException("Must provide a callback to GlobalSession constructor.");
} }
if (anyInvalidStrings(username, password)) {
throw new SyncConfigurationException();
}
Logger.debug(LOG_TAG, "GlobalSession initialized with bundle " + extras); Logger.debug(LOG_TAG, "GlobalSession initialized with bundle " + extras);
URI serverURI; URI serverURI;
try { try {
@ -133,9 +155,11 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
this.context = context; this.context = context;
this.clientsDelegate = clientsDelegate; this.clientsDelegate = clientsDelegate;
config = new SyncConfiguration(username, authHeaderProvider, prefsPath, this); config = new SyncConfiguration(prefsPath, this);
config.userAPI = userAPI;
config.serverURL = serverURI; config.serverURL = serverURI;
config.username = username;
config.password = password;
config.syncKeyBundle = syncKeyBundle; config.syncKeyBundle = syncKeyBundle;
registerCommands(); registerCommands();
@ -545,7 +569,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
} }
public void fetchInfoCollections(JSONRecordFetchDelegate callback) throws URISyntaxException { public void fetchInfoCollections(JSONRecordFetchDelegate callback) throws URISyntaxException {
final JSONRecordFetcher fetcher = new JSONRecordFetcher(config.infoCollectionsURL(), getAuthHeaderProvider()); final JSONRecordFetcher fetcher = new JSONRecordFetcher(config.infoCollectionsURL(), credentials());
fetcher.fetch(callback); fetcher.fetch(callback);
} }
@ -560,6 +584,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
public void uploadKeys(final CollectionKeys keys, public void uploadKeys(final CollectionKeys keys,
final KeyUploadDelegate keyUploadDelegate) { final KeyUploadDelegate keyUploadDelegate) {
SyncStorageRecordRequest request; SyncStorageRecordRequest request;
final GlobalSession self = this;
try { try {
request = new SyncStorageRecordRequest(this.config.keysURI()); request = new SyncStorageRecordRequest(this.config.keysURI());
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
@ -584,7 +609,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
@Override @Override
public void handleRequestFailure(SyncStorageResponse response) { public void handleRequestFailure(SyncStorageResponse response) {
Logger.debug(LOG_TAG, "Failed to upload keys."); Logger.debug(LOG_TAG, "Failed to upload keys.");
GlobalSession.this.interpretHTTPFailure(response.httpResponse()); self.interpretHTTPFailure(response.httpResponse());
BaseResource.consumeEntity(response); // The exception thrown should not need the body of the response. BaseResource.consumeEntity(response); // The exception thrown should not need the body of the response.
keyUploadDelegate.onKeyUploadFailed(new HTTPFailureException(response)); keyUploadDelegate.onKeyUploadFailed(new HTTPFailureException(response));
} }
@ -596,8 +621,8 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return GlobalSession.this.getAuthHeaderProvider(); return self.credentials();
} }
}; };
@ -723,7 +748,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
final MetaGlobal mg = session.generateNewMetaGlobal(); final MetaGlobal mg = session.generateNewMetaGlobal();
session.wipeServer(session.getAuthHeaderProvider(), new WipeServerDelegate() { session.wipeServer(session, new WipeServerDelegate() {
@Override @Override
public void onWiped(long timestamp) { public void onWiped(long timestamp) {
@ -823,12 +848,12 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
// reset client to prompt reupload. // reset client to prompt reupload.
// If sync ID mismatch: take that syncID and reset client. // If sync ID mismatch: take that syncID and reset client.
protected void wipeServer(final AuthHeaderProvider authHeaderProvider, final WipeServerDelegate wipeDelegate) { protected void wipeServer(final CredentialsSource credentials, final WipeServerDelegate wipeDelegate) {
SyncStorageRequest request; SyncStorageRequest request;
final GlobalSession self = this; final GlobalSession self = this;
try { try {
request = new SyncStorageRequest(config.storageURL()); request = new SyncStorageRequest(config.storageURL(false));
} catch (URISyntaxException ex) { } catch (URISyntaxException ex) {
Logger.warn(LOG_TAG, "Invalid URI in wipeServer."); Logger.warn(LOG_TAG, "Invalid URI in wipeServer.");
wipeDelegate.onWipeFailed(ex); wipeDelegate.onWipeFailed(ex);
@ -864,8 +889,8 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return GlobalSession.this.getAuthHeaderProvider(); return credentials.credentials();
} }
}; };
request.delete(); request.delete();
@ -957,6 +982,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
public MetaGlobal generateNewMetaGlobal() { public MetaGlobal generateNewMetaGlobal() {
final String newSyncID = Utils.generateGuid(); final String newSyncID = Utils.generateGuid();
final String metaURL = this.config.metaURL(); final String metaURL = this.config.metaURL();
final String credentials = this.credentials();
ExtendedJSONObject engines = new ExtendedJSONObject(); ExtendedJSONObject engines = new ExtendedJSONObject();
for (String engineName : enabledEngineNames()) { for (String engineName : enabledEngineNames()) {
@ -976,7 +1002,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
engines.put(engineName, engineSettings.toJSONObject()); engines.put(engineName, engineSettings.toJSONObject());
} }
MetaGlobal metaGlobal = new MetaGlobal(metaURL, this.getAuthHeaderProvider()); MetaGlobal metaGlobal = new MetaGlobal(metaURL, credentials);
metaGlobal.setSyncID(newSyncID); metaGlobal.setSyncID(newSyncID);
metaGlobal.setStorageVersion(STORAGE_VERSION); metaGlobal.setStorageVersion(STORAGE_VERSION);
metaGlobal.setEngines(engines); metaGlobal.setEngines(engines);

View File

@ -9,7 +9,6 @@ import java.util.concurrent.TimeUnit;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.delegates.JSONRecordFetchDelegate; import org.mozilla.gecko.sync.delegates.JSONRecordFetchDelegate;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse; import org.mozilla.gecko.sync.net.SyncStorageResponse;
@ -22,13 +21,13 @@ public class JSONRecordFetcher {
private static final long DEFAULT_AWAIT_TIMEOUT_MSEC = 2 * 60 * 1000; // Two minutes. private static final long DEFAULT_AWAIT_TIMEOUT_MSEC = 2 * 60 * 1000; // Two minutes.
private static final String LOG_TAG = "JSONRecordFetcher"; private static final String LOG_TAG = "JSONRecordFetcher";
protected final AuthHeaderProvider authHeaderProvider; protected final String credentials;
protected final String uri; protected final String uri;
protected JSONRecordFetchDelegate delegate; protected JSONRecordFetchDelegate delegate;
public JSONRecordFetcher(final String uri, final AuthHeaderProvider authHeaderProvider) { public JSONRecordFetcher(final String uri, final String credentials) {
this.uri = uri; this.uri = uri;
this.authHeaderProvider = authHeaderProvider; this.credentials = credentials;
} }
protected String getURI() { protected String getURI() {
@ -38,9 +37,8 @@ public class JSONRecordFetcher {
private class JSONFetchHandler implements SyncStorageRequestDelegate { private class JSONFetchHandler implements SyncStorageRequestDelegate {
// SyncStorageRequestDelegate methods for fetching. // SyncStorageRequestDelegate methods for fetching.
@Override public String credentials() {
public AuthHeaderProvider getAuthHeaderProvider() { return credentials;
return authHeaderProvider;
} }
public String ifUnmodifiedSince() { public String ifUnmodifiedSince() {

View File

@ -16,7 +16,6 @@ import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.MetaGlobalException.MetaGlobalMalformedSyncIDException; import org.mozilla.gecko.sync.MetaGlobalException.MetaGlobalMalformedSyncIDException;
import org.mozilla.gecko.sync.MetaGlobalException.MetaGlobalMalformedVersionException; import org.mozilla.gecko.sync.MetaGlobalException.MetaGlobalMalformedVersionException;
import org.mozilla.gecko.sync.delegates.MetaGlobalDelegate; import org.mozilla.gecko.sync.delegates.MetaGlobalDelegate;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse; import org.mozilla.gecko.sync.net.SyncStorageResponse;
@ -24,6 +23,7 @@ import org.mozilla.gecko.sync.net.SyncStorageResponse;
public class MetaGlobal implements SyncStorageRequestDelegate { public class MetaGlobal implements SyncStorageRequestDelegate {
private static final String LOG_TAG = "MetaGlobal"; private static final String LOG_TAG = "MetaGlobal";
protected String metaURL; protected String metaURL;
protected String credentials;
// Fields. // Fields.
protected ExtendedJSONObject engines; protected ExtendedJSONObject engines;
@ -40,11 +40,10 @@ public class MetaGlobal implements SyncStorageRequestDelegate {
// A little hack so we can use the same delegate implementation for upload and download. // A little hack so we can use the same delegate implementation for upload and download.
private boolean isUploading; private boolean isUploading;
protected final AuthHeaderProvider authHeaderProvider;
public MetaGlobal(String metaURL, AuthHeaderProvider authHeaderProvider) { public MetaGlobal(String metaURL, String credentials) {
this.metaURL = metaURL; this.metaURL = metaURL;
this.authHeaderProvider = authHeaderProvider; this.credentials = credentials;
} }
public void fetch(MetaGlobalDelegate delegate) { public void fetch(MetaGlobalDelegate delegate) {
@ -248,12 +247,7 @@ public class MetaGlobal implements SyncStorageRequestDelegate {
// SyncStorageRequestDelegate methods for fetching. // SyncStorageRequestDelegate methods for fetching.
public String credentials() { public String credentials() {
return null; return this.credentials;
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
} }
public String ifUnmodifiedSince() { public String ifUnmodifiedSince() {

View File

@ -5,7 +5,7 @@
package org.mozilla.gecko.sync; package org.mozilla.gecko.sync;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.net.AuthHeaderProvider; import org.mozilla.gecko.sync.CryptoRecord;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -32,7 +32,7 @@ public class PersistedMetaGlobal {
* @return <MetaGlobal> set from previously fetched meta/global record from * @return <MetaGlobal> set from previously fetched meta/global record from
* server * server
*/ */
public MetaGlobal metaGlobal(String metaUrl, AuthHeaderProvider authHeaderProvider) { public MetaGlobal metaGlobal(String metaUrl, String credentials) {
String json = prefs.getString(META_GLOBAL_SERVER_RESPONSE_BODY, null); String json = prefs.getString(META_GLOBAL_SERVER_RESPONSE_BODY, null);
if (json == null) { if (json == null) {
return null; return null;
@ -40,7 +40,7 @@ public class PersistedMetaGlobal {
MetaGlobal metaGlobal = null; MetaGlobal metaGlobal = null;
try { try {
CryptoRecord cryptoRecord = CryptoRecord.fromJSONRecord(json); CryptoRecord cryptoRecord = CryptoRecord.fromJSONRecord(json);
MetaGlobal mg = new MetaGlobal(metaUrl, authHeaderProvider); MetaGlobal mg = new MetaGlobal(metaUrl, credentials);
mg.setFromRecord(cryptoRecord); mg.setFromRecord(cryptoRecord);
metaGlobal = mg; metaGlobal = mg;
} catch (Exception e) { } catch (Exception e) {

View File

@ -16,13 +16,12 @@ import java.util.Set;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys; import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
public class SyncConfiguration { public class SyncConfiguration implements CredentialsSource {
public class EditorBranch implements Editor { public class EditorBranch implements Editor {
@ -180,17 +179,18 @@ public class SyncConfiguration {
private static final String LOG_TAG = "SyncConfiguration"; private static final String LOG_TAG = "SyncConfiguration";
// These must be set in GlobalSession's constructor. // These must be set in GlobalSession's constructor.
public String userAPI;
public URI serverURL; public URI serverURL;
public URI clusterURL; public URI clusterURL;
public String username;
public KeyBundle syncKeyBundle; public KeyBundle syncKeyBundle;
public CollectionKeys collectionKeys; public CollectionKeys collectionKeys;
public InfoCollections infoCollections; public InfoCollections infoCollections;
public MetaGlobal metaGlobal; public MetaGlobal metaGlobal;
public String password;
public String syncID; public String syncID;
protected final String username;
/** /**
* Persisted collection of enabledEngineNames. * Persisted collection of enabledEngineNames.
* <p> * <p>
@ -243,8 +243,6 @@ public class SyncConfiguration {
public String prefsPath; public String prefsPath;
public PrefsSource prefsSource; public PrefsSource prefsSource;
protected final AuthHeaderProvider authHeaderProvider;
public static final String PREF_PREFS_VERSION = "prefs.version"; public static final String PREF_PREFS_VERSION = "prefs.version";
public static final long CURRENT_PREFS_VERSION = 1; public static final long CURRENT_PREFS_VERSION = 1;
@ -269,9 +267,7 @@ public class SyncConfiguration {
* Create a new SyncConfiguration instance. Pass in a PrefsSource to * Create a new SyncConfiguration instance. Pass in a PrefsSource to
* provide access to preferences. * provide access to preferences.
*/ */
public SyncConfiguration(String username, AuthHeaderProvider authHeaderProvider, String prefsPath, PrefsSource prefsSource) { public SyncConfiguration(String prefsPath, PrefsSource prefsSource) {
this.username = username;
this.authHeaderProvider = authHeaderProvider;
this.prefsPath = prefsPath; this.prefsPath = prefsPath;
this.prefsSource = prefsSource; this.prefsSource = prefsSource;
this.loadFromPrefs(getPrefs()); this.loadFromPrefs(getPrefs());
@ -441,8 +437,9 @@ public class SyncConfiguration {
// TODO: keys. // TODO: keys.
} }
public AuthHeaderProvider getAuthHeaderProvider() { @Override
return authHeaderProvider; public String credentials() {
return username + ":" + password;
} }
public CollectionKeys getCollectionKeys() { public CollectionKeys getCollectionKeys() {
@ -481,20 +478,16 @@ public class SyncConfiguration {
} }
public String metaURL() { public String metaURL() {
return storageURL() + "/meta/global"; return clusterURL + GlobalSession.API_VERSION + "/" + username + "/storage/meta/global";
} }
/** public String storageURL(boolean trailingSlash) {
* Return path to storage endpoint without trailing slash. return clusterURL + GlobalSession.API_VERSION + "/" + username +
* (trailingSlash ? "/storage/" : "/storage");
* @return storage endpoint without trailing slash.
*/
public String storageURL() {
return clusterURL + GlobalSession.API_VERSION + "/" + username + "/storage";
} }
public URI collectionURI(String collection) throws URISyntaxException { public URI collectionURI(String collection) throws URISyntaxException {
return new URI(storageURL() + "/" + collection); return new URI(storageURL(true) + collection);
} }
public URI collectionURI(String collection, boolean full) throws URISyntaxException { public URI collectionURI(String collection, boolean full) throws URISyntaxException {
@ -509,12 +502,12 @@ public class SyncConfiguration {
} }
uriParams = params.toString(); uriParams = params.toString();
} }
String uri = storageURL() + "/" + collection + uriParams; String uri = storageURL(true) + collection + uriParams;
return new URI(uri); return new URI(uri);
} }
public URI wboURI(String collection, String id) throws URISyntaxException { public URI wboURI(String collection, String id) throws URISyntaxException {
return new URI(storageURL() + "/" + collection + "/" + id); return new URI(storageURL(true) + collection + "/" + id);
} }
public URI keysURI() throws URISyntaxException { public URI keysURI() throws URISyntaxException {

View File

@ -8,7 +8,6 @@ import java.net.URI;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BaseResource; import org.mozilla.gecko.sync.net.BaseResource;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -28,9 +27,9 @@ public class ClientRecordTerminator {
} }
public static void deleteClientRecord(final String username, public static void deleteClientRecord(final String username,
final String password,
final String clusterURL, final String clusterURL,
final String clientGuid, final String clientGuid)
final AuthHeaderProvider authHeaderProvider)
throws Exception { throws Exception {
// Would prefer to delegate to SyncConfiguration, but that would proliferate static methods. // Would prefer to delegate to SyncConfiguration, but that would proliferate static methods.
@ -41,8 +40,8 @@ public class ClientRecordTerminator {
final SyncStorageRecordRequest r = new SyncStorageRecordRequest(wboURI); final SyncStorageRecordRequest r = new SyncStorageRecordRequest(wboURI);
r.delegate = new SyncStorageRequestDelegate() { r.delegate = new SyncStorageRequestDelegate() {
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return authHeaderProvider; return username + ":" + password;
} }
@Override @Override

View File

@ -92,7 +92,12 @@ public class SyncStorageRequest implements Resource {
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public AuthHeaderProvider getAuthHeaderProvider() {
return request.delegate.getAuthHeaderProvider(); String credentials = request.delegate.credentials();
if (credentials == null) {
return null;
}
return new BasicAuthHeaderProvider(credentials);
} }
@Override @Override

View File

@ -5,8 +5,7 @@
package org.mozilla.gecko.sync.net; package org.mozilla.gecko.sync.net;
public interface SyncStorageRequestDelegate { public interface SyncStorageRequestDelegate {
public AuthHeaderProvider getAuthHeaderProvider(); String credentials();
String ifUnmodifiedSince(); String ifUnmodifiedSince();
// TODO: at this point we can access X-Weave-Timestamp, compare // TODO: at this point we can access X-Weave-Timestamp, compare

View File

@ -12,7 +12,6 @@ import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.config.AccountPickler; import org.mozilla.gecko.sync.config.AccountPickler;
import org.mozilla.gecko.sync.config.ClientRecordTerminator; import org.mozilla.gecko.sync.config.ClientRecordTerminator;
import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
import org.mozilla.gecko.sync.setup.Constants; import org.mozilla.gecko.sync.setup.Constants;
import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters; import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
@ -130,7 +129,7 @@ public class SyncAccountDeletedService extends IntentService {
} }
try { try {
ClientRecordTerminator.deleteClientRecord(encodedUsername, clusterURL, clientGuid, new BasicAuthHeaderProvider(encodedUsername, password)); ClientRecordTerminator.deleteClientRecord(encodedUsername, password, clusterURL, clientGuid);
} catch (Exception e) { } catch (Exception e) {
// This should never happen, but we really don't want to die in a background thread. // This should never happen, but we really don't want to die in a background thread.
Logger.warn(LOG_TAG, "Got exception deleting client record from server; ignoring.", e); Logger.warn(LOG_TAG, "Got exception deleting client record from server; ignoring.", e);

View File

@ -9,6 +9,7 @@ import org.mozilla.gecko.background.common.GlobalConstants;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.SyncConfiguration; import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.ThreadPool; import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.config.ConfigurationMigrator; import org.mozilla.gecko.sync.config.ConfigurationMigrator;
import org.mozilla.gecko.sync.setup.Constants; import org.mozilla.gecko.sync.setup.Constants;
import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -53,7 +54,7 @@ public class UpgradeReceiver extends BroadcastReceiver {
final Account[] accounts = SyncAccounts.syncAccounts(context); final Account[] accounts = SyncAccounts.syncAccounts(context);
for (Account account : accounts) { for (Account account : accounts) {
Logger.info(LOG_TAG, "Migrating preferences on upgrade for Android account named " + account.name + "."); Logger.info(LOG_TAG, "Migrating preferences on upgrade for Android account named " + Utils.obfuscateEmail(account.name) + ".");
SyncAccountParameters params; SyncAccountParameters params;
try { try {

View File

@ -6,7 +6,7 @@ package org.mozilla.gecko.sync.repositories;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.mozilla.gecko.sync.net.AuthHeaderProvider; import org.mozilla.gecko.sync.CredentialsSource;
/** /**
* A kind of Server11Repository that supports explicit setting of limit and sort on operations. * A kind of Server11Repository that supports explicit setting of limit and sort on operations.
@ -19,8 +19,9 @@ public class ConstrainedServer11Repository extends Server11Repository {
private String sort = null; private String sort = null;
private long limit = -1; private long limit = -1;
public ConstrainedServer11Repository(String collection, String storageURL, AuthHeaderProvider authHeaderProvider, long limit, String sort) throws URISyntaxException { public ConstrainedServer11Repository(String serverURI, String username, String collection, CredentialsSource credentialsSource, long limit, String sort) throws URISyntaxException {
super(collection, storageURL, authHeaderProvider); super(serverURI, username, collection, credentialsSource);
this.limit = limit; this.limit = limit;
this.sort = sort; this.sort = sort;
} }

View File

@ -8,8 +8,8 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import org.mozilla.gecko.sync.CredentialsSource;
import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context; import android.content.Context;
@ -21,23 +21,33 @@ import android.content.Context;
* @author rnewman * @author rnewman
*/ */
public class Server11Repository extends Repository { public class Server11Repository extends Repository {
private String serverURI;
private String username;
protected String collection; protected String collection;
protected URI collectionURI; private String collectionPath;
protected final AuthHeaderProvider authHeaderProvider; private URI collectionPathURI;
public CredentialsSource credentialsSource;
public static final String VERSION_PATH_FRAGMENT = "1.1/"; public static final String VERSION_PATH_FRAGMENT = "1.1/";
/** /**
* Construct a new repository that fetches and stores against the Sync 1.1. API.
* *
* @param collection name. * @param serverURI
* @param storageURL full URL to storage endpoint. * URI of the Sync 1.1 server (string)
* @param authHeaderProvider to use in requests. * @param username
* Username on the server (string)
* @param collection
* Name of the collection (string)
* @throws URISyntaxException * @throws URISyntaxException
*/ */
public Server11Repository(String collection, String storageURL, AuthHeaderProvider authHeaderProvider) throws URISyntaxException { public Server11Repository(String serverURI, String username, String collection, CredentialsSource credentialsSource) throws URISyntaxException {
this.serverURI = serverURI;
this.username = username;
this.collection = collection; this.collection = collection;
this.collectionURI = new URI(storageURL + (storageURL.endsWith("/") ? collection : "/" + collection));
this.authHeaderProvider = authHeaderProvider; this.collectionPath = this.serverURI + VERSION_PATH_FRAGMENT + this.username + "/storage/" + this.collection;
this.collectionPathURI = new URI(this.collectionPath);
this.credentialsSource = credentialsSource;
} }
@Override @Override
@ -47,7 +57,7 @@ public class Server11Repository extends Repository {
} }
public URI collectionURI() { public URI collectionURI() {
return this.collectionURI; return this.collectionPathURI;
} }
public URI collectionURI(boolean full, long newer, long limit, String sort, String ids) throws URISyntaxException { public URI collectionURI(boolean full, long newer, long limit, String sort, String ids) throws URISyntaxException {
@ -71,7 +81,7 @@ public class Server11Repository extends Repository {
} }
if (params.size() == 0) { if (params.size() == 0) {
return this.collectionURI; return this.collectionPathURI;
} }
StringBuilder out = new StringBuilder(); StringBuilder out = new StringBuilder();
@ -81,12 +91,12 @@ public class Server11Repository extends Repository {
indicator = '&'; indicator = '&';
out.append(param); out.append(param);
} }
String uri = this.collectionURI + out.toString(); String uri = this.collectionPath + out.toString();
return new URI(uri); return new URI(uri);
} }
public URI wboURI(String id) throws URISyntaxException { public URI wboURI(String id) throws URISyntaxException {
return new URI(this.collectionURI + "/" + id); return new URI(this.collectionPath + "/" + id);
} }
// Override these. // Override these.
@ -99,8 +109,4 @@ public class Server11Repository extends Repository {
protected String getDefaultSort() { protected String getDefaultSort() {
return null; return null;
} }
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
}
} }

View File

@ -25,7 +25,6 @@ import org.mozilla.gecko.sync.Server11PreviousPostFailedException;
import org.mozilla.gecko.sync.Server11RecordPostFailedException; import org.mozilla.gecko.sync.Server11RecordPostFailedException;
import org.mozilla.gecko.sync.UnexpectedJSONException; import org.mozilla.gecko.sync.UnexpectedJSONException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest; import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequest; import org.mozilla.gecko.sync.net.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -136,8 +135,8 @@ public class Server11RepositorySession extends RepositorySession {
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return serverRepository.getAuthHeaderProvider(); return serverRepository.credentialsSource.credentials();
} }
@Override @Override
@ -443,8 +442,8 @@ public class Server11RepositorySession extends RepositorySession {
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return serverRepository.getAuthHeaderProvider(); return serverRepository.credentialsSource.credentials();
} }
@Override @Override

View File

@ -8,7 +8,6 @@ import java.net.URISyntaxException;
import org.mozilla.gecko.sync.JSONRecordFetcher; import org.mozilla.gecko.sync.JSONRecordFetcher;
import org.mozilla.gecko.sync.MetaGlobalException; import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.RecordFactory; import org.mozilla.gecko.sync.repositories.RecordFactory;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository; import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository;
@ -42,13 +41,11 @@ public class AndroidBrowserBookmarksServerSyncStage extends ServerSyncStage {
protected Repository getRemoteRepository() throws URISyntaxException { protected Repository getRemoteRepository() throws URISyntaxException {
// If this is a first sync, we need to check server counts to make sure that we aren't // If this is a first sync, we need to check server counts to make sure that we aren't
// going to screw up. SafeConstrainedServer11Repository does this. See Bug 814331. // going to screw up. SafeConstrainedServer11Repository does this. See Bug 814331.
AuthHeaderProvider authHeaderProvider = session.getAuthHeaderProvider(); final JSONRecordFetcher countsFetcher = new JSONRecordFetcher(session.config.infoCollectionCountsURL(), session.credentials());
final JSONRecordFetcher countsFetcher = new JSONRecordFetcher(session.config.infoCollectionCountsURL(), authHeaderProvider); return new SafeConstrainedServer11Repository(session.config.getClusterURLString(),
String collection = getCollection(); session.config.username,
return new SafeConstrainedServer11Repository( getCollection(),
collection, session,
session.config.storageURL(),
session.getAuthHeaderProvider(),
BOOKMARKS_REQUEST_LIMIT, BOOKMARKS_REQUEST_LIMIT,
BOOKMARKS_SORT, BOOKMARKS_SORT,
countsFetcher); countsFetcher);

View File

@ -44,11 +44,10 @@ public class AndroidBrowserHistoryServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getRemoteRepository() throws URISyntaxException { protected Repository getRemoteRepository() throws URISyntaxException {
String collection = getCollection(); return new ConstrainedServer11Repository(session.config.getClusterURLString(),
return new ConstrainedServer11Repository( session.config.username,
collection, getCollection(),
session.config.storageURL(), session,
session.getAuthHeaderProvider(),
HISTORY_REQUEST_LIMIT, HISTORY_REQUEST_LIMIT,
HISTORY_SORT); HISTORY_SORT);
} }

View File

@ -16,7 +16,6 @@ import org.mozilla.gecko.sync.InfoCollections;
import org.mozilla.gecko.sync.NoCollectionKeysSetException; import org.mozilla.gecko.sync.NoCollectionKeysSetException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys; import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse; import org.mozilla.gecko.sync.net.SyncStorageResponse;
@ -64,8 +63,8 @@ implements SyncStorageRequestDelegate {
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return session.getAuthHeaderProvider(); return session.credentials();
} }
@Override @Override

View File

@ -62,7 +62,7 @@ public class FetchMetaGlobalStage extends AbstractNonRepositorySyncStage {
if (!infoCollections.updateNeeded(META_COLLECTION, lastModified)) { if (!infoCollections.updateNeeded(META_COLLECTION, lastModified)) {
// Try to use our local collection keys for this session. // Try to use our local collection keys for this session.
Logger.info(LOG_TAG, "Trying to use persisted meta/global for this session."); Logger.info(LOG_TAG, "Trying to use persisted meta/global for this session.");
MetaGlobal global = session.config.persistedMetaGlobal().metaGlobal(session.config.metaURL(), session.getAuthHeaderProvider()); MetaGlobal global = session.config.persistedMetaGlobal().metaGlobal(session.config.metaURL(), session.credentials());
if (global != null) { if (global != null) {
Logger.info(LOG_TAG, "Using persisted meta/global for this session."); Logger.info(LOG_TAG, "Using persisted meta/global for this session.");
session.processMetaGlobal(global); // Calls session.advance(). session.processMetaGlobal(global); // Calls session.advance().
@ -73,7 +73,7 @@ public class FetchMetaGlobalStage extends AbstractNonRepositorySyncStage {
// We need an update: fetch or upload meta/global as necessary. // We need an update: fetch or upload meta/global as necessary.
Logger.info(LOG_TAG, "Fetching fresh meta/global for this session."); Logger.info(LOG_TAG, "Fetching fresh meta/global for this session.");
MetaGlobal global = new MetaGlobal(session.config.metaURL(), session.getAuthHeaderProvider()); MetaGlobal global = new MetaGlobal(session.config.metaURL(), session.credentials());
global.fetch(new StageMetaGlobalDelegate(session)); global.fetch(new StageMetaGlobalDelegate(session));
} }
} }

View File

@ -39,11 +39,10 @@ public class FormHistoryServerSyncStage extends ServerSyncStage {
@Override @Override
protected Repository getRemoteRepository() throws URISyntaxException { protected Repository getRemoteRepository() throws URISyntaxException {
String collection = getCollection(); return new ConstrainedServer11Repository(session.config.getClusterURLString(),
return new ConstrainedServer11Repository( session.config.username,
collection, getCollection(),
session.config.storageURL(), session,
session.getAuthHeaderProvider(),
FORM_HISTORY_REQUEST_LIMIT, FORM_HISTORY_REQUEST_LIMIT,
FORM_HISTORY_SORT); FORM_HISTORY_SORT);
} }

View File

@ -7,9 +7,9 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.CredentialsSource;
import org.mozilla.gecko.sync.InfoCounts; import org.mozilla.gecko.sync.InfoCounts;
import org.mozilla.gecko.sync.JSONRecordFetcher; import org.mozilla.gecko.sync.JSONRecordFetcher;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository; import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.Repository; import org.mozilla.gecko.sync.repositories.Repository;
import org.mozilla.gecko.sync.repositories.Server11RepositorySession; import org.mozilla.gecko.sync.repositories.Server11RepositorySession;
@ -32,14 +32,15 @@ public class SafeConstrainedServer11Repository extends ConstrainedServer11Reposi
// This can be lazily evaluated if we need it. // This can be lazily evaluated if we need it.
private JSONRecordFetcher countFetcher; private JSONRecordFetcher countFetcher;
public SafeConstrainedServer11Repository(String collection, public SafeConstrainedServer11Repository(String serverURI,
String storageURL, String username,
AuthHeaderProvider authHeaderProvider, String collection,
CredentialsSource credentialsSource,
long limit, long limit,
String sort, String sort,
JSONRecordFetcher countFetcher) JSONRecordFetcher countFetcher)
throws URISyntaxException { throws URISyntaxException {
super(collection, storageURL, authHeaderProvider, limit, sort); super(serverURI, username, collection, credentialsSource, limit, sort);
this.countFetcher = countFetcher; this.countFetcher = countFetcher;
} }

View File

@ -11,6 +11,7 @@ import java.util.concurrent.ExecutorService;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.CredentialsSource;
import org.mozilla.gecko.sync.EngineSettings; import org.mozilla.gecko.sync.EngineSettings;
import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.HTTPFailureException; import org.mozilla.gecko.sync.HTTPFailureException;
@ -22,7 +23,6 @@ import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.WipeServerDelegate; import org.mozilla.gecko.sync.delegates.WipeServerDelegate;
import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository; import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BaseResource; import org.mozilla.gecko.sync.net.BaseResource;
import org.mozilla.gecko.sync.net.SyncStorageRequest; import org.mozilla.gecko.sync.net.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -145,10 +145,10 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
// Override this in subclasses. // Override this in subclasses.
protected Repository getRemoteRepository() throws URISyntaxException { protected Repository getRemoteRepository() throws URISyntaxException {
String collection = getCollection(); return new Server11Repository(session.config.getClusterURLString(),
return new Server11Repository(collection, session.config.username,
session.config.storageURL(), getCollection(),
session.getAuthHeaderProvider()); session);
} }
/** /**
@ -374,7 +374,7 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
/** /**
* Asynchronously wipe collection on server. * Asynchronously wipe collection on server.
*/ */
protected void wipeServer(final AuthHeaderProvider authHeaderProvider, final WipeServerDelegate wipeDelegate) { protected void wipeServer(final CredentialsSource credentials, final WipeServerDelegate wipeDelegate) {
SyncStorageRequest request; SyncStorageRequest request;
try { try {
@ -415,8 +415,8 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
} }
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return authHeaderProvider; return credentials.credentials();
} }
}; };
@ -436,7 +436,7 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
final Runnable doWipe = new Runnable() { final Runnable doWipe = new Runnable() {
@Override @Override
public void run() { public void run() {
wipeServer(session.getAuthHeaderProvider(), new WipeServerDelegate() { wipeServer(session, new WipeServerDelegate() {
@Override @Override
public void onWiped(long timestamp) { public void onWiped(long timestamp) {
synchronized (monitor) { synchronized (monitor) {

View File

@ -24,7 +24,6 @@ import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.crypto.CryptoException; import org.mozilla.gecko.sync.crypto.CryptoException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BaseResource; import org.mozilla.gecko.sync.net.BaseResource;
import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest; import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
@ -97,8 +96,8 @@ public class SyncClientsEngineStage extends AbstractSessionManagingSyncStage {
boolean localAccountGUIDDownloaded = false; boolean localAccountGUIDDownloaded = false;
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return session.getAuthHeaderProvider(); return session.credentials();
} }
@Override @Override
@ -216,8 +215,8 @@ public class SyncClientsEngineStage extends AbstractSessionManagingSyncStage {
public boolean currentlyUploadingLocalRecord; public boolean currentlyUploadingLocalRecord;
@Override @Override
public AuthHeaderProvider getAuthHeaderProvider() { public String credentials() {
return session.getAuthHeaderProvider(); return session.credentials();
} }
private void setUploadDetails(boolean isLocalRecord) { private void setUploadDetails(boolean isLocalRecord) {

View File

@ -10,16 +10,16 @@ import java.security.NoSuchAlgorithmException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.mozilla.gecko.background.common.GlobalConstants;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.sync.AlreadySyncingException; import org.mozilla.gecko.sync.AlreadySyncingException;
import org.mozilla.gecko.sync.CredentialException; import org.mozilla.gecko.sync.CredentialException;
import org.mozilla.gecko.background.common.GlobalConstants;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.sync.SyncConstants;
import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.NonObjectJSONException; import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration; import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException; import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.SyncConstants;
import org.mozilla.gecko.sync.SyncException; import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.ThreadPool; import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.Utils;
@ -28,8 +28,6 @@ import org.mozilla.gecko.sync.crypto.CryptoException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
import org.mozilla.gecko.sync.net.ConnectionMonitorThread; import org.mozilla.gecko.sync.net.ConnectionMonitorThread;
import org.mozilla.gecko.sync.setup.Constants; import org.mozilla.gecko.sync.setup.Constants;
import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -504,8 +502,8 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
// TODO: default serverURL. // TODO: default serverURL.
final KeyBundle keyBundle = new KeyBundle(username, syncKey); final KeyBundle keyBundle = new KeyBundle(username, syncKey);
final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(username, password); GlobalSession globalSession = new GlobalSession(SyncConfiguration.DEFAULT_USER_API,
GlobalSession globalSession = new GlobalSession(serverURL, username, authHeaderProvider, prefsPath, serverURL, username, password, prefsPath,
keyBundle, this, this.mContext, extras, this); keyBundle, this, this.mContext, extras, this);
globalSession.start(); globalSession.start();

View File

@ -8,10 +8,10 @@ import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
import org.mozilla.gecko.background.testhelpers.DefaultGlobalSessionCallback; import org.mozilla.gecko.background.testhelpers.DefaultGlobalSessionCallback;
import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate; import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate;
import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor;
import org.mozilla.gecko.sync.repositories.domain.ClientRecord; import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
import org.mozilla.gecko.sync.stage.SyncClientsEngineStage; import org.mozilla.gecko.sync.stage.SyncClientsEngineStage;
@ -41,8 +41,9 @@ public class TestClientsStage extends AndroidSyncTestCase {
final ClientsDataDelegate delegate = new MockClientsDataDelegate(); final ClientsDataDelegate delegate = new MockClientsDataDelegate();
final GlobalSession session = new GlobalSession( final GlobalSession session = new GlobalSession(
SyncConfiguration.DEFAULT_USER_API,
null, null,
TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), null, TEST_USERNAME, TEST_PASSWORD, null,
new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY),
callback, context, null, delegate); callback, context, null, delegate);

View File

@ -16,12 +16,12 @@ import org.mozilla.gecko.sync.EngineSettings;
import org.mozilla.gecko.sync.GlobalSession; import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.MetaGlobalException; import org.mozilla.gecko.sync.MetaGlobalException;
import org.mozilla.gecko.sync.NonObjectJSONException; import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException; import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.SynchronizerConfiguration; import org.mozilla.gecko.sync.SynchronizerConfiguration;
import org.mozilla.gecko.sync.crypto.CryptoException; import org.mozilla.gecko.sync.crypto.CryptoException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.domain.Record; import org.mozilla.gecko.sync.repositories.domain.Record;
import org.mozilla.gecko.sync.stage.NoSuchStageException; import org.mozilla.gecko.sync.stage.NoSuchStageException;
import org.mozilla.gecko.sync.synchronizer.Synchronizer; import org.mozilla.gecko.sync.synchronizer.Synchronizer;
@ -153,8 +153,9 @@ public class TestResetting extends AndroidSyncTestCase {
private GlobalSession createDefaultGlobalSession(final GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, ParseException, CryptoException { private GlobalSession createDefaultGlobalSession(final GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, ParseException, CryptoException {
return new GlobalSession( return new GlobalSession(
SyncConfiguration.DEFAULT_USER_API,
null, null,
TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), null, TEST_USERNAME, TEST_PASSWORD, null,
new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY),
callback, getApplicationContext(), null, null) { callback, getApplicationContext(), null, null) {

View File

@ -29,13 +29,13 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
SyncConfiguration config = null; SyncConfiguration config = null;
SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0);
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
config.enabledEngineNames = new HashSet<String>(); config.enabledEngineNames = new HashSet<String>();
config.enabledEngineNames.add("test1"); config.enabledEngineNames.add("test1");
config.enabledEngineNames.add("test2"); config.enabledEngineNames.add("test2");
config.persistToPrefs(); config.persistToPrefs();
assertTrue(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES)); assertTrue(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES));
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
Set<String> expected = new HashSet<String>(); Set<String> expected = new HashSet<String>();
for (String name : new String[] { "test1", "test2" }) { for (String name : new String[] { "test1", "test2" }) {
expected.add(name); expected.add(name);
@ -45,7 +45,7 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
config.enabledEngineNames = null; config.enabledEngineNames = null;
config.persistToPrefs(); config.persistToPrefs();
assertFalse(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES)); assertFalse(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES));
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
assertNull(config.enabledEngineNames); assertNull(config.enabledEngineNames);
} }
@ -53,11 +53,11 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
SyncConfiguration config = null; SyncConfiguration config = null;
SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0);
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
config.syncID = "test1"; config.syncID = "test1";
config.persistToPrefs(); config.persistToPrefs();
assertTrue(prefs.contains(SyncConfiguration.PREF_SYNC_ID)); assertTrue(prefs.contains(SyncConfiguration.PREF_SYNC_ID));
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
assertEquals("test1", config.syncID); assertEquals("test1", config.syncID);
} }
@ -74,7 +74,7 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
// Read values from selectedEngines. // Read values from selectedEngines.
assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC));
SyncConfiguration config = null; SyncConfiguration config = null;
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
config.loadFromPrefs(prefs); config.loadFromPrefs(prefs);
assertEquals(expectedEngines, config.userSelectedEngines); assertEquals(expectedEngines, config.userSelectedEngines);
} }
@ -95,7 +95,7 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
// Read values from selectedEngines. // Read values from selectedEngines.
assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC));
SyncConfiguration config = null; SyncConfiguration config = null;
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
config.loadFromPrefs(prefs); config.loadFromPrefs(prefs);
assertEquals(storedEngines, config.userSelectedEngines); assertEquals(storedEngines, config.userSelectedEngines);
} }
@ -111,13 +111,9 @@ public class TestSyncConfiguration extends AndroidSyncTestCase implements PrefsS
// Read values from selectedEngines. // Read values from selectedEngines.
assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC));
SyncConfiguration config = null; SyncConfiguration config = null;
config = newSyncConfiguration(); config = new SyncConfiguration(TEST_PREFS_NAME, this);
config.loadFromPrefs(prefs); config.loadFromPrefs(prefs);
// Forms should not be selected if history is not present. // Forms should not be selected if history is not present.
assertTrue(config.userSelectedEngines.isEmpty()); assertTrue(config.userSelectedEngines.isEmpty());
} }
protected SyncConfiguration newSyncConfiguration() {
return new SyncConfiguration(null, null, TEST_PREFS_NAME, this);
}
} }

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.mozilla.gecko.sync.EngineSettings; import org.mozilla.gecko.sync.EngineSettings;
import org.mozilla.gecko.sync.NonObjectJSONException; import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException; import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
@ -22,7 +23,7 @@ public class MockGlobalSession extends MockPrefsGlobalSession {
public MockGlobalSession(String clusterURL, String username, String password, public MockGlobalSession(String clusterURL, String username, String password,
KeyBundle syncKeyBundle, GlobalSessionCallback callback) KeyBundle syncKeyBundle, GlobalSessionCallback callback)
throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException { throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException {
super(clusterURL, username, password, null, syncKeyBundle, callback, /* context */ null, null, null); super(SyncConfiguration.DEFAULT_USER_API, clusterURL, username, password, null, syncKeyBundle, callback, /* context */ null, null, null);
} }
@Override @Override

View File

@ -12,8 +12,6 @@ import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.crypto.KeyBundle; import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -26,22 +24,13 @@ public class MockPrefsGlobalSession extends GlobalSession {
public MockSharedPreferences prefs; public MockSharedPreferences prefs;
public MockPrefsGlobalSession(String serverURL, public MockPrefsGlobalSession(String userAPI, String serverURL,
String username, String password, String prefsPath, String username, String password, String prefsPath,
KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context,
Bundle extras, ClientsDataDelegate clientsDelegate) Bundle extras, ClientsDataDelegate clientsDelegate)
throws SyncConfigurationException, IllegalArgumentException, IOException, throws SyncConfigurationException, IllegalArgumentException, IOException,
ParseException, NonObjectJSONException { ParseException, NonObjectJSONException {
this(serverURL, username, new BasicAuthHeaderProvider(username, password), prefsPath, syncKeyBundle, callback, context, extras, clientsDelegate); super(userAPI, serverURL, username, password, prefsPath, syncKeyBundle,
}
public MockPrefsGlobalSession(String serverURL,
String username, AuthHeaderProvider authHeaderProvider, String prefsPath,
KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context,
Bundle extras, ClientsDataDelegate clientsDelegate)
throws SyncConfigurationException, IllegalArgumentException, IOException,
ParseException, NonObjectJSONException {
super(serverURL, username, authHeaderProvider, prefsPath, syncKeyBundle,
callback, context, extras, clientsDelegate); callback, context, extras, clientsDelegate);
} }
@ -58,4 +47,4 @@ public class MockPrefsGlobalSession extends GlobalSession {
return null; return null;
} }
} }