| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/string16.h" | 21 #include "base/string16.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/browser/about_flags.h" | 25 #include "chrome/browser/about_flags.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/defaults.h" | 27 #include "chrome/browser/defaults.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
| 30 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 30 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 31 #include "chrome/browser/prefs/pref_service.h" | |
| 32 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/signin/signin_manager.h" | 32 #include "chrome/browser/signin/signin_manager.h" |
| 34 #include "chrome/browser/signin/signin_manager_factory.h" | 33 #include "chrome/browser/signin/signin_manager_factory.h" |
| 35 #include "chrome/browser/signin/token_service.h" | 34 #include "chrome/browser/signin/token_service.h" |
| 36 #include "chrome/browser/signin/token_service_factory.h" | 35 #include "chrome/browser/signin/token_service_factory.h" |
| 37 #include "chrome/browser/sync/backend_migrator.h" | 36 #include "chrome/browser/sync/backend_migrator.h" |
| 38 #include "chrome/browser/sync/glue/change_processor.h" | 37 #include "chrome/browser/sync/glue/change_processor.h" |
| 39 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 38 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 40 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 39 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
| 41 #include "chrome/browser/sync/glue/data_type_controller.h" | 40 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 42 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 41 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 43 #include "chrome/browser/sync/glue/session_model_associator.h" | 42 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 44 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 43 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| 45 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 44 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 46 #include "chrome/browser/sync/sync_global_error.h" | 45 #include "chrome/browser/sync/sync_global_error.h" |
| 47 #include "chrome/browser/sync/user_selectable_sync_type.h" | 46 #include "chrome/browser/sync/user_selectable_sync_type.h" |
| 48 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
| 49 #include "chrome/browser/ui/browser_list.h" | 48 #include "chrome/browser/ui/browser_list.h" |
| 50 #include "chrome/browser/ui/browser_window.h" | 49 #include "chrome/browser/ui/browser_window.h" |
| 51 #include "chrome/browser/ui/global_error/global_error_service.h" | 50 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 52 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 51 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 53 #include "chrome/common/chrome_notification_types.h" | 52 #include "chrome/common/chrome_notification_types.h" |
| 54 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
| 55 #include "chrome/common/chrome_version_info.h" | 54 #include "chrome/common/chrome_version_info.h" |
| 56 #include "chrome/common/pref_names.h" | |
| 57 #include "chrome/common/time_format.h" | 55 #include "chrome/common/time_format.h" |
| 58 #include "chrome/common/url_constants.h" | 56 #include "chrome/common/url_constants.h" |
| 59 #include "content/public/browser/notification_details.h" | 57 #include "content/public/browser/notification_details.h" |
| 60 #include "content/public/browser/notification_service.h" | 58 #include "content/public/browser/notification_service.h" |
| 61 #include "content/public/browser/notification_source.h" | 59 #include "content/public/browser/notification_source.h" |
| 62 #include "google_apis/gaia/gaia_constants.h" | 60 #include "google_apis/gaia/gaia_constants.h" |
| 63 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
| 64 #include "net/cookies/cookie_monster.h" | 62 #include "net/cookies/cookie_monster.h" |
| 65 #include "sync/api/sync_error.h" | 63 #include "sync/api/sync_error.h" |
| 66 #include "sync/internal_api/public/configure_reason.h" | 64 #include "sync/internal_api/public/configure_reason.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return; | 209 return; |
| 212 } | 210 } |
| 213 | 211 |
| 214 RegisterAuthNotifications(); | 212 RegisterAuthNotifications(); |
| 215 | 213 |
| 216 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { | 214 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { |
| 217 // Clean up in case of previous crash / setup abort / signout. | 215 // Clean up in case of previous crash / setup abort / signout. |
| 218 DisableForUser(); | 216 DisableForUser(); |
| 219 } | 217 } |
| 220 | 218 |
| 221 TrySyncDatatypePrefRecovery(); | |
| 222 | |
| 223 TryStart(); | 219 TryStart(); |
| 224 } | 220 } |
| 225 | 221 |
| 226 void ProfileSyncService::TrySyncDatatypePrefRecovery() { | |
| 227 DCHECK(!sync_initialized()); | |
| 228 if (!HasSyncSetupCompleted()) | |
| 229 return; | |
| 230 | |
| 231 // There was a bug where OnUserChoseDatatypes was not properly called on | |
| 232 // configuration (see crbug.com/154940). We detect this by checking whether | |
| 233 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has | |
| 234 // completed, it means sync was not properly configured, so we manually | |
| 235 // set kSyncKeepEverythingSynced. | |
| 236 PrefService* const pref_service = profile_->GetPrefs(); | |
| 237 if (!pref_service) | |
| 238 return; | |
| 239 if (sync_prefs_.HasKeepEverythingSynced()) | |
| 240 return; | |
| 241 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | |
| 242 if (sync_prefs_.GetPreferredDataTypes(registered_types).Size() > 1) | |
| 243 return; | |
| 244 | |
| 245 const PrefService::Preference* keep_everything_synced = | |
| 246 pref_service->FindPreference(prefs::kSyncKeepEverythingSynced); | |
| 247 // This will be false if the preference was properly set or if it's controlled | |
| 248 // by policy. | |
| 249 if (!keep_everything_synced->IsDefaultValue()) | |
| 250 return; | |
| 251 | |
| 252 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred | |
| 253 // types now, before we configure. | |
| 254 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); | |
| 255 sync_prefs_.SetKeepEverythingSynced(true); | |
| 256 sync_prefs_.SetPreferredDataTypes(registered_types, | |
| 257 registered_types); | |
| 258 } | |
| 259 | |
| 260 void ProfileSyncService::TryStart() { | 222 void ProfileSyncService::TryStart() { |
| 261 if (!IsSyncEnabledAndLoggedIn()) | 223 if (!IsSyncEnabledAndLoggedIn()) |
| 262 return; | 224 return; |
| 263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 225 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 264 if (!token_service) | 226 if (!token_service) |
| 265 return; | 227 return; |
| 266 // Don't start the backend if the token service hasn't finished loading tokens | 228 // Don't start the backend if the token service hasn't finished loading tokens |
| 267 // yet (if the backend is started before the sync token has been loaded, | 229 // yet (if the backend is started before the sync token has been loaded, |
| 268 // GetCredentials() will return bogus credentials). On auto_start platforms | 230 // GetCredentials() will return bogus credentials). On auto_start platforms |
| 269 // (like ChromeOS) we don't start sync until tokens are loaded, because the | 231 // (like ChromeOS) we don't start sync until tokens are loaded, because the |
| (...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1865 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
| 1904 ProfileSyncService* old_this = this; | 1866 ProfileSyncService* old_this = this; |
| 1905 this->~ProfileSyncService(); | 1867 this->~ProfileSyncService(); |
| 1906 new(old_this) ProfileSyncService( | 1868 new(old_this) ProfileSyncService( |
| 1907 new ProfileSyncComponentsFactoryImpl(profile, | 1869 new ProfileSyncComponentsFactoryImpl(profile, |
| 1908 CommandLine::ForCurrentProcess()), | 1870 CommandLine::ForCurrentProcess()), |
| 1909 profile, | 1871 profile, |
| 1910 signin, | 1872 signin, |
| 1911 behavior); | 1873 behavior); |
| 1912 } | 1874 } |
| OLD | NEW |