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

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

Issue 852473002: Prepare SyncController to replace a downstream component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove first line of SyncController comment. Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/sync/SyncController.java
diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/sync/SyncController.java b/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncController.java
similarity index 62%
rename from chrome/android/shell/java/src/org/chromium/chrome/shell/sync/SyncController.java
rename to chrome/android/java/src/org/chromium/chrome/browser/sync/SyncController.java
index c65ac9ce32c23f22b13caf6c92f3f8ced650a20e..df67f95a1b4f1fa3ce0ac0997acba6a7bc03feca 100644
--- a/chrome/android/shell/java/src/org/chromium/chrome/shell/sync/SyncController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/sync/SyncController.java
@@ -1,38 +1,41 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 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.shell.sync;
+package org.chromium.chrome.browser.sync;
import android.accounts.Account;
import android.app.Activity;
-import android.app.FragmentManager;
import android.content.Context;
import android.util.Log;
import org.chromium.base.ThreadUtils;
-import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory;
-import org.chromium.chrome.browser.identity.UuidBasedUniqueIdentificationGenerator;
import org.chromium.chrome.browser.invalidation.InvalidationController;
import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.chrome.browser.signin.SigninManager.SignInFlowObserver;
-import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.sync.notifier.SyncStatusHelper;
import org.chromium.sync.signin.AccountManagerHelper;
import org.chromium.sync.signin.ChromeSigninController;
/**
- * A helper class for managing sync state for the ChromeShell.
+ * SyncController handles the coordination of sync state between the invalidation controller,
+ * the Android sync settings, and the native sync code.
*
- * Builds on top of the ProfileSyncService (which manages Chrome's sync engine's state) and mimics
- * the minimum additional functionality needed to fully enable sync for Chrome on Android.
+ * Sync state can be changed from four places:
+ *
+ * - The Chrome UI, which will call SyncController directly.
+ * - Native sync, which can disable it via a dashboard stop and clear.
+ * - Android's Chrome sync setting.
+ * - Android's master sync setting.
+ *
+ * SyncController implements listeners for the last three cases. When master sync is disabled, we
+ * are careful to not change the Android Chrome sync setting so we know whether to turn sync back
+ * on when it is re-enabled.
*/
public class SyncController implements ProfileSyncService.SyncStateChangedListener,
SyncStatusHelper.SyncSettingsChangedObserver {
private static final String TAG = "SyncController";
- private static final String SESSIONS_UUID_PREF_KEY = "chromium.sync.sessions.id";
-
private static SyncController sInstance;
private final Context mContext;
@@ -47,8 +50,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
mSyncStatusHelper.registerSyncSettingsChangedObserver(this);
mProfileSyncService = ProfileSyncService.get(mContext);
mProfileSyncService.addSyncStateChangedListener(this);
-
- setupSessionSyncId();
mChromeSigninController.ensureGcmIsInitialized();
}
@@ -67,26 +68,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
}
/**
- * Open a dialog that gives the user the option to sign in from a list of available accounts.
- *
- * @param fragmentManager the FragmentManager.
- */
- public static void openSigninDialog(FragmentManager fragmentManager) {
- AccountChooserFragment chooserFragment = new AccountChooserFragment();
- chooserFragment.show(fragmentManager, null);
- }
-
- /**
- * Open a dialog that gives the user the option to sign out.
- *
- * @param fragmentManager the FragmentManager.
- */
- public static void openSignOutDialog(FragmentManager fragmentManager) {
- SignoutFragment signoutFragment = new SignoutFragment();
- signoutFragment.show(fragmentManager, null);
- }
-
- /**
* Trigger Chromium sign in of the given account.
*
* This also ensure that sync setup is not in progress anymore, so sync will start after
@@ -119,31 +100,23 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
});
}
- public void onStart() {
- refreshSyncState();
- }
-
- private void setupSessionSyncId() {
- // Ensure that sync uses the correct UniqueIdentificationGenerator, but do not force the
- // registration, in case a test case has already overridden it.
- UuidBasedUniqueIdentificationGenerator generator =
- new UuidBasedUniqueIdentificationGenerator(mContext, SESSIONS_UUID_PREF_KEY);
- UniqueIdentificationGeneratorFactory.registerGenerator(
- UuidBasedUniqueIdentificationGenerator.GENERATOR_ID, generator, false);
- // Since we do not override the UniqueIdentificationGenerator, we get it from the factory,
- // instead of using the instance we just created.
- mProfileSyncService.setSessionsId(UniqueIdentificationGeneratorFactory
- .getInstance(UuidBasedUniqueIdentificationGenerator.GENERATOR_ID));
- }
-
- private void refreshSyncState() {
- if (mSyncStatusHelper.isSyncEnabled())
+ /**
+ * Updates sync to reflect the state of the Android sync settings.
+ */
+ public void updateSyncStateFromAndroid() {
+ if (mSyncStatusHelper.isSyncEnabled()) {
start();
- else
+ } else {
stop();
+ }
}
- private void start() {
+ /**
+ * Starts sync if the master sync flag is enabled.
+ *
+ * Affects native sync, the invalidation controller, and the Android sync settings.
+ */
+ public void start() {
ThreadUtils.assertOnUiThread();
if (mSyncStatusHelper.isMasterSyncAutomaticallyEnabled()) {
Log.d(TAG, "Enabling sync");
@@ -156,6 +129,8 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
/**
* Stops Sync if a user is currently signed in.
+ *
+ * Affects native sync, the invalidation controller, and the Android sync settings.
*/
public void stop() {
ThreadUtils.assertOnUiThread();
@@ -164,22 +139,39 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
Account account = mChromeSigninController.getSignedInUser();
InvalidationController.get(mContext).stop();
mProfileSyncService.disableSync();
- mSyncStatusHelper.disableAndroidSync(account);
+ if (mSyncStatusHelper.isMasterSyncAutomaticallyEnabled()) {
+ // Only disable Android's Chrome sync setting if we weren't disabled
+ // by the master sync setting. This way, when master sync is enabled
+ // they will both be on and sync will start again.
+ mSyncStatusHelper.disableAndroidSync(account);
+ }
}
}
/**
* From {@link ProfileSyncService.SyncStateChangedListener}.
+ *
+ * Changes the invalidation controller and Android sync setting state to match
+ * the new native sync state.
*/
@Override
public void syncStateChanged() {
ThreadUtils.assertOnUiThread();
- // If sync has been disabled from the dashboard, we must disable it.
Account account = mChromeSigninController.getSignedInUser();
- boolean isSyncSuppressStart = mProfileSyncService.isStartSuppressed();
- boolean isSyncEnabled = mSyncStatusHelper.isSyncEnabled(account);
- if (account != null && isSyncSuppressStart && isSyncEnabled)
- stop();
+ // Don't do anything if there isn't an account.
+ if (account == null) return;
+ boolean isSyncActive = !mProfileSyncService.isStartSuppressed();
+ // Make the Java state match the native state.
+ if (isSyncActive) {
+ InvalidationController.get(mContext).start();
+ mSyncStatusHelper.enableAndroidSync(account);
+ } else {
+ InvalidationController.get(mContext).stop();
+ if (mSyncStatusHelper.isMasterSyncAutomaticallyEnabled()) {
+ // See comment in stop().
+ mSyncStatusHelper.disableAndroidSync(account);
+ }
+ }
}
/**
@@ -190,7 +182,7 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
- refreshSyncState();
+ updateSyncStateFromAndroid();
}
});
}
« no previous file with comments | « no previous file | chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698