Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: components/browser_sync/browser/profile_sync_service.cc

Issue 1451023005: Revert of [Sync] Componentize ProfileSyncComponentsFactoryImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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),
215 backend_mode_(IDLE), 214 backend_mode_(IDLE),
216 need_backup_(false), 215 need_backup_(false),
217 backup_finished_(false), 216 backup_finished_(false),
218 catch_up_configure_in_progress_(false), 217 catch_up_configure_in_progress_(false),
219 passphrase_prompt_triggered_by_version_(false), 218 passphrase_prompt_triggered_by_version_(false),
220 weak_factory_(this), 219 weak_factory_(this),
221 startup_controller_weak_factory_(this) { 220 startup_controller_weak_factory_(this) {
222 DCHECK(thread_checker_.CalledOnValidThread()); 221 DCHECK(thread_checker_.CalledOnValidThread());
223 DCHECK(sync_client_); 222 DCHECK(sync_client_);
224 std::string last_version = sync_prefs_.GetLastRunVersion();
225 std::string current_version = PRODUCT_VERSION;
226 sync_prefs_.SetLastRunVersion(current_version);
227
228 // Check for a major version change. Note that the versions have format
229 // MAJOR.MINOR.BUILD.PATCH.
230 if (last_version.substr(0, last_version.find('.')) !=
231 current_version.substr(0, current_version.find('.'))) {
232 passphrase_prompt_triggered_by_version_ = true;
233 }
234 }
235
236 ProfileSyncService::~ProfileSyncService() {
237 sync_prefs_.RemoveSyncPrefObserver(this);
238 // Shutdown() should have been called before destruction.
239 CHECK(!backend_initialized_);
240 }
241
242 bool ProfileSyncService::CanSyncStart() const {
243 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
244 }
245
246 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() {
247 if (!oauth2_token_service_)
248 return false;
249
250 return oauth2_token_service_->RefreshTokenIsAvailable(
251 signin_->GetAccountIdToUse());
252 }
253
254 void ProfileSyncService::Initialize() {
255 sync_client_->Initialize(this);
256
257 startup_controller_.reset(new browser_sync::StartupController( 223 startup_controller_.reset(new browser_sync::StartupController(
258 start_behavior_, oauth2_token_service_, &sync_prefs_, signin_.get(), 224 start_behavior,
225 oauth2_token_service,
226 &sync_prefs_,
227 signin_.get(),
259 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 228 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
260 startup_controller_weak_factory_.GetWeakPtr(), SYNC))); 229 startup_controller_weak_factory_.GetWeakPtr(),
230 SYNC)));
261 backup_rollback_controller_.reset(new sync_driver::BackupRollbackController( 231 backup_rollback_controller_.reset(new sync_driver::BackupRollbackController(
262 &sync_prefs_, signin_.get(), 232 &sync_prefs_,
233 signin_.get(),
263 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 234 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
264 startup_controller_weak_factory_.GetWeakPtr(), BACKUP), 235 startup_controller_weak_factory_.GetWeakPtr(),
236 BACKUP),
265 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, 237 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents,
266 startup_controller_weak_factory_.GetWeakPtr(), ROLLBACK))); 238 startup_controller_weak_factory_.GetWeakPtr(),
239 ROLLBACK)));
267 scoped_ptr<browser_sync::LocalSessionEventRouter> router( 240 scoped_ptr<browser_sync::LocalSessionEventRouter> router(
268 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter()); 241 sync_client_->GetSyncSessionsClient()->GetLocalSessionEventRouter());
269 local_device_ = sync_client_->GetSyncApiComponentFactory() 242 local_device_ = sync_client_->GetSyncApiComponentFactory()
270 ->CreateLocalDeviceInfoProvider(); 243 ->CreateLocalDeviceInfoProvider();
271 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter( 244 sync_stopped_reporter_.reset(new browser_sync::SyncStoppedReporter(
272 sync_service_url_, local_device_->GetSyncUserAgent(), 245 sync_service_url_, local_device_->GetSyncUserAgent(),
273 url_request_context_, 246 url_request_context_,
274 browser_sync::SyncStoppedReporter::ResultCallback())); 247 browser_sync::SyncStoppedReporter::ResultCallback()));
275 sessions_sync_manager_.reset(new SessionsSyncManager( 248 sessions_sync_manager_.reset(new SessionsSyncManager(
276 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), 249 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(),
277 router.Pass(), 250 router.Pass(),
278 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, 251 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated,
279 weak_factory_.GetWeakPtr()), 252 weak_factory_.GetWeakPtr()),
280 base::Bind(&ProfileSyncService::TriggerRefresh, 253 base::Bind(&ProfileSyncService::TriggerRefresh,
281 weak_factory_.GetWeakPtr(), 254 weak_factory_.GetWeakPtr(),
282 syncer::ModelTypeSet(syncer::SESSIONS)))); 255 syncer::ModelTypeSet(syncer::SESSIONS))));
283 device_info_sync_service_.reset( 256 device_info_sync_service_.reset(
284 new DeviceInfoSyncService(local_device_.get())); 257 new DeviceInfoSyncService(local_device_.get()));
285 258
286 sync_driver::SyncApiComponentFactory::RegisterDataTypesMethod 259 std::string last_version = sync_prefs_.GetLastRunVersion();
287 register_platform_types_callback = 260 std::string current_version = PRODUCT_VERSION;
288 sync_client_->GetRegisterPlatformTypesCallback(); 261 sync_prefs_.SetLastRunVersion(current_version);
289 sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes( 262
290 register_platform_types_callback); 263 // Check for a major version change. Note that the versions have format
264 // MAJOR.MINOR.BUILD.PATCH.
265 if (last_version.substr(0, last_version.find('.')) !=
266 current_version.substr(0, current_version.find('.'))) {
267 passphrase_prompt_triggered_by_version_ = true;
268 }
269 }
270
271 ProfileSyncService::~ProfileSyncService() {
272 sync_prefs_.RemoveSyncPrefObserver(this);
273 // Shutdown() should have been called before destruction.
274 CHECK(!backend_initialized_);
275 }
276
277 bool ProfileSyncService::CanSyncStart() const {
278 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn();
279 }
280
281 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() {
282 if (!oauth2_token_service_)
283 return false;
284
285 return oauth2_token_service_->RefreshTokenIsAvailable(
286 signin_->GetAccountIdToUse());
287 }
288
289 void ProfileSyncService::Initialize() {
290 sync_client_->Initialize(this);
291 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()) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_, invalidator, sync_prefs_.AsWeakPtr(), 675 debug_identifier_, sync_client_.get(), invalidator,
676 directory_path_)); 676 sync_prefs_.AsWeakPtr(), 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
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 }
OLDNEW
« no previous file with comments | « components/browser_sync/browser/profile_sync_service.h ('k') | components/sync_driver/fake_sync_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698