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

Side by Side Diff: components/sync_sessions/sessions_sync_manager.cc

Issue 2776633003: Add taskid for navigation, created in session sync (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 tab_delegate->SetSyncId(tab_node_id); 382 tab_delegate->SetSyncId(tab_node_id);
383 sessions::SessionTab* session_tab = 383 sessions::SessionTab* session_tab =
384 session_tracker_.GetTab(current_machine_tag(), tab_id); 384 session_tracker_.GetTab(current_machine_tag(), tab_id);
385 385
386 // Get the previously synced url. 386 // Get the previously synced url.
387 int old_index = session_tab->normalized_navigation_index(); 387 int old_index = session_tab->normalized_navigation_index();
388 GURL old_url; 388 GURL old_url;
389 if (session_tab->navigations.size() > static_cast<size_t>(old_index)) 389 if (session_tab->navigations.size() > static_cast<size_t>(old_index))
390 old_url = session_tab->navigations[old_index].virtual_url(); 390 old_url = session_tab->navigations[old_index].virtual_url();
391 391
392 TabTasks* tab_tasks = task_tracker_.GetTabTasks(tab_id);
392 // Update the tracker's session representation. 393 // Update the tracker's session representation.
393 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab); 394 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab,
395 tab_tasks);
394 SetVariationIds(session_tab); 396 SetVariationIds(session_tab);
395 session_tracker_.GetSession(current_machine_tag())->modified_time = 397 session_tracker_.GetSession(current_machine_tag())->modified_time =
396 base::Time::Now(); 398 base::Time::Now();
397 399
398 // Write to the sync model itself. 400 // Write to the sync model itself.
399 sync_pb::EntitySpecifics specifics; 401 sync_pb::EntitySpecifics specifics;
400 specifics.mutable_session()->CopyFrom( 402 specifics.mutable_session()->CopyFrom(
401 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); 403 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id));
402 syncer::SyncData data = syncer::SyncData::CreateLocalData( 404 syncer::SyncData data = syncer::SyncData::CreateLocalData(
403 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_, 405 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_,
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 TabNodeIdToTag(current_machine_tag(), tab_delegate.GetSyncId()), 1029 TabNodeIdToTag(current_machine_tag(), tab_delegate.GetSyncId()),
1028 current_session_name_, entity); 1030 current_session_name_, entity);
1029 change_output->push_back( 1031 change_output->push_back(
1030 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); 1032 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data));
1031 } 1033 }
1032 1034
1033 // static 1035 // static
1034 void SessionsSyncManager::SetSessionTabFromDelegate( 1036 void SessionsSyncManager::SetSessionTabFromDelegate(
1035 const SyncedTabDelegate& tab_delegate, 1037 const SyncedTabDelegate& tab_delegate,
1036 base::Time mtime, 1038 base::Time mtime,
1037 sessions::SessionTab* session_tab) { 1039 sessions::SessionTab* session_tab,
1040 TabTasks* tab_tasks) {
1038 DCHECK(session_tab); 1041 DCHECK(session_tab);
1039 session_tab->window_id.set_id(tab_delegate.GetWindowId()); 1042 session_tab->window_id.set_id(tab_delegate.GetWindowId());
1040 session_tab->tab_id.set_id(tab_delegate.GetSessionId()); 1043 session_tab->tab_id.set_id(tab_delegate.GetSessionId());
1041 session_tab->tab_visual_index = 0; 1044 session_tab->tab_visual_index = 0;
1042 // Use -1 to indicate that the index hasn't been set properly yet. 1045 // Use -1 to indicate that the index hasn't been set properly yet.
1043 session_tab->current_navigation_index = -1; 1046 session_tab->current_navigation_index = -1;
1044 const SyncedWindowDelegate* window_delegate = 1047 const SyncedWindowDelegate* window_delegate =
1045 synced_window_delegates_getter()->FindById(tab_delegate.GetWindowId()); 1048 synced_window_delegates_getter()->FindById(tab_delegate.GetWindowId());
1046 session_tab->pinned = 1049 session_tab->pinned =
1047 window_delegate ? window_delegate->IsTabPinned(&tab_delegate) : false; 1050 window_delegate ? window_delegate->IsTabPinned(&tab_delegate) : false;
1048 session_tab->extension_app_id = tab_delegate.GetExtensionAppId(); 1051 session_tab->extension_app_id = tab_delegate.GetExtensionAppId();
1049 session_tab->user_agent_override.clear(); 1052 session_tab->user_agent_override.clear();
1050 session_tab->timestamp = mtime; 1053 session_tab->timestamp = mtime;
1051 const int current_index = tab_delegate.GetCurrentEntryIndex(); 1054 const int current_index = tab_delegate.GetCurrentEntryIndex();
1052 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount); 1055 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount);
1053 const int max_index = std::min(current_index + kMaxSyncNavigationCount, 1056 const int max_index = std::min(current_index + kMaxSyncNavigationCount,
1054 tab_delegate.GetEntryCount()); 1057 tab_delegate.GetEntryCount());
1055 bool is_supervised = tab_delegate.ProfileIsSupervised(); 1058 bool is_supervised = tab_delegate.ProfileIsSupervised();
1056 session_tab->navigations.clear(); 1059 session_tab->navigations.clear();
1057 1060
1061 if (tab_tasks != nullptr)
1062 tab_tasks->UpdateTask(current_index,
1063 tab_delegate.GetTransitionAtIndex(current_index),
1064 mtime.ToTimeT());
1065
1066 DVLOG(0) << "current_index: " << current_index << " of "
1067 << tab_delegate.GetEntryCount();
1068
1058 for (int i = min_index; i < max_index; ++i) { 1069 for (int i = min_index; i < max_index; ++i) {
1059 if (!tab_delegate.GetVirtualURLAtIndex(i).is_valid()) 1070 if (!tab_delegate.GetVirtualURLAtIndex(i).is_valid())
1060 continue; 1071 continue;
1061 sessions::SerializedNavigationEntry serialized_entry; 1072 sessions::SerializedNavigationEntry serialized_entry;
1062 tab_delegate.GetSerializedNavigationAtIndex(i, &serialized_entry); 1073 tab_delegate.GetSerializedNavigationAtIndex(i, &serialized_entry);
1063 1074
1064 // Set current_navigation_index to the index in navigations. 1075 // Set current_navigation_index to the index in navigations.
1065 if (i == current_index) 1076 if (i == current_index)
1066 session_tab->current_navigation_index = session_tab->navigations.size(); 1077 session_tab->current_navigation_index = session_tab->navigations.size();
1067 1078
1079 if (tab_tasks != nullptr && i < tab_tasks->GetNavigationsNum())
1080 serialized_entry.set_task_id(tab_tasks->GetTaskIdAtNav(i));
1081
1068 session_tab->navigations.push_back(serialized_entry); 1082 session_tab->navigations.push_back(serialized_entry);
1069 if (is_supervised) { 1083 if (is_supervised) {
1070 session_tab->navigations.back().set_blocked_state( 1084 session_tab->navigations.back().set_blocked_state(
1071 SerializedNavigationEntry::STATE_ALLOWED); 1085 SerializedNavigationEntry::STATE_ALLOWED);
1072 } 1086 }
1073 } 1087 }
1074 1088
1075 // If the current navigation is invalid, set the index to the end of the 1089 // If the current navigation is invalid, set the index to the end of the
1076 // navigation array. 1090 // navigation array.
1077 if (session_tab->current_navigation_index < 0) { 1091 if (session_tab->current_navigation_index < 0) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 } 1153 }
1140 1154
1141 // static 1155 // static
1142 std::string SessionsSyncManager::TagHashFromSpecifics( 1156 std::string SessionsSyncManager::TagHashFromSpecifics(
1143 const sync_pb::SessionSpecifics& specifics) { 1157 const sync_pb::SessionSpecifics& specifics) {
1144 return syncer::GenerateSyncableHash(syncer::SESSIONS, 1158 return syncer::GenerateSyncableHash(syncer::SESSIONS,
1145 TagFromSpecifics(specifics)); 1159 TagFromSpecifics(specifics));
1146 } 1160 }
1147 1161
1148 }; // namespace sync_sessions 1162 }; // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698