| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "chrome/browser/ui/browser.h" | 57 #include "chrome/browser/ui/browser.h" |
| 58 #include "chrome/browser/ui/browser_list.h" | 58 #include "chrome/browser/ui/browser_list.h" |
| 59 #include "chrome/browser/ui/browser_window.h" | 59 #include "chrome/browser/ui/browser_window.h" |
| 60 #include "chrome/browser/ui/global_error/global_error_service.h" | 60 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 61 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 61 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 62 #include "chrome/common/chrome_switches.h" | 62 #include "chrome/common/chrome_switches.h" |
| 63 #include "chrome/common/chrome_version_info.h" | 63 #include "chrome/common/chrome_version_info.h" |
| 64 #include "chrome/common/pref_names.h" | 64 #include "chrome/common/pref_names.h" |
| 65 #include "chrome/common/url_constants.h" | 65 #include "chrome/common/url_constants.h" |
| 66 #include "components/sync_driver/data_type_controller.h" | 66 #include "components/sync_driver/data_type_controller.h" |
| 67 #include "components/sync_driver/pref_names.h" |
| 67 #include "components/sync_driver/system_encryptor.h" | 68 #include "components/sync_driver/system_encryptor.h" |
| 68 #include "components/sync_driver/user_selectable_sync_type.h" | 69 #include "components/sync_driver/user_selectable_sync_type.h" |
| 69 #include "components/user_prefs/pref_registry_syncable.h" | 70 #include "components/user_prefs/pref_registry_syncable.h" |
| 70 #include "content/public/browser/notification_details.h" | 71 #include "content/public/browser/notification_details.h" |
| 71 #include "content/public/browser/notification_service.h" | 72 #include "content/public/browser/notification_service.h" |
| 72 #include "content/public/browser/notification_source.h" | 73 #include "content/public/browser/notification_source.h" |
| 73 #include "google_apis/gaia/gaia_constants.h" | 74 #include "google_apis/gaia/gaia_constants.h" |
| 74 #include "grit/generated_resources.h" | 75 #include "grit/generated_resources.h" |
| 75 #include "net/cookies/cookie_monster.h" | 76 #include "net/cookies/cookie_monster.h" |
| 76 #include "net/url_request/url_request_context_getter.h" | 77 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has | 304 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has |
| 304 // completed, it means sync was not properly configured, so we manually | 305 // completed, it means sync was not properly configured, so we manually |
| 305 // set kSyncKeepEverythingSynced. | 306 // set kSyncKeepEverythingSynced. |
| 306 PrefService* const pref_service = profile_->GetPrefs(); | 307 PrefService* const pref_service = profile_->GetPrefs(); |
| 307 if (!pref_service) | 308 if (!pref_service) |
| 308 return; | 309 return; |
| 309 if (GetPreferredDataTypes().Size() > 1) | 310 if (GetPreferredDataTypes().Size() > 1) |
| 310 return; | 311 return; |
| 311 | 312 |
| 312 const PrefService::Preference* keep_everything_synced = | 313 const PrefService::Preference* keep_everything_synced = |
| 313 pref_service->FindPreference(prefs::kSyncKeepEverythingSynced); | 314 pref_service->FindPreference( |
| 315 sync_driver::prefs::kSyncKeepEverythingSynced); |
| 314 // This will be false if the preference was properly set or if it's controlled | 316 // This will be false if the preference was properly set or if it's controlled |
| 315 // by policy. | 317 // by policy. |
| 316 if (!keep_everything_synced->IsDefaultValue()) | 318 if (!keep_everything_synced->IsDefaultValue()) |
| 317 return; | 319 return; |
| 318 | 320 |
| 319 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred | 321 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred |
| 320 // types now, before we configure. | 322 // types now, before we configure. |
| 321 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); | 323 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); |
| 322 sync_prefs_.SetKeepEverythingSynced(true); | 324 sync_prefs_.SetKeepEverythingSynced(true); |
| 323 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 325 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 if (experiments.gcm_channel_state == syncer::Experiments::SUPPRESSED) | 1005 if (experiments.gcm_channel_state == syncer::Experiments::SUPPRESSED) |
| 1004 gcm_profile_service->Stop(); | 1006 gcm_profile_service->Stop(); |
| 1005 else | 1007 else |
| 1006 gcm_profile_service->Start(); | 1008 gcm_profile_service->Start(); |
| 1007 } | 1009 } |
| 1008 } else { | 1010 } else { |
| 1009 profile()->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); | 1011 profile()->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); |
| 1010 } | 1012 } |
| 1011 | 1013 |
| 1012 int bookmarks_experiment_state_before = profile_->GetPrefs()->GetInteger( | 1014 int bookmarks_experiment_state_before = profile_->GetPrefs()->GetInteger( |
| 1013 prefs::kEnhancedBookmarksExperimentEnabled); | 1015 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled); |
| 1014 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". | 1016 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". |
| 1015 // "" and "1" means experiment is enabled. | 1017 // "" and "1" means experiment is enabled. |
| 1016 if ((CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 1018 if ((CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 1017 switches::kEnhancedBookmarksExperiment) != "0")) { | 1019 switches::kEnhancedBookmarksExperiment) != "0")) { |
| 1018 profile_->GetPrefs()->SetInteger(prefs::kEnhancedBookmarksExperimentEnabled, | 1020 profile_->GetPrefs()->SetInteger( |
| 1019 experiments.enhanced_bookmarks_enabled ? | 1021 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled, |
| 1020 kBookmarksExperimentEnabled : | 1022 experiments.enhanced_bookmarks_enabled ? kBookmarksExperimentEnabled |
| 1021 kNoBookmarksExperiment); | 1023 : kNoBookmarksExperiment); |
| 1022 profile_->GetPrefs()->SetString(prefs::kEnhancedBookmarksExtensionId, | 1024 profile_->GetPrefs()->SetString( |
| 1023 experiments.enhanced_bookmarks_ext_id); | 1025 sync_driver::prefs::kEnhancedBookmarksExtensionId, |
| 1026 experiments.enhanced_bookmarks_ext_id); |
| 1024 } else { | 1027 } else { |
| 1025 // User opt-out from chrome://flags | 1028 // User opt-out from chrome://flags |
| 1026 if (experiments.enhanced_bookmarks_enabled) { | 1029 if (experiments.enhanced_bookmarks_enabled) { |
| 1027 profile_->GetPrefs()->SetInteger( | 1030 profile_->GetPrefs()->SetInteger( |
| 1028 prefs::kEnhancedBookmarksExperimentEnabled, | 1031 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled, |
| 1029 kBookmarksExperimentEnabledUserOptOut); | 1032 kBookmarksExperimentEnabledUserOptOut); |
| 1030 // Keep extension id up-to-date in case will opt-in later. | 1033 // Keep extension id up-to-date in case will opt-in later. |
| 1031 profile_->GetPrefs()->SetString(prefs::kEnhancedBookmarksExtensionId, | 1034 profile_->GetPrefs()->SetString( |
| 1032 experiments.enhanced_bookmarks_ext_id); | 1035 sync_driver::prefs::kEnhancedBookmarksExtensionId, |
| 1036 experiments.enhanced_bookmarks_ext_id); |
| 1033 } else { | 1037 } else { |
| 1034 profile_->GetPrefs()->ClearPref( | 1038 profile_->GetPrefs()->ClearPref( |
| 1035 prefs::kEnhancedBookmarksExperimentEnabled); | 1039 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled); |
| 1036 profile_->GetPrefs()->ClearPref(prefs::kEnhancedBookmarksExtensionId); | 1040 profile_->GetPrefs()->ClearPref( |
| 1041 sync_driver::prefs::kEnhancedBookmarksExtensionId); |
| 1037 } | 1042 } |
| 1038 } | 1043 } |
| 1039 BookmarksExperimentState bookmarks_experiment_state = | 1044 BookmarksExperimentState bookmarks_experiment_state = |
| 1040 static_cast<BookmarksExperimentState>(profile_->GetPrefs()->GetInteger( | 1045 static_cast<BookmarksExperimentState>(profile_->GetPrefs()->GetInteger( |
| 1041 prefs::kEnhancedBookmarksExperimentEnabled)); | 1046 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled)); |
| 1042 // If bookmark experiment state was changed update about flags experiment. | 1047 // If bookmark experiment state was changed update about flags experiment. |
| 1043 if (bookmarks_experiment_state_before != bookmarks_experiment_state) { | 1048 if (bookmarks_experiment_state_before != bookmarks_experiment_state) { |
| 1044 UpdateBookmarksExperiment(g_browser_process->local_state(), | 1049 UpdateBookmarksExperiment(g_browser_process->local_state(), |
| 1045 bookmarks_experiment_state); | 1050 bookmarks_experiment_state); |
| 1046 } | 1051 } |
| 1047 | 1052 |
| 1048 // If this is a first time sync for a client, this will be called before | 1053 // If this is a first time sync for a client, this will be called before |
| 1049 // OnBackendInitialized() to ensure the new datatypes are available at sync | 1054 // OnBackendInitialized() to ensure the new datatypes are available at sync |
| 1050 // setup. As a result, the migrator won't exist yet. This is fine because for | 1055 // setup. As a result, the migrator won't exist yet. This is fine because for |
| 1051 // first time sync cases we're only concerned with making the datatype | 1056 // first time sync cases we're only concerned with making the datatype |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 } | 2124 } |
| 2120 | 2125 |
| 2121 void ProfileSyncService::UnsuppressAndStart() { | 2126 void ProfileSyncService::UnsuppressAndStart() { |
| 2122 DCHECK(profile_); | 2127 DCHECK(profile_); |
| 2123 sync_prefs_.SetStartSuppressed(false); | 2128 sync_prefs_.SetStartSuppressed(false); |
| 2124 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 2129 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
| 2125 // is never called for some clients. | 2130 // is never called for some clients. |
| 2126 if (signin_.get() && | 2131 if (signin_.get() && |
| 2127 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) { | 2132 signin_->GetOriginal()->GetAuthenticatedUsername().empty()) { |
| 2128 signin_->GetOriginal()->SetAuthenticatedUsername( | 2133 signin_->GetOriginal()->SetAuthenticatedUsername( |
| 2129 sync_prefs_.GetGoogleServicesUsername()); | 2134 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
| 2130 } | 2135 } |
| 2131 startup_controller_.TryStart(); | 2136 startup_controller_.TryStart(); |
| 2132 } | 2137 } |
| 2133 | 2138 |
| 2134 void ProfileSyncService::AcknowledgeSyncedTypes() { | 2139 void ProfileSyncService::AcknowledgeSyncedTypes() { |
| 2135 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); | 2140 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); |
| 2136 } | 2141 } |
| 2137 | 2142 |
| 2138 void ProfileSyncService::ReconfigureDatatypeManager() { | 2143 void ProfileSyncService::ReconfigureDatatypeManager() { |
| 2139 // If we haven't initialized yet, don't configure the DTM as it could cause | 2144 // If we haven't initialized yet, don't configure the DTM as it could cause |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2199 status.last_get_token_error = last_get_token_error_; | 2204 status.last_get_token_error = last_get_token_error_; |
| 2200 if (request_access_token_retry_timer_.IsRunning()) | 2205 if (request_access_token_retry_timer_.IsRunning()) |
| 2201 status.next_token_request_time = next_token_request_time_; | 2206 status.next_token_request_time = next_token_request_time_; |
| 2202 return status; | 2207 return status; |
| 2203 } | 2208 } |
| 2204 | 2209 |
| 2205 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2210 void ProfileSyncService::OverrideNetworkResourcesForTest( |
| 2206 scoped_ptr<syncer::NetworkResources> network_resources) { | 2211 scoped_ptr<syncer::NetworkResources> network_resources) { |
| 2207 network_resources_ = network_resources.Pass(); | 2212 network_resources_ = network_resources.Pass(); |
| 2208 } | 2213 } |
| OLD | NEW |