OLD | NEW |
---|---|
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 // |local_device| is owned by ProfileSyncService, its lifetime exceeds | 116 // |local_device| is owned by ProfileSyncService, its lifetime exceeds |
117 // lifetime of SessionSyncManager. | 117 // lifetime of SessionSyncManager. |
118 SessionsSyncManager::SessionsSyncManager( | 118 SessionsSyncManager::SessionsSyncManager( |
119 sync_sessions::SyncSessionsClient* sessions_client, | 119 sync_sessions::SyncSessionsClient* sessions_client, |
120 syncer::SyncPrefs* sync_prefs, | 120 syncer::SyncPrefs* sync_prefs, |
121 LocalDeviceInfoProvider* local_device, | 121 LocalDeviceInfoProvider* local_device, |
122 std::unique_ptr<LocalSessionEventRouter> router, | 122 std::unique_ptr<LocalSessionEventRouter> router, |
123 const base::Closure& sessions_updated_callback, | 123 const base::Closure& sessions_updated_callback, |
124 const base::Closure& datatype_refresh_callback) | 124 const base::Closure& datatype_refresh_callback, |
125 std::unique_ptr<base::Clock> clock) | |
125 : sessions_client_(sessions_client), | 126 : sessions_client_(sessions_client), |
126 session_tracker_(sessions_client), | 127 session_tracker_(sessions_client), |
127 favicon_cache_(sessions_client->GetFaviconService(), | 128 favicon_cache_(sessions_client->GetFaviconService(), |
128 sessions_client->GetHistoryService(), | 129 sessions_client->GetHistoryService(), |
129 kMaxSyncFavicons), | 130 kMaxSyncFavicons), |
130 local_tab_pool_out_of_sync_(true), | 131 local_tab_pool_out_of_sync_(true), |
131 sync_prefs_(sync_prefs), | 132 sync_prefs_(sync_prefs), |
132 local_device_(local_device), | 133 local_device_(local_device), |
133 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER), | 134 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER), |
134 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), | 135 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), |
135 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 136 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
136 local_event_router_(std::move(router)), | 137 local_event_router_(std::move(router)), |
137 page_revisit_broadcaster_(this, sessions_client), | 138 page_revisit_broadcaster_(this, sessions_client), |
138 sessions_updated_callback_(sessions_updated_callback), | 139 sessions_updated_callback_(sessions_updated_callback), |
139 datatype_refresh_callback_(datatype_refresh_callback) {} | 140 datatype_refresh_callback_(datatype_refresh_callback), |
141 task_tracker_(base::MakeUnique<TaskTracker>(std::move(clock))) {} | |
140 | 142 |
141 SessionsSyncManager::~SessionsSyncManager() {} | 143 SessionsSyncManager::~SessionsSyncManager() {} |
142 | 144 |
143 // Returns the GUID-based string that should be used for | 145 // Returns the GUID-based string that should be used for |
144 // |SessionsSyncManager::current_machine_tag_|. | 146 // |SessionsSyncManager::current_machine_tag_|. |
145 static std::string BuildMachineTag(const std::string& cache_guid) { | 147 static std::string BuildMachineTag(const std::string& cache_guid) { |
146 std::string machine_tag = "session_sync"; | 148 std::string machine_tag = "session_sync"; |
147 machine_tag.append(cache_guid); | 149 machine_tag.append(cache_guid); |
148 return machine_tag; | 150 return machine_tag; |
149 } | 151 } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 tab_delegate->SetSyncId(tab_node_id); | 384 tab_delegate->SetSyncId(tab_node_id); |
383 sessions::SessionTab* session_tab = | 385 sessions::SessionTab* session_tab = |
384 session_tracker_.GetTab(current_machine_tag(), tab_id); | 386 session_tracker_.GetTab(current_machine_tag(), tab_id); |
385 | 387 |
386 // Get the previously synced url. | 388 // Get the previously synced url. |
387 int old_index = session_tab->normalized_navigation_index(); | 389 int old_index = session_tab->normalized_navigation_index(); |
388 GURL old_url; | 390 GURL old_url; |
389 if (session_tab->navigations.size() > static_cast<size_t>(old_index)) | 391 if (session_tab->navigations.size() > static_cast<size_t>(old_index)) |
390 old_url = session_tab->navigations[old_index].virtual_url(); | 392 old_url = session_tab->navigations[old_index].virtual_url(); |
391 | 393 |
394 TabTasks* tab_tasks = task_tracker_->GetTabTasks(tab_id); | |
392 // Update the tracker's session representation. | 395 // Update the tracker's session representation. |
393 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab); | 396 SetSessionTabFromDelegate(*tab_delegate, base::Time::Now(), session_tab, |
397 tab_tasks); | |
394 SetVariationIds(session_tab); | 398 SetVariationIds(session_tab); |
395 session_tracker_.GetSession(current_machine_tag())->modified_time = | 399 session_tracker_.GetSession(current_machine_tag())->modified_time = |
396 base::Time::Now(); | 400 base::Time::Now(); |
397 | 401 |
398 // Write to the sync model itself. | 402 // Write to the sync model itself. |
399 sync_pb::EntitySpecifics specifics; | 403 sync_pb::EntitySpecifics specifics; |
400 specifics.mutable_session()->CopyFrom( | 404 specifics.mutable_session()->CopyFrom( |
401 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); | 405 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); |
402 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 406 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
403 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_, | 407 TabNodeIdToTag(current_machine_tag(), tab_node_id), current_session_name_, |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1027 TabNodeIdToTag(current_machine_tag(), tab_delegate.GetSyncId()), | 1031 TabNodeIdToTag(current_machine_tag(), tab_delegate.GetSyncId()), |
1028 current_session_name_, entity); | 1032 current_session_name_, entity); |
1029 change_output->push_back( | 1033 change_output->push_back( |
1030 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); | 1034 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE, data)); |
1031 } | 1035 } |
1032 | 1036 |
1033 // static | 1037 // static |
1034 void SessionsSyncManager::SetSessionTabFromDelegate( | 1038 void SessionsSyncManager::SetSessionTabFromDelegate( |
1035 const SyncedTabDelegate& tab_delegate, | 1039 const SyncedTabDelegate& tab_delegate, |
1036 base::Time mtime, | 1040 base::Time mtime, |
1037 sessions::SessionTab* session_tab) { | 1041 sessions::SessionTab* session_tab, |
1042 TabTasks* tab_tasks) { | |
1038 DCHECK(session_tab); | 1043 DCHECK(session_tab); |
1039 session_tab->window_id.set_id(tab_delegate.GetWindowId()); | 1044 session_tab->window_id.set_id(tab_delegate.GetWindowId()); |
1040 session_tab->tab_id.set_id(tab_delegate.GetSessionId()); | 1045 session_tab->tab_id.set_id(tab_delegate.GetSessionId()); |
1041 session_tab->tab_visual_index = 0; | 1046 session_tab->tab_visual_index = 0; |
1042 // Use -1 to indicate that the index hasn't been set properly yet. | 1047 // Use -1 to indicate that the index hasn't been set properly yet. |
1043 session_tab->current_navigation_index = -1; | 1048 session_tab->current_navigation_index = -1; |
1044 const SyncedWindowDelegate* window_delegate = | 1049 const SyncedWindowDelegate* window_delegate = |
1045 synced_window_delegates_getter()->FindById(tab_delegate.GetWindowId()); | 1050 synced_window_delegates_getter()->FindById(tab_delegate.GetWindowId()); |
1046 session_tab->pinned = | 1051 session_tab->pinned = |
1047 window_delegate ? window_delegate->IsTabPinned(&tab_delegate) : false; | 1052 window_delegate ? window_delegate->IsTabPinned(&tab_delegate) : false; |
1048 session_tab->extension_app_id = tab_delegate.GetExtensionAppId(); | 1053 session_tab->extension_app_id = tab_delegate.GetExtensionAppId(); |
1049 session_tab->user_agent_override.clear(); | 1054 session_tab->user_agent_override.clear(); |
1050 session_tab->timestamp = mtime; | 1055 session_tab->timestamp = mtime; |
1051 const int current_index = tab_delegate.GetCurrentEntryIndex(); | 1056 const int current_index = tab_delegate.GetCurrentEntryIndex(); |
1052 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount); | 1057 const int min_index = std::max(0, current_index - kMaxSyncNavigationCount); |
1053 const int max_index = std::min(current_index + kMaxSyncNavigationCount, | 1058 const int max_index = std::min(current_index + kMaxSyncNavigationCount, |
1054 tab_delegate.GetEntryCount()); | 1059 tab_delegate.GetEntryCount()); |
1055 bool is_supervised = tab_delegate.ProfileIsSupervised(); | 1060 bool is_supervised = tab_delegate.ProfileIsSupervised(); |
1056 session_tab->navigations.clear(); | 1061 session_tab->navigations.clear(); |
1057 | 1062 |
1063 if (tab_tasks != nullptr) | |
1064 tab_tasks->UpdateTask(current_index, | |
Nicolas Zea
2017/03/27 20:43:52
nit: curly braces around multi-line if
shenchao
2017/04/06 00:54:55
Done.
| |
1065 tab_delegate.GetTransitionAtIndex(current_index)); | |
1066 | |
1067 DVLOG(0) << "current_index: " << current_index << " of " | |
Nicolas Zea
2017/03/27 20:43:52
Did you mean to leave this?
shenchao
2017/04/06 00:54:55
Done.
| |
1068 << tab_delegate.GetEntryCount(); | |
1069 | |
1058 for (int i = min_index; i < max_index; ++i) { | 1070 for (int i = min_index; i < max_index; ++i) { |
1059 if (!tab_delegate.GetVirtualURLAtIndex(i).is_valid()) | 1071 if (!tab_delegate.GetVirtualURLAtIndex(i).is_valid()) |
1060 continue; | 1072 continue; |
1061 sessions::SerializedNavigationEntry serialized_entry; | 1073 sessions::SerializedNavigationEntry serialized_entry; |
1062 tab_delegate.GetSerializedNavigationAtIndex(i, &serialized_entry); | 1074 tab_delegate.GetSerializedNavigationAtIndex(i, &serialized_entry); |
1063 | 1075 |
1064 // Set current_navigation_index to the index in navigations. | 1076 // Set current_navigation_index to the index in navigations. |
1065 if (i == current_index) | 1077 if (i == current_index) |
1066 session_tab->current_navigation_index = session_tab->navigations.size(); | 1078 session_tab->current_navigation_index = session_tab->navigations.size(); |
1067 | 1079 |
1080 if (tab_tasks != nullptr && i < tab_tasks->GetNavigationsCount()) | |
1081 serialized_entry.set_task_id(tab_tasks->GetTaskIdAtNavIndex(i)); | |
1082 | |
1068 session_tab->navigations.push_back(serialized_entry); | 1083 session_tab->navigations.push_back(serialized_entry); |
1069 if (is_supervised) { | 1084 if (is_supervised) { |
1070 session_tab->navigations.back().set_blocked_state( | 1085 session_tab->navigations.back().set_blocked_state( |
1071 SerializedNavigationEntry::STATE_ALLOWED); | 1086 SerializedNavigationEntry::STATE_ALLOWED); |
1072 } | 1087 } |
1073 } | 1088 } |
1074 | 1089 |
1075 // If the current navigation is invalid, set the index to the end of the | 1090 // If the current navigation is invalid, set the index to the end of the |
1076 // navigation array. | 1091 // navigation array. |
1077 if (session_tab->current_navigation_index < 0) { | 1092 if (session_tab->current_navigation_index < 0) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 } | 1154 } |
1140 | 1155 |
1141 // static | 1156 // static |
1142 std::string SessionsSyncManager::TagHashFromSpecifics( | 1157 std::string SessionsSyncManager::TagHashFromSpecifics( |
1143 const sync_pb::SessionSpecifics& specifics) { | 1158 const sync_pb::SessionSpecifics& specifics) { |
1144 return syncer::GenerateSyncableHash(syncer::SESSIONS, | 1159 return syncer::GenerateSyncableHash(syncer::SESSIONS, |
1145 TagFromSpecifics(specifics)); | 1160 TagFromSpecifics(specifics)); |
1146 } | 1161 } |
1147 | 1162 |
1148 }; // namespace sync_sessions | 1163 }; // namespace sync_sessions |
OLD | NEW |