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

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..e3a5940778cef4f453574c9d539cc6b8c15f66d4
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncAccountSwitcher.java
@@ -0,0 +1,111 @@
+// 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.BrowsingDataType;
+import org.chromium.chrome.browser.ChromeBrowserProviderClient;
+import org.chromium.chrome.browser.preferences.PrefServiceBridge;
+import org.chromium.chrome.browser.preferences.PrefServiceBridge.OnClearBrowsingDataListener;
+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.ConfirmImportSyncDataFragment;
+
+/**
+ * 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 ConfirmImportSyncDataFragment.Listener#onDialogCompleted}
+ * {@link OnClearBrowsingDataListener#OnClearBrowsingDataListener}
+ * (if the user chooses to merge their data, this step is skipped)
+ * {@link SignInCallback#onSignInComplete}
+ */
+public class SyncAccountSwitcher
+ implements OnPreferenceChangeListener, ConfirmImportSyncDataFragment.Listener,
+ OnClearBrowsingDataListener, SignInCallback {
+ private static final String TAG = "SyncAccountSwitcher";
+
+ private static final String CONFIRM_IMPORT_SYNC_DATA_DIALOG_TAG =
+ "confirm_import_sync_data_tag";
+
+ private static final int[] SYNC_DATA_TYPES = {
+ BrowsingDataType.HISTORY,
+ BrowsingDataType.CACHE,
+ BrowsingDataType.COOKIES,
+ BrowsingDataType.PASSWORDS,
+ BrowsingDataType.FORM_DATA
+ };
+
+ private final SyncedAccountPreference mSyncedAccountPreference;
+ private final Context mContext;
+ private final FragmentManager mFragmentManager;
+
+ private String mNewAccountName;
+
+ public SyncAccountSwitcher(Context c, FragmentManager fm, SyncedAccountPreference pref) {
+ mSyncedAccountPreference = pref;
+ mContext = c;
+ mFragmentManager = fm;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference p, Object newValue) {
+ if (newValue == null) return false;
+
+ SyncedAccountPreference preference = (SyncedAccountPreference) p;
+ mNewAccountName = preference.valueToEntry((String) newValue);
+ String currentAccount = preference.getEntry().toString();
+
+ if (TextUtils.equals(mNewAccountName, currentAccount)) return false;
+
+ ConfirmImportSyncDataFragment confirmSync =
+ ConfirmImportSyncDataFragment.newInstance(currentAccount, mNewAccountName);
+ confirmSync.setListener(this);
+ confirmSync.show(mFragmentManager, CONFIRM_IMPORT_SYNC_DATA_DIALOG_TAG);
+
+ // 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 onDialogCompleted(boolean mergeData) {
+ if (!mergeData) {
+ ChromeBrowserProviderClient.removeAllUserBookmarks(mContext);
+ PrefServiceBridge.getInstance().clearBrowsingData(this, SYNC_DATA_TYPES);
May 2016/02/17 14:22:11 Don't you still need to sign in the new account at
PEConn 2016/02/17 17:16:48 Yes, but not before the browsing data has been cle
+ } else {
+ signin();
+ }
+ }
+
+ @Override
+ public void onBrowsingDataCleared() {
+ signin();
+ }
+
+ private void signin() {
+ assert mNewAccountName != null;
+ SigninManager.get(mContext).signIn(mNewAccountName, null, this);
+ }
+
+ @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