Index: components/browser_sync/browser/profile_sync_service.cc |
diff --git a/components/browser_sync/browser/profile_sync_service.cc b/components/browser_sync/browser/profile_sync_service.cc |
index a41b846d748d38185b63c7bdc93751727ff758ed..e58ae72248ec4d7861e0339384cf5bb41231554b 100644 |
--- a/components/browser_sync/browser/profile_sync_service.cc |
+++ b/components/browser_sync/browser/profile_sync_service.cc |
@@ -1530,15 +1530,19 @@ bool ProfileSyncService::IsFirstSetupInProgress() const { |
return !IsFirstSetupComplete() && startup_controller_->IsSetupInProgress(); |
} |
-void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { |
- // This method is a no-op if |setup_in_progress_| remains unchanged. |
- if (startup_controller_->IsSetupInProgress() == setup_in_progress) |
- return; |
+std::unique_ptr<sync_driver::SyncSetupInProgressHandle> |
+ProfileSyncService::GetSetupInProgressHandle() { |
+ if (++outstanding_setup_in_progress_handles_ == 1) { |
+ DCHECK(!startup_controller_->IsSetupInProgress()); |
+ startup_controller_->SetSetupInProgress(true); |
- startup_controller_->SetSetupInProgress(setup_in_progress); |
- if (!setup_in_progress && IsBackendInitialized()) |
- ReconfigureDatatypeManager(); |
- NotifyObservers(); |
+ NotifyObservers(); |
+ } |
+ |
+ return std::unique_ptr<sync_driver::SyncSetupInProgressHandle>( |
+ new sync_driver::SyncSetupInProgressHandle( |
+ base::Bind(&ProfileSyncService::OnSetupInProgressHandleDestroyed, |
+ weak_factory_.GetWeakPtr()))); |
} |
bool ProfileSyncService::IsSyncAllowed() const { |
@@ -2544,3 +2548,16 @@ tracked_objects::Location ProfileSyncService::unrecoverable_error_location() |
const { |
return unrecoverable_error_location_; |
} |
+ |
+void ProfileSyncService::OnSetupInProgressHandleDestroyed() { |
Nicolas Zea
2016/06/13 20:01:00
nit: maybe DCHECK that the counter never goes nega
tommycli
2016/06/13 20:27:31
Done.
|
+ // Don't re-start Sync until all outstanding handles are destroyed. |
+ if (--outstanding_setup_in_progress_handles_ != 0) |
+ return; |
+ |
+ DCHECK(startup_controller_->IsSetupInProgress()); |
+ startup_controller_->SetSetupInProgress(false); |
+ |
+ if (IsBackendInitialized()) |
+ ReconfigureDatatypeManager(); |
+ NotifyObservers(); |
+} |