| 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.components.sync; | 5 package org.chromium.components.sync; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.content.ContentResolver; | 8 import android.content.ContentResolver; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.SyncStatusObserver; | 10 import android.content.SyncStatusObserver; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 /** | 86 /** |
| 87 * @param context the context the ApplicationContext will be retrieved from. | 87 * @param context the context the ApplicationContext will be retrieved from. |
| 88 * @param syncContentResolverDelegate an implementation of {@link SyncConten
tResolverDelegate}. | 88 * @param syncContentResolverDelegate an implementation of {@link SyncConten
tResolverDelegate}. |
| 89 */ | 89 */ |
| 90 private AndroidSyncSettings( | 90 private AndroidSyncSettings( |
| 91 Context context, SyncContentResolverDelegate syncContentResolverDele
gate) { | 91 Context context, SyncContentResolverDelegate syncContentResolverDele
gate) { |
| 92 mApplicationContext = context.getApplicationContext(); | 92 mApplicationContext = context.getApplicationContext(); |
| 93 mSyncContentResolverDelegate = syncContentResolverDelegate; | 93 mSyncContentResolverDelegate = syncContentResolverDelegate; |
| 94 mContractAuthority = getContractAuthority(); | 94 mContractAuthority = getContractAuthority(); |
| 95 | 95 |
| 96 mAccount = ChromeSigninController.get().getSignedInUser(); | 96 mAccount = ChromeSigninController.get(context).getSignedInUser(); |
| 97 updateSyncability(); | 97 updateSyncability(); |
| 98 updateCachedSettings(); | 98 updateCachedSettings(); |
| 99 | 99 |
| 100 mSyncContentResolverDelegate.addStatusChangeListener( | 100 mSyncContentResolverDelegate.addStatusChangeListener( |
| 101 ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, | 101 ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, |
| 102 new AndroidSyncSettingsChangedObserver()); | 102 new AndroidSyncSettingsChangedObserver()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Checks whether sync is currently enabled from Chrome for the currently si
gned in account. | 106 * Checks whether sync is currently enabled from Chrome for the currently si
gned in account. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // Make account syncable if there is one. | 224 // Make account syncable if there is one. |
| 225 if (shouldBeSyncable) { | 225 if (shouldBeSyncable) { |
| 226 mSyncContentResolverDelegate.setIsSyncable(mAccount, mContractAuthor
ity, 1); | 226 mSyncContentResolverDelegate.setIsSyncable(mAccount, mContractAuthor
ity, 1); |
| 227 // This reduces unnecessary resource usage. See http://crbug.com/480
688 for details. | 227 // This reduces unnecessary resource usage. See http://crbug.com/480
688 for details. |
| 228 mSyncContentResolverDelegate.removePeriodicSync( | 228 mSyncContentResolverDelegate.removePeriodicSync( |
| 229 mAccount, mContractAuthority, Bundle.EMPTY); | 229 mAccount, mContractAuthority, Bundle.EMPTY); |
| 230 } | 230 } |
| 231 StrictMode.setThreadPolicy(oldPolicy); | 231 StrictMode.setThreadPolicy(oldPolicy); |
| 232 | 232 |
| 233 // Disable the syncability of Chrome for all other accounts. | 233 // Disable the syncability of Chrome for all other accounts. |
| 234 AccountManagerHelper.get().getGoogleAccounts(new Callback<Account[]>() { | 234 AccountManagerHelper.get(mApplicationContext).getGoogleAccounts(new Call
back<Account[]>() { |
| 235 @Override | 235 @Override |
| 236 public void onResult(Account[] accounts) { | 236 public void onResult(Account[] accounts) { |
| 237 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWr
ites(); | 237 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWr
ites(); |
| 238 for (Account account : accounts) { | 238 for (Account account : accounts) { |
| 239 if (!account.equals(mAccount) | 239 if (!account.equals(mAccount) |
| 240 && mSyncContentResolverDelegate.getIsSyncable( | 240 && mSyncContentResolverDelegate.getIsSyncable( |
| 241 account, mContractAuthority) | 241 account, mContractAuthority) |
| 242 > 0) { | 242 > 0) { |
| 243 mSyncContentResolverDelegate.setIsSyncable(account, mCon
tractAuthority, 0); | 243 mSyncContentResolverDelegate.setIsSyncable(account, mCon
tractAuthority, 0); |
| 244 } | 244 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 private void notifyObservers() { | 298 private void notifyObservers() { |
| 299 for (AndroidSyncSettingsObserver observer : mObservers) { | 299 for (AndroidSyncSettingsObserver observer : mObservers) { |
| 300 observer.androidSyncSettingsChanged(); | 300 observer.androidSyncSettingsChanged(); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 private String getContractAuthority() { | 304 private String getContractAuthority() { |
| 305 return mApplicationContext.getPackageName(); | 305 return mApplicationContext.getPackageName(); |
| 306 } | 306 } |
| 307 } | 307 } |
| OLD | NEW |