Chromium Code Reviews| Index: chrome/browser/sync/sessions/session_data_type_controller.cc |
| diff --git a/chrome/browser/sync/sessions/session_data_type_controller.cc b/chrome/browser/sync/sessions/session_data_type_controller.cc |
| index 25578b633782bf2008e974d58bf050517b1536ee..1ae2c904c54c0ad5e842dbbf4890be03fdea5a8f 100644 |
| --- a/chrome/browser/sync/sessions/session_data_type_controller.cc |
| +++ b/chrome/browser/sync/sessions/session_data_type_controller.cc |
| @@ -8,6 +8,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" |
| #include "chrome/browser/sync/glue/synced_window_delegate.h" |
| +#include "chrome/browser/sync/sessions/synced_window_delegates_getter.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_service.h" |
| @@ -20,6 +21,8 @@ namespace browser_sync { |
| SessionDataTypeController::SessionDataTypeController( |
| SyncApiComponentFactory* sync_factory, |
| Profile* profile, |
| + SyncedWindowDelegatesGetter* synced_window_getter, |
| + LocalDeviceInfoProvider* local_device, |
| const DisableTypeCallback& disable_callback) |
| : UIDataTypeController( |
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| @@ -27,7 +30,12 @@ SessionDataTypeController::SessionDataTypeController( |
| disable_callback, |
| syncer::SESSIONS, |
| sync_factory), |
| - profile_(profile) { |
| + profile_(profile), |
| + synced_window_getter_(synced_window_getter), |
| + local_device_(local_device), |
| + waiting_on_session_restore_(false), |
| + waiting_on_local_device_info_(false) { |
| + DCHECK(local_device_); |
| } |
| SessionDataTypeController::~SessionDataTypeController() {} |
| @@ -35,7 +43,7 @@ SessionDataTypeController::~SessionDataTypeController() {} |
| bool SessionDataTypeController::StartModels() { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| std::set<browser_sync::SyncedWindowDelegate*> window = |
| - browser_sync::SyncedWindowDelegate::GetSyncedWindowDelegates(); |
| + synced_window_getter_->GetSyncedWindowDelegates(); |
| for (std::set<browser_sync::SyncedWindowDelegate*>::const_iterator i = |
| window.begin(); i != window.end(); ++i) { |
| if ((*i)->IsSessionRestoreInProgress()) { |
| @@ -43,16 +51,35 @@ bool SessionDataTypeController::StartModels() { |
| this, |
| chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, |
| content::Source<Profile>(profile_)); |
| - return false; |
| + waiting_on_session_restore_ = true; |
| + break; |
| } |
| } |
| - return true; |
| + |
| + if (!local_device_->IsInitialized()) { |
|
rlarocque
2014/07/08 18:25:38
I like the way you've handled this, but I can't th
stanisc
2014/07/09 21:58:37
Local Device Info initialization is asynchronous.
|
| + subscription_ = local_device_->RegisterOnInitializedCallback( |
| + base::Bind(&SessionDataTypeController::OnLocalDeviceInfoInitialized, |
| + this)); |
| + waiting_on_local_device_info_ = true; |
| + } |
| + |
| + return !IsWaiting(); |
| } |
| void SessionDataTypeController::StopModels() { |
| notification_registrar_.RemoveAll(); |
| } |
| +bool SessionDataTypeController::IsWaiting() { |
| + return waiting_on_session_restore_ || waiting_on_local_device_info_; |
| +} |
| + |
| +void SessionDataTypeController::MaybeCompleteLoading() { |
| + if (state_ == MODEL_STARTING && !IsWaiting()) { |
| + OnModelLoaded(); |
| + } |
| +} |
| + |
| void SessionDataTypeController::Observe( |
| int type, |
| const content::NotificationSource& source, |
| @@ -61,7 +88,17 @@ void SessionDataTypeController::Observe( |
| DCHECK_EQ(chrome::NOTIFICATION_SESSION_RESTORE_COMPLETE, type); |
| DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| notification_registrar_.RemoveAll(); |
| - OnModelLoaded(); |
| + |
| + waiting_on_session_restore_ = false; |
| + MaybeCompleteLoading(); |
| +} |
| + |
| +void SessionDataTypeController::OnLocalDeviceInfoInitialized() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + subscription_.reset(); |
| + |
| + waiting_on_local_device_info_ = false; |
| + MaybeCompleteLoading(); |
| } |
| } // namespace browser_sync |