| Index: chrome/browser/sync/profile_sync_service.cc
|
| diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
|
| index d3db701464897347bb0d7f5cf433c5f91f264630..413a28f7a168f452435405eb5f12d8022bbab174 100644
|
| --- a/chrome/browser/sync/profile_sync_service.cc
|
| +++ b/chrome/browser/sync/profile_sync_service.cc
|
| @@ -125,6 +125,16 @@ void ProfileSyncService::Initialize() {
|
| InitSettings();
|
| RegisterPreferences();
|
|
|
| + // Watch the preference that indicates sync is managed so we can take
|
| + // appropriate action.
|
| + pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this);
|
| +
|
| + // For now, the only thing we can do through policy is to turn sync off.
|
| + if (IsManaged()) {
|
| + DisableForUser();
|
| + return;
|
| + }
|
| +
|
| if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) {
|
| DisableForUser(); // Clean up in case of previous crash / setup abort.
|
|
|
| @@ -216,6 +226,8 @@ void ProfileSyncService::RegisterPreferences() {
|
|
|
| pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced,
|
| enable_by_default);
|
| +
|
| + pref_service->RegisterBooleanPref(prefs::kSyncManaged, false);
|
| }
|
|
|
| void ProfileSyncService::ClearPreferences() {
|
| @@ -752,6 +764,17 @@ void ProfileSyncService::Observe(NotificationType type,
|
| FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
|
| break;
|
| }
|
| + case NotificationType::PREF_CHANGED: {
|
| + std::wstring* pref_name = Details<std::wstring>(details).ptr();
|
| + if (*pref_name == prefs::kSyncManaged) {
|
| + FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
|
| + if (*pref_sync_managed_)
|
| + DisableForUser();
|
| + else if (HasSyncSetupCompleted())
|
| + StartUp();
|
| + }
|
| + break;
|
| + }
|
| default: {
|
| NOTREACHED();
|
| }
|
| @@ -770,12 +793,18 @@ void ProfileSyncService::SyncEvent(SyncEventCodes code) {
|
| UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE);
|
| }
|
|
|
| +// static
|
| bool ProfileSyncService::IsSyncEnabled() {
|
| // We have switches::kEnableSync just in case we need to change back to
|
| // sync-disabled-by-default on a platform.
|
| return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync);
|
| }
|
|
|
| +bool ProfileSyncService::IsManaged() {
|
| + // Some tests use ProfileSyncServiceMock which doesn't have a profile.
|
| + return profile_ && profile_->GetPrefs()->GetBoolean(prefs::kSyncManaged);
|
| +}
|
| +
|
| bool ProfileSyncService::ShouldPushChanges() {
|
| // True only after all bootstrapping has succeeded: the sync backend
|
| // is initialized, all enabled data types are consistent with one
|
|
|