Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2487)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java

Issue 1698043006: Created the dialog offering the user to merge their account data or keep it (Closed) Base URL: maybelle.lon.corp.google.com:/usr/local/google/code/clankium/src@sync_settings
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..8b2c200d1e0b4f2aa19db1d1a0db6ef501cfb991
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java
@@ -0,0 +1,85 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.sync;
+
+import android.app.FragmentManager;
+import android.content.Context;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.text.TextUtils;
+
+import org.chromium.chrome.browser.preferences.SyncedAccountPreference;
+import org.chromium.chrome.browser.signin.SigninManager;
+import org.chromium.chrome.browser.signin.SigninManager.SignInCallback;
+import org.chromium.chrome.browser.sync.ui.ConfirmImportSyncDataDialog;
+import org.chromium.chrome.browser.sync.ui.ConfirmImportSyncDataDialog.ImportSyncType;
+
+/**
+ * A class that encapsulates the control flow of listeners and callbacks when switching sync
+ * accounts.
+ *
+ * Control flows through the method in this order:
+ * {@link OnPreferenceChangeListener#onPreferenceChange}
+ * {@link ConfirmImportSyncDataDialog.Listener#onConfirm}
+ * {@link SignInCallback#onSignInComplete}
+ */
+public class SyncAccountSwitcher
+ implements OnPreferenceChangeListener, ConfirmImportSyncDataDialog.Listener,
+ SignInCallback {
+ private static final String TAG = "SyncAccountSwitcher";
+
+ private final SyncedAccountPreference mSyncedAccountPreference;
+ private final Context mContext;
+ private final FragmentManager mFragmentManager;
+
+ private String mNewAccountName;
+
+ /**
+ * Sets up a SyncAccountSwitcher to be ready to accept callbacks.
+ * @param context Context used during signing the user in.
+ * @param fragmentManager To display the data sync fragment.
+ * @param syncedAccountPreference The preference to update once signin has been completed.
+ */
+ public SyncAccountSwitcher(Context context, FragmentManager fragmentManager,
+ SyncedAccountPreference syncedAccountPreference) {
+ mContext = context;
+ mFragmentManager = fragmentManager;
+ mSyncedAccountPreference = syncedAccountPreference;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference p, Object newValue) {
+ if (newValue == null) return false;
+
+ mNewAccountName = (String) newValue;
+ String currentAccount = mSyncedAccountPreference.getValue();
+
+ if (TextUtils.equals(mNewAccountName, currentAccount)) return false;
+
+ ConfirmImportSyncDataDialog.showNewInstance(currentAccount, mNewAccountName,
+ ImportSyncType.SWITCHING_SYNC_ACCOUNTS, mFragmentManager, this);
+
+ // Don't update the selected account in the preference. It will be updated by
+ // the call to mSyncAccountListPreference.update() if everything succeeds.
+ return false;
+ }
+
+ @Override
+ public void onConfirm() {
+ assert mNewAccountName != null;
+ SigninManager.get(mContext).signIn(mNewAccountName, null, this);
newt (away) 2016/02/25 18:01:32 we want to pass non-null here to get interactive s
PEConn 2016/02/25 20:45:12 Done.
+ }
+
+ @Override
+ public void onSignInComplete() {
+ // Update the Preference so it displays the correct account name.
+ mSyncedAccountPreference.update();
+ }
+
+ @Override
+ public void onSignInAborted() {
+ assert false : "Should not be able to abort sign in when switching sync accounts.";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698