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

Unified Diff: chrome/browser/sync/sessions/session_data_type_controller.cc

Issue 367153005: Sync: Refactoring of DEVICE_INFO syncable type - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test issues with mocking of LocalDeviceInfoProvider Created 6 years, 5 months 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 side-by-side diff with in-line comments
Download patch
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..6717f7551d3f9b32c614cab9fce32fd89cf3f242 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_->GetLocalDeviceInfo()) {
+ 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

Powered by Google App Engine
This is Rietveld 408576698