1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/sync/Sync11Configuration.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.sync; 1.9 + 1.10 +import java.net.URI; 1.11 + 1.12 +import org.mozilla.gecko.background.common.log.Logger; 1.13 +import org.mozilla.gecko.sync.crypto.KeyBundle; 1.14 +import org.mozilla.gecko.sync.net.AuthHeaderProvider; 1.15 + 1.16 +import android.content.SharedPreferences; 1.17 +import android.content.SharedPreferences.Editor; 1.18 + 1.19 +/** 1.20 + * Override SyncConfiguration to restore the old behavior of clusterURL -- 1.21 + * that is, a URL without the protocol version etc. 1.22 + * 1.23 + */ 1.24 +public class Sync11Configuration extends SyncConfiguration { 1.25 + private static final String LOG_TAG = "Sync11Configuration"; 1.26 + private static final String API_VERSION = "1.1"; 1.27 + 1.28 + public Sync11Configuration(String username, 1.29 + AuthHeaderProvider authHeaderProvider, 1.30 + SharedPreferences prefs) { 1.31 + super(username, authHeaderProvider, prefs); 1.32 + } 1.33 + 1.34 + public Sync11Configuration(String username, 1.35 + AuthHeaderProvider authHeaderProvider, 1.36 + SharedPreferences prefs, 1.37 + KeyBundle keyBundle) { 1.38 + super(username, authHeaderProvider, prefs, keyBundle); 1.39 + } 1.40 + 1.41 + @Override 1.42 + public String getAPIVersion() { 1.43 + return API_VERSION; 1.44 + } 1.45 + 1.46 + @Override 1.47 + public String storageURL() { 1.48 + return clusterURL + API_VERSION + "/" + username + "/storage"; 1.49 + } 1.50 + 1.51 + @Override 1.52 + protected String infoBaseURL() { 1.53 + return clusterURL + API_VERSION + "/" + username + "/info/"; 1.54 + } 1.55 + 1.56 + protected void setAndPersistClusterURL(URI u, SharedPreferences prefs) { 1.57 + boolean shouldPersist = (prefs != null) && (clusterURL == null); 1.58 + 1.59 + Logger.trace(LOG_TAG, "Setting cluster URL to " + u.toASCIIString() + 1.60 + (shouldPersist ? ". Persisting." : ". Not persisting.")); 1.61 + clusterURL = u; 1.62 + if (shouldPersist) { 1.63 + Editor edit = prefs.edit(); 1.64 + edit.putString(PREF_CLUSTER_URL, clusterURL.toASCIIString()); 1.65 + edit.commit(); 1.66 + } 1.67 + } 1.68 + 1.69 + protected void setClusterURL(URI u, SharedPreferences prefs) { 1.70 + if (u == null) { 1.71 + Logger.warn(LOG_TAG, "Refusing to set cluster URL to null."); 1.72 + return; 1.73 + } 1.74 + URI uri = u.normalize(); 1.75 + if (uri.toASCIIString().endsWith("/")) { 1.76 + setAndPersistClusterURL(u, prefs); 1.77 + return; 1.78 + } 1.79 + setAndPersistClusterURL(uri.resolve("/"), prefs); 1.80 + Logger.trace(LOG_TAG, "Set cluster URL to " + clusterURL.toASCIIString() + ", given input " + u.toASCIIString()); 1.81 + } 1.82 + 1.83 + @Override 1.84 + public void setClusterURL(URI u) { 1.85 + setClusterURL(u, this.getPrefs()); 1.86 + } 1.87 +} 1.88 \ No newline at end of file