| 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 "components/browser_sync/browser/profile_sync_service.h" | 5 #include "components/browser_sync/browser/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 204 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
| 205 encrypt_everything_allowed_(true), | 205 encrypt_everything_allowed_(true), |
| 206 encrypt_everything_(false), | 206 encrypt_everything_(false), |
| 207 encryption_pending_(false), | 207 encryption_pending_(false), |
| 208 configure_status_(DataTypeManager::UNKNOWN), | 208 configure_status_(DataTypeManager::UNKNOWN), |
| 209 oauth2_token_service_(oauth2_token_service), | 209 oauth2_token_service_(oauth2_token_service), |
| 210 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), | 210 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
| 211 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), | 211 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), |
| 212 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), | 212 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), |
| 213 network_resources_(new syncer::HttpBridgeNetworkResources), | 213 network_resources_(new syncer::HttpBridgeNetworkResources), |
| 214 start_behavior_(start_behavior), |
| 214 backend_mode_(IDLE), | 215 backend_mode_(IDLE), |
| 215 need_backup_(false), | 216 need_backup_(false), |
| 216 backup_finished_(false), | 217 backup_finished_(false), |
| 217 catch_up_configure_in_progress_(false), | 218 catch_up_configure_in_progress_(false), |
| 218 passphrase_prompt_triggered_by_version_(false), | 219 passphrase_prompt_triggered_by_version_(false), |
| 219 weak_factory_(this), | 220 weak_factory_(this), |
| 220 startup_controller_weak_factory_(this) { | 221 startup_controller_weak_factory_(this) { |
| 221 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 222 DCHECK(sync_client_); | 223 DCHECK(sync_client_); |
| 223 startup_controller_.reset(new browser_sync::StartupController( | |
| 224 start_behavior, | |
| 225 oauth2_token_service, | |
| 226 &sync_prefs_, | |
| 227 signin_.get(), | |
| 228 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | |
| 229 startup_controller_weak_factory_.GetWeakPtr(), | |
| 230 SYNC))); | |
| 231 backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( | |
| 232 &sync_prefs_, | |
| 233 signin_.get(), | |
| 234 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | |
| 235 startup_controller_weak_factory_.GetWeakPtr(), | |
| 236 BACKUP), | |
| 237 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | |
| 238 startup_controller_weak_factory_.GetWeakPtr(), | |
| 239 ROLLBACK))); | |
| 240 scoped_ptr<browser_sync::LocalSessionEventRouter> router( | |
| 241 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); | |
| 242 local_device_ = sync_client_->GetSyncApiComponentFactory() | |
| 243 ->CreateLocalDeviceInfoProvider(); | |
| 244 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( | |
| 245 sync_service_url_, local_device_->GetSyncUserAgent(), | |
| 246 url_request_context_, | |
| 247 browser_sync::SyncStoppedReporter::ResultCallback())); | |
| 248 sessions_sync_manager_.reset(new SessionsSyncManager( | |
| 249 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), | |
| 250 router.Pass(), | |
| 251 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, | |
| 252 weak_factory_.GetWeakPtr()), | |
| 253 base::Bind(&ProfileSyncService::TriggerRefresh, | |
| 254 weak_factory_.GetWeakPtr(), | |
| 255 syncer::ModelTypeSet(syncer::SESSIONS)))); | |
| 256 device_info_sync_service_.reset( | |
| 257 new DeviceInfoSyncService(local_device_.get())); | |
| 258 | |
| 259 std::string last_version = sync_prefs_.GetLastRunVersion(); | 224 std::string last_version = sync_prefs_.GetLastRunVersion(); |
| 260 std::string current_version = PRODUCT_VERSION; | 225 std::string current_version = PRODUCT_VERSION; |
| 261 sync_prefs_.SetLastRunVersion(current_version); | 226 sync_prefs_.SetLastRunVersion(current_version); |
| 262 | 227 |
| 263 // Check for a major version change. Note that the versions have format | 228 // Check for a major version change. Note that the versions have format |
| 264 // MAJOR.MINOR.BUILD.PATCH. | 229 // MAJOR.MINOR.BUILD.PATCH. |
| 265 if (last_version.substr(0, last_version.find('.')) != | 230 if (last_version.substr(0, last_version.find('.')) != |
| 266 current_version.substr(0, current_version.find('.'))) { | 231 current_version.substr(0, current_version.find('.'))) { |
| 267 passphrase_prompt_triggered_by_version_ = true; | 232 passphrase_prompt_triggered_by_version_ = true; |
| 268 } | 233 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 282 if (!oauth2_token_service_) | 247 if (!oauth2_token_service_) |
| 283 return false; | 248 return false; |
| 284 | 249 |
| 285 return oauth2_token_service_->RefreshTokenIsAvailable( | 250 return oauth2_token_service_->RefreshTokenIsAvailable( |
| 286 signin_->GetAccountIdToUse()); | 251 signin_->GetAccountIdToUse()); |
| 287 } | 252 } |
| 288 | 253 |
| 289 void ProfileSyncService::Initialize() { | 254 void ProfileSyncService::Initialize() { |
| 290 sync_client_->Initialize(this); | 255 sync_client_->Initialize(this); |
| 291 | 256 |
| 257 startup_controller_.reset(new browser_sync::StartupController( |
| 258 start_behavior_, oauth2_token_service_, &sync_prefs_, signin_.get(), |
| 259 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
| 260 startup_controller_weak_factory_.GetWeakPtr(), SYNC))); |
| 261 backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( |
| 262 &sync_prefs_, signin_.get(), |
| 263 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
| 264 startup_controller_weak_factory_.GetWeakPtr(), BACKUP), |
| 265 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
| 266 startup_controller_weak_factory_.GetWeakPtr(), ROLLBACK))); |
| 267 scoped_ptr<browser_sync::LocalSessionEventRouter> router( |
| 268 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); |
| 269 local_device_ = sync_client_->GetSyncApiComponentFactory() |
| 270 ->CreateLocalDeviceInfoProvider(); |
| 271 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( |
| 272 sync_service_url_, local_device_->GetSyncUserAgent(), |
| 273 url_request_context_, |
| 274 browser_sync::SyncStoppedReporter::ResultCallback())); |
| 275 sessions_sync_manager_.reset(new SessionsSyncManager( |
| 276 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), |
| 277 router.Pass(), |
| 278 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, |
| 279 weak_factory_.GetWeakPtr()), |
| 280 base::Bind(&ProfileSyncService::TriggerRefresh, |
| 281 weak_factory_.GetWeakPtr(), |
| 282 syncer::ModelTypeSet(syncer::SESSIONS)))); |
| 283 device_info_sync_service_.reset( |
| 284 new DeviceInfoSyncService(local_device_.get())); |
| 285 |
| 286 sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod |
| 287 register_platform_types_callback = |
| 288 sync_client_->GetRegisterPlatformTypesCallback(); |
| 289 sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes( |
| 290 register_platform_types_callback); |
| 291 |
| 292 // We clear this here (vs Shutdown) because we want to remember that an error | 292 // We clear this here (vs Shutdown) because we want to remember that an error |
| 293 // happened on shutdown so we can display details (message, location) about it | 293 // happened on shutdown so we can display details (message, location) about it |
| 294 // in about:sync. | 294 // in about:sync. |
| 295 ClearStaleErrors(); | 295 ClearStaleErrors(); |
| 296 | 296 |
| 297 sync_prefs_.AddSyncPrefObserver(this); | 297 sync_prefs_.AddSyncPrefObserver(this); |
| 298 | 298 |
| 299 // If sync isn't allowed, the only thing to do is to turn it off. | 299 // If sync isn't allowed, the only thing to do is to turn it off. |
| 300 if (!IsSyncAllowed()) { | 300 if (!IsSyncAllowed()) { |
| 301 RequestStop(CLEAR_DATA); | 301 RequestStop(CLEAR_DATA); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 base::FilePath(kSyncDataFolderName) : | 665 base::FilePath(kSyncDataFolderName) : |
| 666 base::FilePath(kSyncBackupDataFolderName); | 666 base::FilePath(kSyncBackupDataFolderName); |
| 667 | 667 |
| 668 invalidation::InvalidationService* invalidator = | 668 invalidation::InvalidationService* invalidator = |
| 669 backend_mode_ == SYNC ? sync_client_->GetInvalidationService() : nullptr; | 669 backend_mode_ == SYNC ? sync_client_->GetInvalidationService() : nullptr; |
| 670 | 670 |
| 671 directory_path_ = base_directory_.Append(sync_folder); | 671 directory_path_ = base_directory_.Append(sync_folder); |
| 672 | 672 |
| 673 backend_.reset( | 673 backend_.reset( |
| 674 sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( | 674 sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( |
| 675 debug_identifier_, sync_client_.get(), invalidator, | 675 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), |
| 676 sync_prefs_.AsWeakPtr(), directory_path_)); | 676 directory_path_)); |
| 677 | 677 |
| 678 // Initialize the backend. Every time we start up a new SyncBackendHost, | 678 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 679 // we'll want to start from a fresh SyncDB, so delete any old one that might | 679 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 680 // be there. | 680 // be there. |
| 681 InitializeBackend(ShouldDeleteSyncFolder()); | 681 InitializeBackend(ShouldDeleteSyncFolder()); |
| 682 | 682 |
| 683 UpdateFirstSyncTimePref(); | 683 UpdateFirstSyncTimePref(); |
| 684 | 684 |
| 685 ReportPreviousSessionMemoryWarningCount(); | 685 ReportPreviousSessionMemoryWarningCount(); |
| 686 } | 686 } |
| (...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2696 } | 2696 } |
| 2697 | 2697 |
| 2698 std::string ProfileSyncService::unrecoverable_error_message() const { | 2698 std::string ProfileSyncService::unrecoverable_error_message() const { |
| 2699 return unrecoverable_error_message_; | 2699 return unrecoverable_error_message_; |
| 2700 } | 2700 } |
| 2701 | 2701 |
| 2702 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() | 2702 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() |
| 2703 const { | 2703 const { |
| 2704 return unrecoverable_error_location_; | 2704 return unrecoverable_error_location_; |
| 2705 } | 2705 } |
| OLD | NEW |