diff -r 000000000000 -r 6474c204b198 mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mobile/android/base/sync/SharedPreferencesClientsDataDelegate.java Wed Dec 31 06:09:35 2014 +0100
@@ -0,0 +1,57 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.sync;
+
+import org.mozilla.gecko.background.common.GlobalConstants;
+import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
+
+import android.content.SharedPreferences;
+
+/**
+ * A ClientsDataDelegate
implementation that persists to a
+ * SharedPreferences
instance.
+ */
+public class SharedPreferencesClientsDataDelegate implements ClientsDataDelegate {
+ protected final SharedPreferences sharedPreferences;
+
+ public SharedPreferencesClientsDataDelegate(SharedPreferences sharedPreferences) {
+ this.sharedPreferences = sharedPreferences;
+ }
+
+ @Override
+ public synchronized String getAccountGUID() {
+ String accountGUID = sharedPreferences.getString(SyncConfiguration.PREF_ACCOUNT_GUID, null);
+ if (accountGUID == null) {
+ accountGUID = Utils.generateGuid();
+ sharedPreferences.edit().putString(SyncConfiguration.PREF_ACCOUNT_GUID, accountGUID).commit();
+ }
+ return accountGUID;
+ }
+
+ @Override
+ public synchronized String getClientName() {
+ String clientName = sharedPreferences.getString(SyncConfiguration.PREF_CLIENT_NAME, null);
+ if (clientName == null) {
+ clientName = GlobalConstants.MOZ_APP_DISPLAYNAME + " on " + android.os.Build.MODEL;
+ sharedPreferences.edit().putString(SyncConfiguration.PREF_CLIENT_NAME, clientName).commit();
+ }
+ return clientName;
+ }
+
+ @Override
+ public synchronized void setClientsCount(int clientsCount) {
+ sharedPreferences.edit().putLong(SyncConfiguration.PREF_NUM_CLIENTS, (long) clientsCount).commit();
+ }
+
+ @Override
+ public boolean isLocalGUID(String guid) {
+ return getAccountGUID().equals(guid);
+ }
+
+ @Override
+ public synchronized int getClientsCount() {
+ return (int) sharedPreferences.getLong(SyncConfiguration.PREF_NUM_CLIENTS, 0);
+ }
+}