| 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.annotation.SuppressLint; | 8 import android.annotation.SuppressLint; |
| 9 import android.content.ContentResolver; | 9 import android.content.ContentResolver; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * @param context the context the ApplicationContext will be retrieved from. | 90 * @param context the context the ApplicationContext will be retrieved from. |
| 91 * @param syncContentResolverDelegate an implementation of {@link SyncConten
tResolverDelegate}. | 91 * @param syncContentResolverDelegate an implementation of {@link SyncConten
tResolverDelegate}. |
| 92 */ | 92 */ |
| 93 private AndroidSyncSettings( | 93 private AndroidSyncSettings( |
| 94 Context context, SyncContentResolverDelegate syncContentResolverDele
gate) { | 94 Context context, SyncContentResolverDelegate syncContentResolverDele
gate) { |
| 95 mApplicationContext = context.getApplicationContext(); | 95 mApplicationContext = context.getApplicationContext(); |
| 96 mContractAuthority = mApplicationContext.getPackageName(); |
| 96 mSyncContentResolverDelegate = syncContentResolverDelegate; | 97 mSyncContentResolverDelegate = syncContentResolverDelegate; |
| 97 mContractAuthority = getContractAuthority(); | |
| 98 | 98 |
| 99 mAccount = ChromeSigninController.get().getSignedInUser(); | 99 mAccount = ChromeSigninController.get().getSignedInUser(); |
| 100 updateSyncability(null); | 100 updateSyncability(null); |
| 101 updateCachedSettings(); | 101 updateCachedSettings(); |
| 102 | 102 |
| 103 mSyncContentResolverDelegate.addStatusChangeListener( | 103 mSyncContentResolverDelegate.addStatusChangeListener( |
| 104 ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, | 104 ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, |
| 105 new AndroidSyncSettingsChangedObserver()); | 105 new AndroidSyncSettingsChangedObserver()); |
| 106 } | 106 } |
| 107 | 107 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (sInstance.updateCachedSettings()) { | 179 if (sInstance.updateCachedSettings()) { |
| 180 sInstance.notifyObservers(); | 180 sInstance.notifyObservers(); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * Returns the contract authority to use when requesting sync. | 185 * Returns the contract authority to use when requesting sync. |
| 186 */ | 186 */ |
| 187 public static String getContractAuthority(Context context) { | 187 public static String getContractAuthority(Context context) { |
| 188 ensureInitialized(context); | 188 ensureInitialized(context); |
| 189 return sInstance.getContractAuthority(); | 189 return sInstance.mContractAuthority; |
| 190 } | 190 } |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Add a new AndroidSyncSettingsObserver. | 193 * Add a new AndroidSyncSettingsObserver. |
| 194 */ | 194 */ |
| 195 public static void registerObserver(Context context, AndroidSyncSettingsObse
rver observer) { | 195 public static void registerObserver(Context context, AndroidSyncSettingsObse
rver observer) { |
| 196 ensureInitialized(context); | 196 ensureInitialized(context); |
| 197 synchronized (sInstance.mLock) { | 197 synchronized (sInstance.mLock) { |
| 198 sInstance.mObservers.addObserver(observer); | 198 sInstance.mObservers.addObserver(observer); |
| 199 } | 199 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 return oldChromeSyncEnabled != mChromeSyncEnabled | 315 return oldChromeSyncEnabled != mChromeSyncEnabled |
| 316 || oldMasterSyncEnabled != mMasterSyncEnabled; | 316 || oldMasterSyncEnabled != mMasterSyncEnabled; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 private void notifyObservers() { | 320 private void notifyObservers() { |
| 321 for (AndroidSyncSettingsObserver observer : mObservers) { | 321 for (AndroidSyncSettingsObserver observer : mObservers) { |
| 322 observer.androidSyncSettingsChanged(); | 322 observer.androidSyncSettingsChanged(); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | |
| 326 private String getContractAuthority() { | |
| 327 return mApplicationContext.getPackageName(); | |
| 328 } | |
| 329 } | 325 } |
| OLD | NEW |