| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.sync; | 5 package org.chromium.chrome.browser.sync; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Starts sync if the master sync flag is enabled. | 115 * Starts sync if the master sync flag is enabled. |
| 116 * | 116 * |
| 117 * Affects native sync, the invalidation controller, and the Android sync se
ttings. | 117 * Affects native sync, the invalidation controller, and the Android sync se
ttings. |
| 118 */ | 118 */ |
| 119 public void start() { | 119 public void start() { |
| 120 ThreadUtils.assertOnUiThread(); | 120 ThreadUtils.assertOnUiThread(); |
| 121 if (mAndroidSyncSettings.isMasterSyncEnabled()) { | 121 if (mAndroidSyncSettings.isMasterSyncEnabled()) { |
| 122 Log.d(TAG, "Enabling sync"); | 122 Log.d(TAG, "Enabling sync"); |
| 123 Account account = mChromeSigninController.getSignedInUser(); | |
| 124 InvalidationController.get(mContext).start(); | 123 InvalidationController.get(mContext).start(); |
| 125 mProfileSyncService.enableSync(); | 124 mProfileSyncService.enableSync(); |
| 126 mAndroidSyncSettings.enableChromeSync(account); | 125 mAndroidSyncSettings.enableChromeSync(); |
| 127 } | 126 } |
| 128 } | 127 } |
| 129 | 128 |
| 130 /** | 129 /** |
| 131 * Stops Sync if a user is currently signed in. | 130 * Stops Sync if a user is currently signed in. |
| 132 * | 131 * |
| 133 * Affects native sync, the invalidation controller, and the Android sync se
ttings. | 132 * Affects native sync, the invalidation controller, and the Android sync se
ttings. |
| 134 */ | 133 */ |
| 135 public void stop() { | 134 public void stop() { |
| 136 ThreadUtils.assertOnUiThread(); | 135 ThreadUtils.assertOnUiThread(); |
| 137 if (mChromeSigninController.isSignedIn()) { | 136 if (mChromeSigninController.isSignedIn()) { |
| 138 Log.d(TAG, "Disabling sync"); | 137 Log.d(TAG, "Disabling sync"); |
| 139 Account account = mChromeSigninController.getSignedInUser(); | |
| 140 InvalidationController.get(mContext).stop(); | 138 InvalidationController.get(mContext).stop(); |
| 141 mProfileSyncService.disableSync(); | 139 mProfileSyncService.disableSync(); |
| 142 if (mAndroidSyncSettings.isMasterSyncEnabled()) { | 140 if (mAndroidSyncSettings.isMasterSyncEnabled()) { |
| 143 // Only disable Android's Chrome sync setting if we weren't disa
bled | 141 // Only disable Android's Chrome sync setting if we weren't disa
bled |
| 144 // by the master sync setting. This way, when master sync is ena
bled | 142 // by the master sync setting. This way, when master sync is ena
bled |
| 145 // they will both be on and sync will start again. | 143 // they will both be on and sync will start again. |
| 146 mAndroidSyncSettings.disableChromeSync(account); | 144 mAndroidSyncSettings.disableChromeSync(); |
| 147 } | 145 } |
| 148 } | 146 } |
| 149 } | 147 } |
| 150 | 148 |
| 151 /** | 149 /** |
| 152 * From {@link ProfileSyncService.SyncStateChangedListener}. | 150 * From {@link ProfileSyncService.SyncStateChangedListener}. |
| 153 * | 151 * |
| 154 * Changes the invalidation controller and Android sync setting state to mat
ch | 152 * Changes the invalidation controller and Android sync setting state to mat
ch |
| 155 * the new native sync state. | 153 * the new native sync state. |
| 156 */ | 154 */ |
| 157 @Override | 155 @Override |
| 158 public void syncStateChanged() { | 156 public void syncStateChanged() { |
| 159 ThreadUtils.assertOnUiThread(); | 157 ThreadUtils.assertOnUiThread(); |
| 160 Account account = mChromeSigninController.getSignedInUser(); | |
| 161 // Don't do anything if there isn't an account. | |
| 162 if (account == null) return; | |
| 163 boolean isSyncActive = !mProfileSyncService.isStartSuppressed(); | 158 boolean isSyncActive = !mProfileSyncService.isStartSuppressed(); |
| 164 // Make the Java state match the native state. | 159 // Make the Java state match the native state. |
| 165 if (isSyncActive) { | 160 if (isSyncActive) { |
| 166 InvalidationController.get(mContext).start(); | 161 InvalidationController.get(mContext).start(); |
| 167 mAndroidSyncSettings.enableChromeSync(account); | 162 mAndroidSyncSettings.enableChromeSync(); |
| 168 } else { | 163 } else { |
| 169 InvalidationController.get(mContext).stop(); | 164 InvalidationController.get(mContext).stop(); |
| 170 if (mAndroidSyncSettings.isMasterSyncEnabled()) { | 165 if (mAndroidSyncSettings.isMasterSyncEnabled()) { |
| 171 // See comment in stop(). | 166 // See comment in stop(). |
| 172 mAndroidSyncSettings.disableChromeSync(account); | 167 mAndroidSyncSettings.disableChromeSync(); |
| 173 } | 168 } |
| 174 } | 169 } |
| 175 } | 170 } |
| 176 | 171 |
| 177 /** | 172 /** |
| 178 * From {@link AndroidSyncSettings.AndroidSyncSettingsObserver}. | 173 * From {@link AndroidSyncSettings.AndroidSyncSettingsObserver}. |
| 179 */ | 174 */ |
| 180 @Override | 175 @Override |
| 181 public void androidSyncSettingsChanged() { | 176 public void androidSyncSettingsChanged() { |
| 182 ThreadUtils.runOnUiThread(new Runnable() { | 177 ThreadUtils.runOnUiThread(new Runnable() { |
| 183 @Override | 178 @Override |
| 184 public void run() { | 179 public void run() { |
| 185 updateSyncStateFromAndroid(); | 180 updateSyncStateFromAndroid(); |
| 186 } | 181 } |
| 187 }); | 182 }); |
| 188 } | 183 } |
| 189 } | 184 } |
| OLD | NEW |