Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 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 #if defined(OS_WIN) | |
| 25 #include "base/win/windows_version.h" | |
| 26 #endif | |
| 24 #include "chrome/browser/about_flags.h" | 27 #include "chrome/browser/about_flags.h" |
| 25 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/defaults.h" | 29 #include "chrome/browser/defaults.h" |
| 27 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 30 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/signin/signin_manager.h" | 32 #include "chrome/browser/signin/signin_manager.h" |
| 30 #include "chrome/browser/signin/signin_manager_factory.h" | 33 #include "chrome/browser/signin/signin_manager_factory.h" |
| 31 #include "chrome/browser/signin/token_service.h" | 34 #include "chrome/browser/signin/token_service.h" |
| 32 #include "chrome/browser/signin/token_service_factory.h" | 35 #include "chrome/browser/signin/token_service_factory.h" |
| 33 #include "chrome/browser/sync/backend_migrator.h" | 36 #include "chrome/browser/sync/backend_migrator.h" |
| 37 #include "chrome/browser/sync/credential_cache_service_win.h" | |
| 38 #include "chrome/browser/sync/credential_cache_service_factory_win.h" | |
| 34 #include "chrome/browser/sync/glue/change_processor.h" | 39 #include "chrome/browser/sync/glue/change_processor.h" |
| 35 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 40 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 36 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" | 41 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
| 37 #include "chrome/browser/sync/glue/data_type_controller.h" | 42 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 38 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 43 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 39 #include "chrome/browser/sync/glue/session_model_associator.h" | 44 #include "chrome/browser/sync/glue/session_model_associator.h" |
| 40 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 45 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| 41 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" | 46 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 42 #include "chrome/browser/sync/sync_global_error.h" | 47 #include "chrome/browser/sync/sync_global_error.h" |
| 43 #include "chrome/browser/sync/user_selectable_sync_type.h" | 48 #include "chrome/browser/sync/user_selectable_sync_type.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 signin_(signin_manager), | 137 signin_(signin_manager), |
| 133 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 138 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
| 134 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 139 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 135 expect_sync_configuration_aborted_(false), | 140 expect_sync_configuration_aborted_(false), |
| 136 encrypted_types_(syncer::Cryptographer::SensitiveTypes()), | 141 encrypted_types_(syncer::Cryptographer::SensitiveTypes()), |
| 137 encrypt_everything_(false), | 142 encrypt_everything_(false), |
| 138 encryption_pending_(false), | 143 encryption_pending_(false), |
| 139 auto_start_enabled_(start_behavior == AUTO_START), | 144 auto_start_enabled_(start_behavior == AUTO_START), |
| 140 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 145 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 141 configure_status_(DataTypeManager::UNKNOWN), | 146 configure_status_(DataTypeManager::UNKNOWN), |
| 142 setup_in_progress_(false) { | 147 setup_in_progress_(false), |
| 148 credential_cache_service_(NULL) { | |
| 143 #if defined(OS_ANDROID) | 149 #if defined(OS_ANDROID) |
| 144 chrome::VersionInfo version_info; | 150 chrome::VersionInfo version_info; |
| 145 if (version_info.IsOfficialBuild()) { | 151 if (version_info.IsOfficialBuild()) { |
| 146 sync_service_url_ = GURL(kSyncServerUrl); | 152 sync_service_url_ = GURL(kSyncServerUrl); |
| 147 } | 153 } |
| 148 #else | 154 #else |
| 149 // By default, dev, canary, and unbranded Chromium users will go to the | 155 // By default, dev, canary, and unbranded Chromium users will go to the |
| 150 // development servers. Development servers have more features than standard | 156 // development servers. Development servers have more features than standard |
| 151 // sync servers. Users with officially-branded Chrome stable and beta builds | 157 // sync servers. Users with officially-branded Chrome stable and beta builds |
| 152 // will go to the standard sync servers. | 158 // will go to the standard sync servers. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 RegisterAuthNotifications(); | 207 RegisterAuthNotifications(); |
| 202 | 208 |
| 203 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { | 209 if (!HasSyncSetupCompleted() || signin_->GetAuthenticatedUsername().empty()) { |
| 204 // Clean up in case of previous crash / setup abort / signout. | 210 // Clean up in case of previous crash / setup abort / signout. |
| 205 DisableForUser(); | 211 DisableForUser(); |
| 206 } | 212 } |
| 207 | 213 |
| 208 TryStart(); | 214 TryStart(); |
| 209 } | 215 } |
| 210 | 216 |
| 217 bool ProfileSyncService::ShouldInitializeCredentialCacheService() { | |
| 218 #if defined(OS_WIN) | |
| 219 return | |
| 220 base::win::GetVersion() >= base::win::VERSION_WIN8 && | |
|
Andrew T Wilson (Slow)
2012/07/20 01:04:05
This seems like a non-optimal pattern - why not ju
Raghu Simha
2012/07/20 23:35:22
I did this based on Roger's comment that we should
| |
| 221 syncer::CredentialCacheService::IsDefaultProfileDir( | |
| 222 profile()->GetPath()) && | |
| 223 !IsManaged() && | |
| 224 !sync_prefs_.IsStartSuppressed(); | |
| 225 #else | |
| 226 return false; | |
| 227 #endif | |
| 228 } | |
| 229 | |
| 230 bool ProfileSyncService::LoadedCachedCredentials() { | |
| 231 #if defined(OS_WIN) | |
| 232 return (credential_cache_service_ && | |
| 233 credential_cache_service_->SuccessfullyLoadedCredentials()); | |
| 234 #else | |
| 235 return false; | |
| 236 #endif | |
| 237 } | |
| 238 | |
| 211 void ProfileSyncService::TryStart() { | 239 void ProfileSyncService::TryStart() { |
| 240 #if defined(OS_WIN) | |
| 241 if (ShouldInitializeCredentialCacheService()) { | |
|
Andrew T Wilson (Slow)
2012/07/20 01:04:05
I'm not clear on why we need to do this initializa
Raghu Simha
2012/07/20 23:35:22
At first, I thought we would not initialize the cr
| |
| 242 // Lazily instantiate the credential cache service if required. | |
| 243 credential_cache_service_ = | |
| 244 CredentialCacheServiceFactory::GetInstance()->GetForProfile(profile_); | |
| 245 if (!setup_in_progress_ && signin_->GetAuthenticatedUsername().empty()) { | |
| 246 credential_cache_service_->LookForCachedCredentialsInAlternateProfile(); | |
| 247 } | |
| 248 return; | |
| 249 } | |
| 250 #endif | |
| 251 | |
| 212 if (!IsSyncEnabledAndLoggedIn()) | 252 if (!IsSyncEnabledAndLoggedIn()) |
| 213 return; | 253 return; |
| 214 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 254 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 215 if (!token_service) | 255 if (!token_service) |
| 216 return; | 256 return; |
| 217 // Don't start the backend if the token service hasn't finished loading tokens | 257 // Don't start the backend if the token service hasn't finished loading tokens |
| 218 // yet (if the backend is started before the sync token has been loaded, | 258 // yet (if the backend is started before the sync token has been loaded, |
| 219 // GetCredentials() will return bogus credentials). On auto_start platforms | 259 // GetCredentials() will return bogus credentials). On auto_start platforms |
| 220 // (like ChromeOS) we don't start sync until tokens are loaded, because the | 260 // (like ChromeOS) we don't start sync until tokens are loaded, because the |
| 221 // user can be "signed in" on those platforms long before the tokens get | 261 // user can be "signed in" on those platforms long before the tokens get |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 ConsumeCachedPassphraseIfPossible(); | 729 ConsumeCachedPassphraseIfPossible(); |
| 690 | 730 |
| 691 // The very first time the backend initializes is effectively the first time | 731 // The very first time the backend initializes is effectively the first time |
| 692 // we can say we successfully "synced". last_synced_time_ will only be null | 732 // we can say we successfully "synced". last_synced_time_ will only be null |
| 693 // in this case, because the pref wasn't restored on StartUp. | 733 // in this case, because the pref wasn't restored on StartUp. |
| 694 if (last_synced_time_.is_null()) { | 734 if (last_synced_time_.is_null()) { |
| 695 UpdateLastSyncedTime(); | 735 UpdateLastSyncedTime(); |
| 696 } | 736 } |
| 697 NotifyObservers(); | 737 NotifyObservers(); |
| 698 | 738 |
| 699 if (auto_start_enabled_ && !FirstSetupInProgress()) { | 739 if ((auto_start_enabled_ && !FirstSetupInProgress()) || |
| 700 // Backend is initialized but we're not in sync setup, so this must be an | 740 LoadedCachedCredentials()) { |
|
Andrew T Wilson (Slow)
2012/07/20 01:04:05
I think a better way to do this would be for the C
Raghu Simha
2012/07/20 23:35:22
Agreed. Done.
| |
| 701 // autostart - mark our sync setup as completed and we'll start syncing | 741 // If one of following is true, mark setup as completed and start syncing. |
| 702 // below. | 742 // 1) Backend is initialized but we're not in sync setup, so this must be an |
| 743 // autostart. | |
| 744 // 2) We are starting up using cached credentials. | |
| 703 SetSyncSetupCompleted(); | 745 SetSyncSetupCompleted(); |
| 704 NotifyObservers(); | 746 NotifyObservers(); |
| 705 } | 747 } |
| 706 | 748 |
| 707 if (HasSyncSetupCompleted()) { | 749 if (HasSyncSetupCompleted()) { |
| 708 ConfigureDataTypeManager(); | 750 ConfigureDataTypeManager(); |
| 709 } else { | 751 } else { |
| 710 DCHECK(FirstSetupInProgress()); | 752 DCHECK(FirstSetupInProgress()); |
| 711 } | 753 } |
| 712 } | 754 } |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 1805 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
| 1764 ProfileSyncService* old_this = this; | 1806 ProfileSyncService* old_this = this; |
| 1765 this->~ProfileSyncService(); | 1807 this->~ProfileSyncService(); |
| 1766 new(old_this) ProfileSyncService( | 1808 new(old_this) ProfileSyncService( |
| 1767 new ProfileSyncComponentsFactoryImpl(profile, | 1809 new ProfileSyncComponentsFactoryImpl(profile, |
| 1768 CommandLine::ForCurrentProcess()), | 1810 CommandLine::ForCurrentProcess()), |
| 1769 profile, | 1811 profile, |
| 1770 signin, | 1812 signin, |
| 1771 behavior); | 1813 behavior); |
| 1772 } | 1814 } |
| OLD | NEW |