| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 ProfileSyncService::~ProfileSyncService() { | 119 ProfileSyncService::~ProfileSyncService() { |
| 120 Shutdown(false); | 120 Shutdown(false); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ProfileSyncService::Initialize() { | 123 void ProfileSyncService::Initialize() { |
| 124 LOG(INFO) << "Starting ProfileSyncService."; | 124 LOG(INFO) << "Starting ProfileSyncService."; |
| 125 InitSettings(); | 125 InitSettings(); |
| 126 RegisterPreferences(); | 126 RegisterPreferences(); |
| 127 | 127 |
| 128 // Watch the preference that indicates sync is managed so we can take |
| 129 // appropriate action. |
| 130 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this); |
| 131 |
| 132 // For now, the only thing we can do through policy is to turn sync off. |
| 133 if (IsManaged()) { |
| 134 DisableForUser(); |
| 135 return; |
| 136 } |
| 137 |
| 128 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { | 138 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { |
| 129 DisableForUser(); // Clean up in case of previous crash / setup abort. | 139 DisableForUser(); // Clean up in case of previous crash / setup abort. |
| 130 | 140 |
| 131 // Automatically start sync in Chromium OS. | 141 // Automatically start sync in Chromium OS. |
| 132 if (bootstrap_sync_authentication_) { | 142 if (bootstrap_sync_authentication_) { |
| 133 // If the LSID is empty, we're in a CrOS UI test that is not testing sync | 143 // If the LSID is empty, we're in a CrOS UI test that is not testing sync |
| 134 // behavior, so we don't want the sync service to start. | 144 // behavior, so we don't want the sync service to start. |
| 135 if (GetLsidForAuthBootstraping().empty()) { | 145 if (GetLsidForAuthBootstraping().empty()) { |
| 136 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present."; | 146 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present."; |
| 137 return; | 147 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks, true); | 219 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks, true); |
| 210 pref_service->RegisterBooleanPref(prefs::kSyncPasswords, enable_by_default); | 220 pref_service->RegisterBooleanPref(prefs::kSyncPasswords, enable_by_default); |
| 211 pref_service->RegisterBooleanPref(prefs::kSyncPreferences, enable_by_default); | 221 pref_service->RegisterBooleanPref(prefs::kSyncPreferences, enable_by_default); |
| 212 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); | 222 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); |
| 213 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); | 223 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); |
| 214 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); | 224 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); |
| 215 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); | 225 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); |
| 216 | 226 |
| 217 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, | 227 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, |
| 218 enable_by_default); | 228 enable_by_default); |
| 229 |
| 230 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); |
| 219 } | 231 } |
| 220 | 232 |
| 221 void ProfileSyncService::ClearPreferences() { | 233 void ProfileSyncService::ClearPreferences() { |
| 222 PrefService* pref_service = profile_->GetPrefs(); | 234 PrefService* pref_service = profile_->GetPrefs(); |
| 223 pref_service->ClearPref(prefs::kSyncLastSyncedTime); | 235 pref_service->ClearPref(prefs::kSyncLastSyncedTime); |
| 224 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 236 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 225 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 237 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 226 // Is that really what we want? | 238 // Is that really what we want? |
| 227 pref_service->ScheduleSavePersistentPrefs(); | 239 pref_service->ScheduleSavePersistentPrefs(); |
| 228 } | 240 } |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { | 757 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { |
| 746 // Make sure the data types that depend on the passphrase are started at | 758 // Make sure the data types that depend on the passphrase are started at |
| 747 // this time. | 759 // this time. |
| 748 syncable::ModelTypeSet types; | 760 syncable::ModelTypeSet types; |
| 749 GetPreferredDataTypes(&types); | 761 GetPreferredDataTypes(&types); |
| 750 data_type_manager_->Configure(types); | 762 data_type_manager_->Configure(types); |
| 751 | 763 |
| 752 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 764 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 753 break; | 765 break; |
| 754 } | 766 } |
| 767 case NotificationType::PREF_CHANGED: { |
| 768 std::wstring* pref_name = Details<std::wstring>(details).ptr(); |
| 769 if (*pref_name == prefs::kSyncManaged) { |
| 770 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| 771 if (*pref_sync_managed_) |
| 772 DisableForUser(); |
| 773 else if (HasSyncSetupCompleted()) |
| 774 StartUp(); |
| 775 } |
| 776 break; |
| 777 } |
| 755 default: { | 778 default: { |
| 756 NOTREACHED(); | 779 NOTREACHED(); |
| 757 } | 780 } |
| 758 } | 781 } |
| 759 } | 782 } |
| 760 | 783 |
| 761 void ProfileSyncService::AddObserver(Observer* observer) { | 784 void ProfileSyncService::AddObserver(Observer* observer) { |
| 762 observers_.AddObserver(observer); | 785 observers_.AddObserver(observer); |
| 763 } | 786 } |
| 764 | 787 |
| 765 void ProfileSyncService::RemoveObserver(Observer* observer) { | 788 void ProfileSyncService::RemoveObserver(Observer* observer) { |
| 766 observers_.RemoveObserver(observer); | 789 observers_.RemoveObserver(observer); |
| 767 } | 790 } |
| 768 | 791 |
| 769 void ProfileSyncService::SyncEvent(SyncEventCodes code) { | 792 void ProfileSyncService::SyncEvent(SyncEventCodes code) { |
| 770 UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE); | 793 UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE); |
| 771 } | 794 } |
| 772 | 795 |
| 796 // static |
| 773 bool ProfileSyncService::IsSyncEnabled() { | 797 bool ProfileSyncService::IsSyncEnabled() { |
| 774 // We have switches::kEnableSync just in case we need to change back to | 798 // We have switches::kEnableSync just in case we need to change back to |
| 775 // sync-disabled-by-default on a platform. | 799 // sync-disabled-by-default on a platform. |
| 776 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync); | 800 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync); |
| 777 } | 801 } |
| 778 | 802 |
| 803 bool ProfileSyncService::IsManaged() { |
| 804 // Some tests use ProfileSyncServiceMock which doesn't have a profile. |
| 805 return profile_ && profile_->GetPrefs()->GetBoolean(prefs::kSyncManaged); |
| 806 } |
| 807 |
| 779 bool ProfileSyncService::ShouldPushChanges() { | 808 bool ProfileSyncService::ShouldPushChanges() { |
| 780 // True only after all bootstrapping has succeeded: the sync backend | 809 // True only after all bootstrapping has succeeded: the sync backend |
| 781 // is initialized, all enabled data types are consistent with one | 810 // is initialized, all enabled data types are consistent with one |
| 782 // another, and no unrecoverable error has transpired. | 811 // another, and no unrecoverable error has transpired. |
| 783 if (unrecoverable_error_detected_) | 812 if (unrecoverable_error_detected_) |
| 784 return false; | 813 return false; |
| 785 | 814 |
| 786 if (!data_type_manager_.get()) | 815 if (!data_type_manager_.get()) |
| 787 return false; | 816 return false; |
| 788 | 817 |
| 789 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 818 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 790 } | 819 } |
| OLD | NEW |