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

Unified Diff: components/sync_sessions/sessions_sync_manager.cc

Issue 2776633003: Add taskid for navigation, created in session sync (Closed)
Patch Set: Fixing a bug where root of the task is not considered and addressing comments. Created 3 years, 8 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: 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 d61d75591b9a75f8bf94956cfdbe0bec00c1797b..56c6740637a4b49e9f4ca4dd8bbbe6137eb3f745 100644
--- a/components/sync_sessions/sessions_sync_manager.cc
+++ b/components/sync_sessions/sessions_sync_manager.cc
@@ -136,7 +136,8 @@ SessionsSyncManager::SessionsSyncManager(
local_event_router_(std::move(router)),
page_revisit_broadcaster_(this, sessions_client),
sessions_updated_callback_(sessions_updated_callback),
- datatype_refresh_callback_(datatype_refresh_callback) {}
+ datatype_refresh_callback_(datatype_refresh_callback),
+ task_tracker_(base::MakeUnique<TaskTracker>()) {}
SessionsSyncManager::~SessionsSyncManager() {}
@@ -399,6 +400,9 @@ void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab_delegate,
sync_pb::EntitySpecifics specifics;
specifics.mutable_session()->CopyFrom(
SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id));
+ // Intercept the sync model here to update task tracker and fill navigations
+ // with their ancestor navigations.
+ TrackTasks(tab_id, tab_delegate, specifics.mutable_session());
syncer::SyncData data = syncer::SyncData::CreateLocalData(
TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_,
specifics);
@@ -418,6 +422,51 @@ void SessionsSyncManager::AssociateTab(SyncedTabDelegate* const tab_delegate,
}
}
+void SessionsSyncManager::TrackTasks(
+ SessionID::id_type tab_id,
Nicolas Zea 2017/04/10 17:09:00 given tab_id comes from tab_delegate, it seems lik
shenchao 2017/04/11 18:53:44 Done.
+ SyncedTabDelegate* const tab_delegate,
+ sync_pb::SessionSpecifics* session_specifics) {
+ sync_pb::SessionTab* tab_specifics = session_specifics->mutable_tab();
+ // Index in the whole navigations of the tab.
+ int current_navigation_index = tab_delegate->GetCurrentEntryIndex();
+ // Index in the tab_specifics, where the navigations is a -6/+6 window
+ int current_index_in_tab_specifics =
+ tab_specifics->current_navigation_index();
+
+ TabTasks* tab_tasks = task_tracker_->GetTabTasks(tab_id);
+ tab_tasks->UpdateWithNavigation(
+ current_navigation_index,
+ tab_delegate->GetTransitionAtIndex(current_navigation_index));
+
+ for (int i = 0; i < tab_specifics->navigation_size(); i++) {
+ // Excluding blocked navigations, which are appended at tail.
+ if (tab_specifics->navigation(i).blocked_state() ==
+ sync_pb::TabNavigation::STATE_BLOCKED) {
+ break;
+ }
+
+ int navigation_index =
+ current_navigation_index - current_index_in_tab_specifics + i;
+ // Skipping navigations not been tracked by task_tracker.
+ if (navigation_index < 0 ||
+ navigation_index >= tab_tasks->GetNavigationsCount()) {
+ continue;
+ }
+ std::vector<int64_t> task_ids =
+ tab_tasks->RootToSelfTaskIdsOfNavigationIndex(navigation_index);
+ if (task_ids.empty())
+ continue;
+
+ tab_specifics->mutable_navigation(i)->set_task_id(task_ids.back());
+ // Pop the task id of navigation self.
+ task_ids.pop_back();
+ for (auto ancestor_task_id : task_ids) {
+ tab_specifics->mutable_navigation(i)->add_ancestor_task_id(
+ ancestor_task_id);
+ }
+ }
+}
+
bool SessionsSyncManager::RebuildAssociations() {
syncer::SyncDataList data(sync_processor_->GetAllSyncData(syncer::SESSIONS));
std::unique_ptr<syncer::SyncErrorFactory> error_handler(

Powered by Google App Engine
This is Rietveld 408576698