Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync; |
michael@0 | 6 | |
michael@0 | 7 | import java.net.URI; |
michael@0 | 8 | |
michael@0 | 9 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 10 | import org.mozilla.gecko.sync.crypto.KeyBundle; |
michael@0 | 11 | import org.mozilla.gecko.sync.net.AuthHeaderProvider; |
michael@0 | 12 | |
michael@0 | 13 | import android.content.SharedPreferences; |
michael@0 | 14 | import android.content.SharedPreferences.Editor; |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * Override SyncConfiguration to restore the old behavior of clusterURL -- |
michael@0 | 18 | * that is, a URL without the protocol version etc. |
michael@0 | 19 | * |
michael@0 | 20 | */ |
michael@0 | 21 | public class Sync11Configuration extends SyncConfiguration { |
michael@0 | 22 | private static final String LOG_TAG = "Sync11Configuration"; |
michael@0 | 23 | private static final String API_VERSION = "1.1"; |
michael@0 | 24 | |
michael@0 | 25 | public Sync11Configuration(String username, |
michael@0 | 26 | AuthHeaderProvider authHeaderProvider, |
michael@0 | 27 | SharedPreferences prefs) { |
michael@0 | 28 | super(username, authHeaderProvider, prefs); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | public Sync11Configuration(String username, |
michael@0 | 32 | AuthHeaderProvider authHeaderProvider, |
michael@0 | 33 | SharedPreferences prefs, |
michael@0 | 34 | KeyBundle keyBundle) { |
michael@0 | 35 | super(username, authHeaderProvider, prefs, keyBundle); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | @Override |
michael@0 | 39 | public String getAPIVersion() { |
michael@0 | 40 | return API_VERSION; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | @Override |
michael@0 | 44 | public String storageURL() { |
michael@0 | 45 | return clusterURL + API_VERSION + "/" + username + "/storage"; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | @Override |
michael@0 | 49 | protected String infoBaseURL() { |
michael@0 | 50 | return clusterURL + API_VERSION + "/" + username + "/info/"; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | protected void setAndPersistClusterURL(URI u, SharedPreferences prefs) { |
michael@0 | 54 | boolean shouldPersist = (prefs != null) && (clusterURL == null); |
michael@0 | 55 | |
michael@0 | 56 | Logger.trace(LOG_TAG, "Setting cluster URL to " + u.toASCIIString() + |
michael@0 | 57 | (shouldPersist ? ". Persisting." : ". Not persisting.")); |
michael@0 | 58 | clusterURL = u; |
michael@0 | 59 | if (shouldPersist) { |
michael@0 | 60 | Editor edit = prefs.edit(); |
michael@0 | 61 | edit.putString(PREF_CLUSTER_URL, clusterURL.toASCIIString()); |
michael@0 | 62 | edit.commit(); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | protected void setClusterURL(URI u, SharedPreferences prefs) { |
michael@0 | 67 | if (u == null) { |
michael@0 | 68 | Logger.warn(LOG_TAG, "Refusing to set cluster URL to null."); |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | URI uri = u.normalize(); |
michael@0 | 72 | if (uri.toASCIIString().endsWith("/")) { |
michael@0 | 73 | setAndPersistClusterURL(u, prefs); |
michael@0 | 74 | return; |
michael@0 | 75 | } |
michael@0 | 76 | setAndPersistClusterURL(uri.resolve("/"), prefs); |
michael@0 | 77 | Logger.trace(LOG_TAG, "Set cluster URL to " + clusterURL.toASCIIString() + ", given input " + u.toASCIIString()); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | @Override |
michael@0 | 81 | public void setClusterURL(URI u) { |
michael@0 | 82 | setClusterURL(u, this.getPrefs()); |
michael@0 | 83 | } |
michael@0 | 84 | } |