michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync; michael@0: michael@0: import java.net.URI; michael@0: michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: import org.mozilla.gecko.sync.crypto.KeyBundle; michael@0: import org.mozilla.gecko.sync.net.AuthHeaderProvider; michael@0: michael@0: import android.content.SharedPreferences; michael@0: import android.content.SharedPreferences.Editor; michael@0: michael@0: /** michael@0: * Override SyncConfiguration to restore the old behavior of clusterURL -- michael@0: * that is, a URL without the protocol version etc. michael@0: * michael@0: */ michael@0: public class Sync11Configuration extends SyncConfiguration { michael@0: private static final String LOG_TAG = "Sync11Configuration"; michael@0: private static final String API_VERSION = "1.1"; michael@0: michael@0: public Sync11Configuration(String username, michael@0: AuthHeaderProvider authHeaderProvider, michael@0: SharedPreferences prefs) { michael@0: super(username, authHeaderProvider, prefs); michael@0: } michael@0: michael@0: public Sync11Configuration(String username, michael@0: AuthHeaderProvider authHeaderProvider, michael@0: SharedPreferences prefs, michael@0: KeyBundle keyBundle) { michael@0: super(username, authHeaderProvider, prefs, keyBundle); michael@0: } michael@0: michael@0: @Override michael@0: public String getAPIVersion() { michael@0: return API_VERSION; michael@0: } michael@0: michael@0: @Override michael@0: public String storageURL() { michael@0: return clusterURL + API_VERSION + "/" + username + "/storage"; michael@0: } michael@0: michael@0: @Override michael@0: protected String infoBaseURL() { michael@0: return clusterURL + API_VERSION + "/" + username + "/info/"; michael@0: } michael@0: michael@0: protected void setAndPersistClusterURL(URI u, SharedPreferences prefs) { michael@0: boolean shouldPersist = (prefs != null) && (clusterURL == null); michael@0: michael@0: Logger.trace(LOG_TAG, "Setting cluster URL to " + u.toASCIIString() + michael@0: (shouldPersist ? ". Persisting." : ". Not persisting.")); michael@0: clusterURL = u; michael@0: if (shouldPersist) { michael@0: Editor edit = prefs.edit(); michael@0: edit.putString(PREF_CLUSTER_URL, clusterURL.toASCIIString()); michael@0: edit.commit(); michael@0: } michael@0: } michael@0: michael@0: protected void setClusterURL(URI u, SharedPreferences prefs) { michael@0: if (u == null) { michael@0: Logger.warn(LOG_TAG, "Refusing to set cluster URL to null."); michael@0: return; michael@0: } michael@0: URI uri = u.normalize(); michael@0: if (uri.toASCIIString().endsWith("/")) { michael@0: setAndPersistClusterURL(u, prefs); michael@0: return; michael@0: } michael@0: setAndPersistClusterURL(uri.resolve("/"), prefs); michael@0: Logger.trace(LOG_TAG, "Set cluster URL to " + clusterURL.toASCIIString() + ", given input " + u.toASCIIString()); michael@0: } michael@0: michael@0: @Override michael@0: public void setClusterURL(URI u) { michael@0: setClusterURL(u, this.getPrefs()); michael@0: } michael@0: }