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 64% |
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..ec6de7a6ee1390ee99190d35f041ce3c1c9134d2 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,28 +1,24 @@ |
-// 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. |
+ * A helper class for managing sync state. |
* |
* 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. |
@@ -31,8 +27,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen |
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 +41,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen |
mSyncStatusHelper.registerSyncSettingsChangedObserver(this); |
mProfileSyncService = ProfileSyncService.get(mContext); |
mProfileSyncService.addSyncStateChangedListener(this); |
- |
- setupSessionSyncId(); |
mChromeSigninController.ensureGcmIsInitialized(); |
nyquist
2015/01/21 22:53:04
Could we move this to SigninManager and have it li
maxbogue
2015/01/21 23:37:56
Leaving as is per offline discussion.
|
} |
@@ -67,26 +59,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 +91,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 +120,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,7 +130,12 @@ 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); |
+ } |
} |
} |
@@ -174,12 +145,21 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen |
@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 +170,7 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen |
ThreadUtils.runOnUiThread(new Runnable() { |
@Override |
public void run() { |
- refreshSyncState(); |
+ updateSyncStateFromAndroid(); |
} |
}); |
} |