Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: chrome/browser/sync/profile_sync_service.cc

Issue 2905003: Implement support for disabling sync through configuration management. (Closed)
Patch Set: Fix PrefsControllerTest on MAC. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698