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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 kMaxSyncFavicons), | 129 kMaxSyncFavicons), |
130 local_tab_pool_out_of_sync_(true), | 130 local_tab_pool_out_of_sync_(true), |
131 sync_prefs_(sync_prefs), | 131 sync_prefs_(sync_prefs), |
132 local_device_(local_device), | 132 local_device_(local_device), |
133 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER), | 133 current_device_type_(sync_pb::SyncEnums_DeviceType_TYPE_OTHER), |
134 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), | 134 local_session_header_node_id_(TabNodePool::kInvalidTabNodeID), |
135 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), | 135 stale_session_threshold_days_(kDefaultStaleSessionThresholdDays), |
136 local_event_router_(std::move(router)), | 136 local_event_router_(std::move(router)), |
137 page_revisit_broadcaster_(this, sessions_client), | 137 page_revisit_broadcaster_(this, sessions_client), |
138 sessions_updated_callback_(sessions_updated_callback), | 138 sessions_updated_callback_(sessions_updated_callback), |
139 datatype_refresh_callback_(datatype_refresh_callback) {} | 139 datatype_refresh_callback_(datatype_refresh_callback), |
140 task_tracker_(base::MakeUnique<TaskTracker>()) {} | |
140 | 141 |
141 SessionsSyncManager::~SessionsSyncManager() {} | 142 SessionsSyncManager::~SessionsSyncManager() {} |
142 | 143 |
143 // Returns the GUID-based string that should be used for | 144 // Returns the GUID-based string that should be used for |
144 // |SessionsSyncManager::current_machine_tag_|. | 145 // |SessionsSyncManager::current_machine_tag_|. |
145 static std::string BuildMachineTag(const std::string& cache_guid) { | 146 static std::string BuildMachineTag(const std::string& cache_guid) { |
146 std::string machine_tag = "session_sync"; | 147 std::string machine_tag = "session_sync"; |
147 machine_tag.append(cache_guid); | 148 machine_tag.append(cache_guid); |
148 return machine_tag; | 149 return machine_tag; |
149 } | 150 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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); |
394 SetVariationIds(session_tab); | 395 SetVariationIds(session_tab); |
395 session_tracker_.GetSession(current_machine_tag())->modified_time = | 396 session_tracker_.GetSession(current_machine_tag())->modified_time = |
396 base::Time::Now(); | 397 base::Time::Now(); |
397 | 398 |
398 // Write to the sync model itself. | 399 // Write to the sync model itself. |
399 sync_pb::EntitySpecifics specifics; | 400 sync_pb::EntitySpecifics specifics; |
400 specifics.mutable_session()->CopyFrom( | 401 specifics.mutable_session()->CopyFrom( |
401 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); | 402 SessionTabToSpecifics(*session_tab, current_machine_tag(), tab_node_id)); |
403 // Intercept the sync model here to update task tracker and fill navigations | |
404 // with their ancestor navigations. | |
405 TrackTasks(tab_id, tab_delegate, specifics.mutable_session()); | |
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_, |
404 specifics); | 408 specifics); |
405 change_output->push_back( | 409 change_output->push_back( |
406 syncer::SyncChange(FROM_HERE, | 410 syncer::SyncChange(FROM_HERE, |
407 existing_tab_node ? syncer::SyncChange::ACTION_UPDATE | 411 existing_tab_node ? syncer::SyncChange::ACTION_UPDATE |
408 : syncer::SyncChange::ACTION_ADD, | 412 : syncer::SyncChange::ACTION_ADD, |
409 data)); | 413 data)); |
410 | 414 |
411 int current_index = tab_delegate->GetCurrentEntryIndex(); | 415 int current_index = tab_delegate->GetCurrentEntryIndex(); |
412 const GURL new_url = tab_delegate->GetVirtualURLAtIndex(current_index); | 416 const GURL new_url = tab_delegate->GetVirtualURLAtIndex(current_index); |
413 if (new_url != old_url) { | 417 if (new_url != old_url) { |
414 favicon_cache_.OnFaviconVisited( | 418 favicon_cache_.OnFaviconVisited( |
415 new_url, tab_delegate->GetFaviconURLAtIndex(current_index)); | 419 new_url, tab_delegate->GetFaviconURLAtIndex(current_index)); |
416 page_revisit_broadcaster_.OnPageVisit( | 420 page_revisit_broadcaster_.OnPageVisit( |
417 new_url, tab_delegate->GetTransitionAtIndex(current_index)); | 421 new_url, tab_delegate->GetTransitionAtIndex(current_index)); |
418 } | 422 } |
419 } | 423 } |
420 | 424 |
425 void SessionsSyncManager::TrackTasks( | |
426 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.
| |
427 SyncedTabDelegate* const tab_delegate, | |
428 sync_pb::SessionSpecifics* session_specifics) { | |
429 sync_pb::SessionTab* tab_specifics = session_specifics->mutable_tab(); | |
430 // Index in the whole navigations of the tab. | |
431 int current_navigation_index = tab_delegate->GetCurrentEntryIndex(); | |
432 // Index in the tab_specifics, where the navigations is a -6/+6 window | |
433 int current_index_in_tab_specifics = | |
434 tab_specifics->current_navigation_index(); | |
435 | |
436 TabTasks* tab_tasks = task_tracker_->GetTabTasks(tab_id); | |
437 tab_tasks->UpdateWithNavigation( | |
438 current_navigation_index, | |
439 tab_delegate->GetTransitionAtIndex(current_navigation_index)); | |
440 | |
441 for (int i = 0; i < tab_specifics->navigation_size(); i++) { | |
442 // Excluding blocked navigations, which are appended at tail. | |
443 if (tab_specifics->navigation(i).blocked_state() == | |
444 sync_pb::TabNavigation::STATE_BLOCKED) { | |
445 break; | |
446 } | |
447 | |
448 int navigation_index = | |
449 current_navigation_index - current_index_in_tab_specifics + i; | |
450 // Skipping navigations not been tracked by task_tracker. | |
451 if (navigation_index < 0 || | |
452 navigation_index >= tab_tasks->GetNavigationsCount()) { | |
453 continue; | |
454 } | |
455 std::vector<int64_t> task_ids = | |
456 tab_tasks->RootToSelfTaskIdsOfNavigationIndex(navigation_index); | |
457 if (task_ids.empty()) | |
458 continue; | |
459 | |
460 tab_specifics->mutable_navigation(i)->set_task_id(task_ids.back()); | |
461 // Pop the task id of navigation self. | |
462 task_ids.pop_back(); | |
463 for (auto ancestor_task_id : task_ids) { | |
464 tab_specifics->mutable_navigation(i)->add_ancestor_task_id( | |
465 ancestor_task_id); | |
466 } | |
467 } | |
468 } | |
469 | |
421 bool SessionsSyncManager::RebuildAssociations() { | 470 bool SessionsSyncManager::RebuildAssociations() { |
422 syncer::SyncDataList data(sync_processor_->GetAllSyncData(syncer::SESSIONS)); | 471 syncer::SyncDataList data(sync_processor_->GetAllSyncData(syncer::SESSIONS)); |
423 std::unique_ptr<syncer::SyncErrorFactory> error_handler( | 472 std::unique_ptr<syncer::SyncErrorFactory> error_handler( |
424 std::move(error_handler_)); | 473 std::move(error_handler_)); |
425 std::unique_ptr<syncer::SyncChangeProcessor> processor( | 474 std::unique_ptr<syncer::SyncChangeProcessor> processor( |
426 std::move(sync_processor_)); | 475 std::move(sync_processor_)); |
427 | 476 |
428 StopSyncing(syncer::SESSIONS); | 477 StopSyncing(syncer::SESSIONS); |
429 syncer::SyncMergeResult merge_result = MergeDataAndStartSyncing( | 478 syncer::SyncMergeResult merge_result = MergeDataAndStartSyncing( |
430 syncer::SESSIONS, data, std::move(processor), std::move(error_handler)); | 479 syncer::SESSIONS, data, std::move(processor), std::move(error_handler)); |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 } | 1188 } |
1140 | 1189 |
1141 // static | 1190 // static |
1142 std::string SessionsSyncManager::TagHashFromSpecifics( | 1191 std::string SessionsSyncManager::TagHashFromSpecifics( |
1143 const sync_pb::SessionSpecifics& specifics) { | 1192 const sync_pb::SessionSpecifics& specifics) { |
1144 return syncer::GenerateSyncableHash(syncer::SESSIONS, | 1193 return syncer::GenerateSyncableHash(syncer::SESSIONS, |
1145 TagFromSpecifics(specifics)); | 1194 TagFromSpecifics(specifics)); |
1146 } | 1195 } |
1147 | 1196 |
1148 }; // namespace sync_sessions | 1197 }; // namespace sync_sessions |
OLD | NEW |