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

Unified Diff: components/sync_sessions/sessions_sync_manager.cc

Issue 2546163003: [Sync] Convert SyncSessions to NonUIDataTypeController and remove UIDataTypeController (Closed)
Patch Set: Fix SyncSessionsMetricsTest Created 4 years 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
« no previous file with comments | « components/sync_sessions/sessions_sync_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync_sessions/sessions_sync_manager.cc
diff --git a/components/sync_sessions/sessions_sync_manager.cc b/components/sync_sessions/sessions_sync_manager.cc
index acb6882b7bcae3f68e4bfc4110af0daf1694b060..04e01b70a32a5d0de015a3d9c00bc21bd9a2f004 100644
--- a/components/sync_sessions/sessions_sync_manager.cc
+++ b/components/sync_sessions/sessions_sync_manager.cc
@@ -92,6 +92,7 @@ SessionsSyncManager::SessionsSyncManager(
local_tab_pool_out_of_sync_(true),
sync_prefs_(sync_prefs),
local_device_(local_device),
+ current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER),
local_session_header_node_id_(TabNodePool::kInvalidTabNodeID),
stale_session_threshold_days_(kDefaultStaleSessionThresholdDays),
local_event_router_(std::move(router)),
@@ -121,6 +122,19 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing(
error_handler_ = std::move(error_handler);
sync_processor_ = std::move(sync_processor);
+ // SessionDataTypeController ensures that the local device info
+ // is available before activating this datatype.
+ DCHECK(local_device_);
+ const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo();
+ if (!local_device_info) {
+ merge_result.set_error(error_handler_->CreateAndUploadError(
+ FROM_HERE, "Failed to get local device info."));
+ return merge_result;
+ }
+
+ current_session_name_ = local_device_info->client_name();
+ current_device_type_ = local_device_info->device_type();
+
// It's possible(via RebuildAssociations) for lost_navigations_recorder_ to
// persist between sync being stopped and started. If it did persist, it's
// already associated with |sync_processor|, so leave it alone.
@@ -136,19 +150,7 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing(
// a conveniently safe time to assert sync is ready and the cache_guid is
// initialized.
if (current_machine_tag_.empty()) {
- InitializeCurrentMachineTag();
- }
-
- // SessionDataTypeController ensures that the local device info
- // is available before activating this datatype.
- DCHECK(local_device_);
- const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo();
- if (local_device_info) {
- current_session_name_ = local_device_info->client_name();
- } else {
- merge_result.set_error(error_handler_->CreateAndUploadError(
- FROM_HERE, "Failed to get local device info."));
- return merge_result;
+ InitializeCurrentMachineTag(local_device_->GetLocalSyncCacheGUID());
}
session_tracker_.SetLocalSessionTag(current_machine_tag_);
@@ -164,7 +166,7 @@ syncer::SyncMergeResult SessionsSyncManager::MergeDataAndStartSyncing(
base_specifics->set_session_tag(current_machine_tag());
sync_pb::SessionHeader* header_s = base_specifics->mutable_header();
header_s->set_client_name(current_session_name_);
- header_s->set_device_type(local_device_info->device_type());
+ header_s->set_device_type(current_device_type_);
syncer::SyncData data = syncer::SyncData::CreateLocalData(
current_machine_tag(), current_session_name_, specifics);
new_changes.push_back(
@@ -200,11 +202,7 @@ void SessionsSyncManager::AssociateWindows(
SyncedSession* current_session = session_tracker_.GetSession(local_tag);
current_session->modified_time = base::Time::Now();
header_s->set_client_name(current_session_name_);
- // SessionDataTypeController ensures that the local device info
- // is available before activating this datatype.
- DCHECK(local_device_);
- const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo();
- header_s->set_device_type(local_device_info->device_type());
+ header_s->set_device_type(current_device_type_);
session_tracker_.ResetSessionTracking(local_tag);
std::set<const SyncedWindowDelegate*> windows =
@@ -389,7 +387,7 @@ void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab,
base::Time::Now();
}
-void SessionsSyncManager::RebuildAssociations() {
+bool SessionsSyncManager::RebuildAssociations() {
syncer::SyncDataList data(sync_processor_->GetAllSyncData(syncer::SESSIONS));
std::unique_ptr<syncer::SyncErrorFactory> error_handler(
std::move(error_handler_));
@@ -397,8 +395,9 @@ void SessionsSyncManager::RebuildAssociations() {
std::move(sync_processor_));
StopSyncing(syncer::SESSIONS);
- MergeDataAndStartSyncing(syncer::SESSIONS, data, std::move(processor),
- std::move(error_handler));
+ syncer::SyncMergeResult merge_result = MergeDataAndStartSyncing(
+ syncer::SESSIONS, data, std::move(processor), std::move(error_handler));
+ return !merge_result.error().IsSet();
}
bool SessionsSyncManager::IsValidSessionHeader(
@@ -434,8 +433,8 @@ void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) {
if (local_tab_pool_out_of_sync_) {
// If our tab pool is corrupt, pay the price of a full re-association to
// fix things up. This takes care of the new tab modification as well.
- RebuildAssociations();
- DCHECK(!local_tab_pool_out_of_sync_);
+ bool rebuild_association_succeeded = RebuildAssociations();
+ DCHECK(!rebuild_association_succeeded || !local_tab_pool_out_of_sync_);
return;
}
@@ -767,7 +766,8 @@ void SessionsSyncManager::UpdateTrackerWithForeignSession(
}
}
-void SessionsSyncManager::InitializeCurrentMachineTag() {
+void SessionsSyncManager::InitializeCurrentMachineTag(
+ const std::string& cache_guid) {
DCHECK(current_machine_tag_.empty());
std::string persisted_guid;
persisted_guid = sync_prefs_->GetSyncSessionsGUID();
@@ -775,8 +775,6 @@ void SessionsSyncManager::InitializeCurrentMachineTag() {
current_machine_tag_ = persisted_guid;
DVLOG(1) << "Restoring persisted session sync guid: " << persisted_guid;
} else {
- DCHECK(local_device_);
- std::string cache_guid = local_device_->GetLocalSyncCacheGUID();
DCHECK(!cache_guid.empty());
current_machine_tag_ = BuildMachineTag(cache_guid);
DVLOG(1) << "Creating session sync guid: " << current_machine_tag_;
« no previous file with comments | « components/sync_sessions/sessions_sync_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698