Backed out changeset 569d58c88da3 (bug 922147)

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

View File

@ -552,6 +552,7 @@ sync_java_files = [
'sync/config/ClientRecordTerminator.java',
'sync/config/ConfigurationMigrator.java',
'sync/CredentialException.java',
'sync/CredentialsSource.java',
'sync/crypto/CryptoException.java',
'sync/crypto/CryptoInfo.java',
'sync/crypto/HKDF.java',
@ -786,8 +787,8 @@ sync_java_files = [
]
sync_generated_java_files = [
'background/common/GlobalConstants.java',
'sync/SyncConstants.java',
'background/announcements/AnnouncementsConstants.java',
'background/healthreport/HealthReportConstants.java',
'org/mozilla/gecko/background/announcements/AnnouncementsConstants.java',
'org/mozilla/gecko/background/common/GlobalConstants.java',
'org/mozilla/gecko/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.
// Eventually Fennec might listen to startup notifications and
// 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_HEALTHREPORT_UPLOAD_PREF_METHOD = "broadcastHealthReportUploadPref";
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.MetaGlobalDelegate;
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.HttpResponseObserver;
import org.mozilla.gecko.sync.net.SyncResponse;
@ -59,7 +58,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
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";
public static final String API_VERSION = "1.1";
@ -90,17 +89,39 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
/*
* Config passthrough for convenience.
*/
public AuthHeaderProvider getAuthHeaderProvider() {
return config.getAuthHeaderProvider();
@Override
public String credentials() {
return config.credentials();
}
public URI wboURI(String collection, String id) throws URISyntaxException {
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,
AuthHeaderProvider authHeaderProvider,
String password,
String prefsPath,
KeyBundle syncKeyBundle,
GlobalSessionCallback callback,
@ -108,13 +129,14 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
Bundle extras,
ClientsDataDelegate clientsDelegate)
throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException {
if (username == null) {
throw new IllegalArgumentException("username must not be null.");
}
if (callback == null) {
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);
URI serverURI;
try {
@ -133,9 +155,11 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
this.context = context;
this.clientsDelegate = clientsDelegate;
config = new SyncConfiguration(username, authHeaderProvider, prefsPath, this);
config = new SyncConfiguration(prefsPath, this);
config.userAPI = userAPI;
config.serverURL = serverURI;
config.username = username;
config.password = password;
config.syncKeyBundle = syncKeyBundle;
registerCommands();
@ -545,7 +569,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
}
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);
}
@ -560,6 +584,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
public void uploadKeys(final CollectionKeys keys,
final KeyUploadDelegate keyUploadDelegate) {
SyncStorageRecordRequest request;
final GlobalSession self = this;
try {
request = new SyncStorageRecordRequest(this.config.keysURI());
} catch (URISyntaxException e) {
@ -584,7 +609,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
@Override
public void handleRequestFailure(SyncStorageResponse response) {
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.
keyUploadDelegate.onKeyUploadFailed(new HTTPFailureException(response));
}
@ -596,8 +621,8 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return GlobalSession.this.getAuthHeaderProvider();
public String credentials() {
return self.credentials();
}
};
@ -723,7 +748,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
final MetaGlobal mg = session.generateNewMetaGlobal();
session.wipeServer(session.getAuthHeaderProvider(), new WipeServerDelegate() {
session.wipeServer(session, new WipeServerDelegate() {
@Override
public void onWiped(long timestamp) {
@ -823,12 +848,12 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
// reset client to prompt reupload.
// 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;
final GlobalSession self = this;
try {
request = new SyncStorageRequest(config.storageURL());
request = new SyncStorageRequest(config.storageURL(false));
} catch (URISyntaxException ex) {
Logger.warn(LOG_TAG, "Invalid URI in wipeServer.");
wipeDelegate.onWipeFailed(ex);
@ -864,8 +889,8 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return GlobalSession.this.getAuthHeaderProvider();
public String credentials() {
return credentials.credentials();
}
};
request.delete();
@ -957,6 +982,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
public MetaGlobal generateNewMetaGlobal() {
final String newSyncID = Utils.generateGuid();
final String metaURL = this.config.metaURL();
final String credentials = this.credentials();
ExtendedJSONObject engines = new ExtendedJSONObject();
for (String engineName : enabledEngineNames()) {
@ -976,7 +1002,7 @@ public class GlobalSession implements PrefsSource, HttpResponseObserver {
engines.put(engineName, engineSettings.toJSONObject());
}
MetaGlobal metaGlobal = new MetaGlobal(metaURL, this.getAuthHeaderProvider());
MetaGlobal metaGlobal = new MetaGlobal(metaURL, credentials);
metaGlobal.setSyncID(newSyncID);
metaGlobal.setStorageVersion(STORAGE_VERSION);
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.sync.delegates.JSONRecordFetchDelegate;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
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 String LOG_TAG = "JSONRecordFetcher";
protected final AuthHeaderProvider authHeaderProvider;
protected final String credentials;
protected final String uri;
protected JSONRecordFetchDelegate delegate;
public JSONRecordFetcher(final String uri, final AuthHeaderProvider authHeaderProvider) {
public JSONRecordFetcher(final String uri, final String credentials) {
this.uri = uri;
this.authHeaderProvider = authHeaderProvider;
this.credentials = credentials;
}
protected String getURI() {
@ -38,9 +37,8 @@ public class JSONRecordFetcher {
private class JSONFetchHandler implements SyncStorageRequestDelegate {
// SyncStorageRequestDelegate methods for fetching.
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
public String credentials() {
return credentials;
}
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.MetaGlobalMalformedVersionException;
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.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
@ -24,6 +23,7 @@ import org.mozilla.gecko.sync.net.SyncStorageResponse;
public class MetaGlobal implements SyncStorageRequestDelegate {
private static final String LOG_TAG = "MetaGlobal";
protected String metaURL;
protected String credentials;
// Fields.
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.
private boolean isUploading;
protected final AuthHeaderProvider authHeaderProvider;
public MetaGlobal(String metaURL, AuthHeaderProvider authHeaderProvider) {
this.metaURL = metaURL;
this.authHeaderProvider = authHeaderProvider;
public MetaGlobal(String metaURL, String credentials) {
this.metaURL = metaURL;
this.credentials = credentials;
}
public void fetch(MetaGlobalDelegate delegate) {
@ -248,12 +247,7 @@ public class MetaGlobal implements SyncStorageRequestDelegate {
// SyncStorageRequestDelegate methods for fetching.
public String credentials() {
return null;
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
return this.credentials;
}
public String ifUnmodifiedSince() {

View File

@ -5,7 +5,7 @@
package org.mozilla.gecko.sync;
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;
@ -32,7 +32,7 @@ public class PersistedMetaGlobal {
* @return <MetaGlobal> set from previously fetched meta/global record from
* 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);
if (json == null) {
return null;
@ -40,7 +40,7 @@ public class PersistedMetaGlobal {
MetaGlobal metaGlobal = null;
try {
CryptoRecord cryptoRecord = CryptoRecord.fromJSONRecord(json);
MetaGlobal mg = new MetaGlobal(metaUrl, authHeaderProvider);
MetaGlobal mg = new MetaGlobal(metaUrl, credentials);
mg.setFromRecord(cryptoRecord);
metaGlobal = mg;
} 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.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class SyncConfiguration {
public class SyncConfiguration implements CredentialsSource {
public class EditorBranch implements Editor {
@ -180,17 +179,18 @@ public class SyncConfiguration {
private static final String LOG_TAG = "SyncConfiguration";
// These must be set in GlobalSession's constructor.
public String userAPI;
public URI serverURL;
public URI clusterURL;
public String username;
public KeyBundle syncKeyBundle;
public CollectionKeys collectionKeys;
public InfoCollections infoCollections;
public MetaGlobal metaGlobal;
public String password;
public String syncID;
protected final String username;
/**
* Persisted collection of enabledEngineNames.
* <p>
@ -243,8 +243,6 @@ public class SyncConfiguration {
public String prefsPath;
public PrefsSource prefsSource;
protected final AuthHeaderProvider authHeaderProvider;
public static final String PREF_PREFS_VERSION = "prefs.version";
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
* provide access to preferences.
*/
public SyncConfiguration(String username, AuthHeaderProvider authHeaderProvider, String prefsPath, PrefsSource prefsSource) {
this.username = username;
this.authHeaderProvider = authHeaderProvider;
public SyncConfiguration(String prefsPath, PrefsSource prefsSource) {
this.prefsPath = prefsPath;
this.prefsSource = prefsSource;
this.loadFromPrefs(getPrefs());
@ -441,8 +437,9 @@ public class SyncConfiguration {
// TODO: keys.
}
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
@Override
public String credentials() {
return username + ":" + password;
}
public CollectionKeys getCollectionKeys() {
@ -481,20 +478,16 @@ public class SyncConfiguration {
}
public String metaURL() {
return storageURL() + "/meta/global";
return clusterURL + GlobalSession.API_VERSION + "/" + username + "/storage/meta/global";
}
/**
* Return path to storage endpoint without trailing slash.
*
* @return storage endpoint without trailing slash.
*/
public String storageURL() {
return clusterURL + GlobalSession.API_VERSION + "/" + username + "/storage";
public String storageURL(boolean trailingSlash) {
return clusterURL + GlobalSession.API_VERSION + "/" + username +
(trailingSlash ? "/storage/" : "/storage");
}
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 {
@ -509,12 +502,12 @@ public class SyncConfiguration {
}
uriParams = params.toString();
}
String uri = storageURL() + "/" + collection + uriParams;
String uri = storageURL(true) + collection + uriParams;
return new URI(uri);
}
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 {

View File

@ -8,7 +8,6 @@ import java.net.URI;
import org.mozilla.gecko.background.common.log.Logger;
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.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -28,9 +27,9 @@ public class ClientRecordTerminator {
}
public static void deleteClientRecord(final String username,
final String password,
final String clusterURL,
final String clientGuid,
final AuthHeaderProvider authHeaderProvider)
final String clientGuid)
throws Exception {
// 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);
r.delegate = new SyncStorageRequestDelegate() {
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
public String credentials() {
return username + ":" + password;
}
@Override

View File

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

View File

@ -5,8 +5,7 @@
package org.mozilla.gecko.sync.net;
public interface SyncStorageRequestDelegate {
public AuthHeaderProvider getAuthHeaderProvider();
String credentials();
String ifUnmodifiedSince();
// 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.config.AccountPickler;
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.SyncAccounts.SyncAccountParameters;
@ -130,7 +129,7 @@ public class SyncAccountDeletedService extends IntentService {
}
try {
ClientRecordTerminator.deleteClientRecord(encodedUsername, clusterURL, clientGuid, new BasicAuthHeaderProvider(encodedUsername, password));
ClientRecordTerminator.deleteClientRecord(encodedUsername, password, clusterURL, clientGuid);
} catch (Exception e) {
// 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);

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.sync.SyncConfiguration;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.config.ConfigurationMigrator;
import org.mozilla.gecko.sync.setup.Constants;
import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -53,7 +54,7 @@ public class UpgradeReceiver extends BroadcastReceiver {
final Account[] accounts = SyncAccounts.syncAccounts(context);
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;
try {

View File

@ -6,7 +6,7 @@ package org.mozilla.gecko.sync.repositories;
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.
@ -19,8 +19,9 @@ public class ConstrainedServer11Repository extends Server11Repository {
private String sort = null;
private long limit = -1;
public ConstrainedServer11Repository(String collection, String storageURL, AuthHeaderProvider authHeaderProvider, long limit, String sort) throws URISyntaxException {
super(collection, storageURL, authHeaderProvider);
public ConstrainedServer11Repository(String serverURI, String username, String collection, CredentialsSource credentialsSource, long limit, String sort) throws URISyntaxException {
super(serverURI, username, collection, credentialsSource);
this.limit = limit;
this.sort = sort;
}

View File

@ -8,8 +8,8 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import org.mozilla.gecko.sync.CredentialsSource;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate;
import android.content.Context;
@ -21,23 +21,33 @@ import android.content.Context;
* @author rnewman
*/
public class Server11Repository extends Repository {
private String serverURI;
private String username;
protected String collection;
protected URI collectionURI;
protected final AuthHeaderProvider authHeaderProvider;
private String collectionPath;
private URI collectionPathURI;
public CredentialsSource credentialsSource;
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 storageURL full URL to storage endpoint.
* @param authHeaderProvider to use in requests.
* @param serverURI
* URI of the Sync 1.1 server (string)
* @param username
* Username on the server (string)
* @param collection
* Name of the collection (string)
* @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.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
@ -47,7 +57,7 @@ public class Server11Repository extends Repository {
}
public URI collectionURI() {
return this.collectionURI;
return this.collectionPathURI;
}
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) {
return this.collectionURI;
return this.collectionPathURI;
}
StringBuilder out = new StringBuilder();
@ -81,12 +91,12 @@ public class Server11Repository extends Repository {
indicator = '&';
out.append(param);
}
String uri = this.collectionURI + out.toString();
String uri = this.collectionPath + out.toString();
return new URI(uri);
}
public URI wboURI(String id) throws URISyntaxException {
return new URI(this.collectionURI + "/" + id);
return new URI(this.collectionPath + "/" + id);
}
// Override these.
@ -99,8 +109,4 @@ public class Server11Repository extends Repository {
protected String getDefaultSort() {
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.UnexpectedJSONException;
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.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -136,8 +135,8 @@ public class Server11RepositorySession extends RepositorySession {
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return serverRepository.getAuthHeaderProvider();
public String credentials() {
return serverRepository.credentialsSource.credentials();
}
@Override
@ -443,8 +442,8 @@ public class Server11RepositorySession extends RepositorySession {
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return serverRepository.getAuthHeaderProvider();
public String credentials() {
return serverRepository.credentialsSource.credentials();
}
@Override

View File

@ -8,7 +8,6 @@ import java.net.URISyntaxException;
import org.mozilla.gecko.sync.JSONRecordFetcher;
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.Repository;
import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository;
@ -42,13 +41,11 @@ public class AndroidBrowserBookmarksServerSyncStage extends ServerSyncStage {
protected Repository getRemoteRepository() throws URISyntaxException {
// 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.
AuthHeaderProvider authHeaderProvider = session.getAuthHeaderProvider();
final JSONRecordFetcher countsFetcher = new JSONRecordFetcher(session.config.infoCollectionCountsURL(), authHeaderProvider);
String collection = getCollection();
return new SafeConstrainedServer11Repository(
collection,
session.config.storageURL(),
session.getAuthHeaderProvider(),
final JSONRecordFetcher countsFetcher = new JSONRecordFetcher(session.config.infoCollectionCountsURL(), session.credentials());
return new SafeConstrainedServer11Repository(session.config.getClusterURLString(),
session.config.username,
getCollection(),
session,
BOOKMARKS_REQUEST_LIMIT,
BOOKMARKS_SORT,
countsFetcher);

View File

@ -44,11 +44,10 @@ public class AndroidBrowserHistoryServerSyncStage extends ServerSyncStage {
@Override
protected Repository getRemoteRepository() throws URISyntaxException {
String collection = getCollection();
return new ConstrainedServer11Repository(
collection,
session.config.storageURL(),
session.getAuthHeaderProvider(),
return new ConstrainedServer11Repository(session.config.getClusterURLString(),
session.config.username,
getCollection(),
session,
HISTORY_REQUEST_LIMIT,
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.crypto.KeyBundle;
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.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
@ -64,8 +63,8 @@ implements SyncStorageRequestDelegate {
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return session.getAuthHeaderProvider();
public String credentials() {
return session.credentials();
}
@Override

View File

@ -62,7 +62,7 @@ public class FetchMetaGlobalStage extends AbstractNonRepositorySyncStage {
if (!infoCollections.updateNeeded(META_COLLECTION, lastModified)) {
// Try to use our local collection keys 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) {
Logger.info(LOG_TAG, "Using persisted meta/global for this session.");
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.
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));
}
}

View File

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

View File

@ -7,9 +7,9 @@ package org.mozilla.gecko.sync.stage;
import java.net.URISyntaxException;
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.JSONRecordFetcher;
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
import org.mozilla.gecko.sync.repositories.ConstrainedServer11Repository;
import org.mozilla.gecko.sync.repositories.Repository;
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.
private JSONRecordFetcher countFetcher;
public SafeConstrainedServer11Repository(String collection,
String storageURL,
AuthHeaderProvider authHeaderProvider,
public SafeConstrainedServer11Repository(String serverURI,
String username,
String collection,
CredentialsSource credentialsSource,
long limit,
String sort,
JSONRecordFetcher countFetcher)
throws URISyntaxException {
super(collection, storageURL, authHeaderProvider, limit, sort);
super(serverURI, username, collection, credentialsSource, limit, sort);
this.countFetcher = countFetcher;
}

View File

@ -11,6 +11,7 @@ import java.util.concurrent.ExecutorService;
import org.json.simple.parser.ParseException;
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.GlobalSession;
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.delegates.WipeServerDelegate;
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.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
@ -145,10 +145,10 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
// Override this in subclasses.
protected Repository getRemoteRepository() throws URISyntaxException {
String collection = getCollection();
return new Server11Repository(collection,
session.config.storageURL(),
session.getAuthHeaderProvider());
return new Server11Repository(session.config.getClusterURLString(),
session.config.username,
getCollection(),
session);
}
/**
@ -374,7 +374,7 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
/**
* 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;
try {
@ -415,8 +415,8 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
}
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return authHeaderProvider;
public String credentials() {
return credentials.credentials();
}
};
@ -436,7 +436,7 @@ public abstract class ServerSyncStage extends AbstractSessionManagingSyncStage i
final Runnable doWipe = new Runnable() {
@Override
public void run() {
wipeServer(session.getAuthHeaderProvider(), new WipeServerDelegate() {
wipeServer(session, new WipeServerDelegate() {
@Override
public void onWiped(long timestamp) {
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.KeyBundle;
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.SyncStorageCollectionRequest;
import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
@ -97,8 +96,8 @@ public class SyncClientsEngineStage extends AbstractSessionManagingSyncStage {
boolean localAccountGUIDDownloaded = false;
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return session.getAuthHeaderProvider();
public String credentials() {
return session.credentials();
}
@Override
@ -216,8 +215,8 @@ public class SyncClientsEngineStage extends AbstractSessionManagingSyncStage {
public boolean currentlyUploadingLocalRecord;
@Override
public AuthHeaderProvider getAuthHeaderProvider() {
return session.getAuthHeaderProvider();
public String credentials() {
return session.credentials();
}
private void setUploadDetails(boolean isLocalRecord) {

View File

@ -10,16 +10,16 @@ import java.security.NoSuchAlgorithmException;
import java.util.concurrent.atomic.AtomicBoolean;
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.sync.AlreadySyncingException;
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.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.SyncConstants;
import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.ThreadPool;
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.delegates.ClientsDataDelegate;
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.setup.Constants;
import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -504,8 +502,8 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
// TODO: default serverURL.
final KeyBundle keyBundle = new KeyBundle(username, syncKey);
final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(username, password);
GlobalSession globalSession = new GlobalSession(serverURL, username, authHeaderProvider, prefsPath,
GlobalSession globalSession = new GlobalSession(SyncConfiguration.DEFAULT_USER_API,
serverURL, username, password, prefsPath,
keyBundle, this, this.mContext, extras, this);
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.MockClientsDataDelegate;
import org.mozilla.gecko.sync.GlobalSession;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
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.domain.ClientRecord;
import org.mozilla.gecko.sync.stage.SyncClientsEngineStage;
@ -41,8 +41,9 @@ public class TestClientsStage extends AndroidSyncTestCase {
final ClientsDataDelegate delegate = new MockClientsDataDelegate();
final GlobalSession session = new GlobalSession(
SyncConfiguration.DEFAULT_USER_API,
null,
TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), null,
TEST_USERNAME, TEST_PASSWORD, null,
new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY),
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.MetaGlobalException;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.SynchronizerConfiguration;
import org.mozilla.gecko.sync.crypto.CryptoException;
import org.mozilla.gecko.sync.crypto.KeyBundle;
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.stage.NoSuchStageException;
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 {
return new GlobalSession(
SyncConfiguration.DEFAULT_USER_API,
null,
TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), null,
TEST_USERNAME, TEST_PASSWORD, null,
new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY),
callback, getApplicationContext(), null, null) {

View File

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

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import org.json.simple.parser.ParseException;
import org.mozilla.gecko.sync.EngineSettings;
import org.mozilla.gecko.sync.NonObjectJSONException;
import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
@ -22,7 +23,7 @@ public class MockGlobalSession extends MockPrefsGlobalSession {
public MockGlobalSession(String clusterURL, String username, String password,
KeyBundle syncKeyBundle, GlobalSessionCallback callback)
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

View File

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