| 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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "components/sync_sessions/synced_window_delegate.h" | 21 #include "components/sync_sessions/synced_window_delegate.h" |
| 22 #include "components/sync_sessions/synced_window_delegates_getter.h" | 22 #include "components/sync_sessions/synced_window_delegates_getter.h" |
| 23 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
| 24 | 24 |
| 25 using sessions::SerializedNavigationEntry; | 25 using sessions::SerializedNavigationEntry; |
| 26 using sync_driver::DeviceInfo; | 26 using sync_driver::DeviceInfo; |
| 27 using sync_driver::LocalDeviceInfoProvider; | 27 using sync_driver::LocalDeviceInfoProvider; |
| 28 using syncer::SyncChange; | 28 using syncer::SyncChange; |
| 29 using syncer::SyncData; | 29 using syncer::SyncData; |
| 30 | 30 |
| 31 namespace browser_sync { | 31 namespace sync_sessions { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Maximum number of favicons to sync. | 35 // Maximum number of favicons to sync. |
| 36 // TODO(zea): pull this from the server. | 36 // TODO(zea): pull this from the server. |
| 37 const int kMaxSyncFavicons = 200; | 37 const int kMaxSyncFavicons = 200; |
| 38 | 38 |
| 39 // The maximum number of navigations in each direction we care to sync. | 39 // The maximum number of navigations in each direction we care to sync. |
| 40 const int kMaxSyncNavigationCount = 6; | 40 const int kMaxSyncNavigationCount = 6; |
| 41 | 41 |
| 42 // The URL at which the set of synced tabs is displayed. We treat it differently | 42 // The URL at which the set of synced tabs is displayed. We treat it differently |
| 43 // from all other URL's as accessing it triggers a sync refresh of Sessions. | 43 // from all other URL's as accessing it triggers a sync refresh of Sessions. |
| 44 const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; | 44 const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs"; |
| 45 | 45 |
| 46 // Default number of days without activity after which a session is considered | 46 // Default number of days without activity after which a session is considered |
| 47 // stale and becomes a candidate for garbage collection. | 47 // stale and becomes a candidate for garbage collection. |
| 48 const int kDefaultStaleSessionThresholdDays = 14; // 2 weeks. | 48 const int kDefaultStaleSessionThresholdDays = 14; // 2 weeks. |
| 49 | 49 |
| 50 // Comparator function for use with std::sort that will sort tabs by | 50 // Comparator function for use with std::sort that will sort tabs by |
| 51 // descending timestamp (i.e., most recent first). | 51 // descending timestamp (i.e., most recent first). |
| 52 bool TabsRecencyComparator(const sessions::SessionTab* t1, | 52 bool TabsRecencyComparator(const sessions::SessionTab* t1, |
| 53 const sessions::SessionTab* t2) { | 53 const sessions::SessionTab* t2) { |
| 54 return t1->timestamp > t2->timestamp; | 54 return t1->timestamp > t2->timestamp; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Comparator function for use with std::sort that will sort sessions by | 57 // Comparator function for use with std::sort that will sort sessions by |
| 58 // descending modified_time (i.e., most recent first). | 58 // descending modified_time (i.e., most recent first). |
| 59 bool SessionsRecencyComparator(const sync_driver::SyncedSession* s1, | 59 bool SessionsRecencyComparator(const SyncedSession* s1, |
| 60 const sync_driver::SyncedSession* s2) { | 60 const SyncedSession* s2) { |
| 61 return s1->modified_time > s2->modified_time; | 61 return s1->modified_time > s2->modified_time; |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::string TagFromSpecifics(const sync_pb::SessionSpecifics& specifics) { | 64 std::string TagFromSpecifics(const sync_pb::SessionSpecifics& specifics) { |
| 65 if (specifics.has_header()) { | 65 if (specifics.has_header()) { |
| 66 return specifics.session_tag(); | 66 return specifics.session_tag(); |
| 67 } else if (specifics.has_tab()) { | 67 } else if (specifics.has_tab()) { |
| 68 return TabNodePool::TabIdToTag(specifics.session_tag(), | 68 return TabNodePool::TabIdToTag(specifics.session_tag(), |
| 69 specifics.tab_node_id()); | 69 specifics.tab_node_id()); |
| 70 } else { | 70 } else { |
| 71 return std::string(); | 71 return std::string(); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 // |local_device| is owned by ProfileSyncService, its lifetime exceeds | 77 // |local_device| is owned by ProfileSyncService, its lifetime exceeds |
| 78 // lifetime of SessionSyncManager. | 78 // lifetime of SessionSyncManager. |
| 79 SessionsSyncManager::SessionsSyncManager( | 79 SessionsSyncManager::SessionsSyncManager( |
| 80 sync_sessions::SyncSessionsClient* sessions_client, | 80 SyncSessionsClient* sessions_client, |
| 81 sync_driver::SyncPrefs* sync_prefs, | 81 sync_driver::SyncPrefs* sync_prefs, |
| 82 LocalDeviceInfoProvider* local_device, | 82 LocalDeviceInfoProvider* local_device, |
| 83 std::unique_ptr<LocalSessionEventRouter> router, | 83 std::unique_ptr<LocalSessionEventRouter> router, |
| 84 const base::Closure& sessions_updated_callback, | 84 const base::Closure& sessions_updated_callback, |
| 85 const base::Closure& datatype_refresh_callback) | 85 const base::Closure& datatype_refresh_callback) |
| 86 : sessions_client_(sessions_client), | 86 : sessions_client_(sessions_client), |
| 87 session_tracker_(sessions_client), | 87 session_tracker_(sessions_client), |
| 88 favicon_cache_(sessions_client->GetFaviconService(), | 88 favicon_cache_(sessions_client->GetFaviconService(), |
| 89 sessions_client->GetHistoryService(), | 89 sessions_client->GetHistoryService(), |
| 90 kMaxSyncFavicons), | 90 kMaxSyncFavicons), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 void SessionsSyncManager::AssociateWindows( | 182 void SessionsSyncManager::AssociateWindows( |
| 183 ReloadTabsOption option, | 183 ReloadTabsOption option, |
| 184 const syncer::SyncDataList& restored_tabs, | 184 const syncer::SyncDataList& restored_tabs, |
| 185 syncer::SyncChangeList* change_output) { | 185 syncer::SyncChangeList* change_output) { |
| 186 const std::string local_tag = current_machine_tag(); | 186 const std::string local_tag = current_machine_tag(); |
| 187 sync_pb::SessionSpecifics specifics; | 187 sync_pb::SessionSpecifics specifics; |
| 188 specifics.set_session_tag(local_tag); | 188 specifics.set_session_tag(local_tag); |
| 189 sync_pb::SessionHeader* header_s = specifics.mutable_header(); | 189 sync_pb::SessionHeader* header_s = specifics.mutable_header(); |
| 190 sync_driver::SyncedSession* current_session = | 190 SyncedSession* current_session = session_tracker_.GetSession(local_tag); |
| 191 session_tracker_.GetSession(local_tag); | |
| 192 current_session->modified_time = base::Time::Now(); | 191 current_session->modified_time = base::Time::Now(); |
| 193 header_s->set_client_name(current_session_name_); | 192 header_s->set_client_name(current_session_name_); |
| 194 // SessionDataTypeController ensures that the local device info | 193 // SessionDataTypeController ensures that the local device info |
| 195 // is available before activating this datatype. | 194 // is available before activating this datatype. |
| 196 DCHECK(local_device_); | 195 DCHECK(local_device_); |
| 197 const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo(); | 196 const DeviceInfo* local_device_info = local_device_->GetLocalDeviceInfo(); |
| 198 header_s->set_device_type(local_device_info->device_type()); | 197 header_s->set_device_type(local_device_info->device_type()); |
| 199 | 198 |
| 200 session_tracker_.ResetSessionTracking(local_tag); | 199 session_tracker_.ResetSessionTracking(local_tag); |
| 201 std::set<const SyncedWindowDelegate*> windows = | 200 std::set<const SyncedWindowDelegate*> windows = |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 local_tab_map_.clear(); | 442 local_tab_map_.clear(); |
| 444 local_tab_pool_.Clear(); | 443 local_tab_pool_.Clear(); |
| 445 current_machine_tag_.clear(); | 444 current_machine_tag_.clear(); |
| 446 current_session_name_.clear(); | 445 current_session_name_.clear(); |
| 447 local_session_header_node_id_ = TabNodePool::kInvalidTabNodeID; | 446 local_session_header_node_id_ = TabNodePool::kInvalidTabNodeID; |
| 448 } | 447 } |
| 449 | 448 |
| 450 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( | 449 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( |
| 451 syncer::ModelType type) const { | 450 syncer::ModelType type) const { |
| 452 syncer::SyncDataList list; | 451 syncer::SyncDataList list; |
| 453 const sync_driver::SyncedSession* session = NULL; | 452 const SyncedSession* session = NULL; |
| 454 if (!session_tracker_.LookupLocalSession(&session)) | 453 if (!session_tracker_.LookupLocalSession(&session)) |
| 455 return syncer::SyncDataList(); | 454 return syncer::SyncDataList(); |
| 456 | 455 |
| 457 // First construct the header node. | 456 // First construct the header node. |
| 458 sync_pb::EntitySpecifics header_entity; | 457 sync_pb::EntitySpecifics header_entity; |
| 459 header_entity.mutable_session()->set_session_tag(current_machine_tag()); | 458 header_entity.mutable_session()->set_session_tag(current_machine_tag()); |
| 460 sync_pb::SessionHeader* header_specifics = | 459 sync_pb::SessionHeader* header_specifics = |
| 461 header_entity.mutable_session()->mutable_header(); | 460 header_entity.mutable_session()->mutable_header(); |
| 462 header_specifics->MergeFrom(session->ToSessionHeader()); | 461 header_specifics->MergeFrom(session->ToSessionHeader()); |
| 463 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 462 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
| 464 current_machine_tag(), current_session_name_, header_entity); | 463 current_machine_tag(), current_session_name_, header_entity); |
| 465 list.push_back(data); | 464 list.push_back(data); |
| 466 | 465 |
| 467 sync_driver::SyncedSession::SyncedWindowMap::const_iterator win_iter; | 466 SyncedSession::SyncedWindowMap::const_iterator win_iter; |
| 468 for (win_iter = session->windows.begin(); win_iter != session->windows.end(); | 467 for (win_iter = session->windows.begin(); win_iter != session->windows.end(); |
| 469 ++win_iter) { | 468 ++win_iter) { |
| 470 std::vector<sessions::SessionTab*>::const_iterator tabs_iter; | 469 std::vector<sessions::SessionTab*>::const_iterator tabs_iter; |
| 471 for (tabs_iter = win_iter->second->tabs.begin(); | 470 for (tabs_iter = win_iter->second->tabs.begin(); |
| 472 tabs_iter != win_iter->second->tabs.end(); ++tabs_iter) { | 471 tabs_iter != win_iter->second->tabs.end(); ++tabs_iter) { |
| 473 sync_pb::EntitySpecifics entity; | 472 sync_pb::EntitySpecifics entity; |
| 474 sync_pb::SessionSpecifics* specifics = entity.mutable_session(); | 473 sync_pb::SessionSpecifics* specifics = entity.mutable_session(); |
| 475 specifics->mutable_tab()->MergeFrom((*tabs_iter)->ToSyncData()); | 474 specifics->mutable_tab()->MergeFrom((*tabs_iter)->ToSyncData()); |
| 476 specifics->set_session_tag(current_machine_tag_); | 475 specifics->set_session_tag(current_machine_tag_); |
| 477 | 476 |
| 478 TabLinksMap::const_iterator tab_map_iter = | 477 TabLinksMap::const_iterator tab_map_iter = |
| 479 local_tab_map_.find((*tabs_iter)->tab_id.id()); | 478 local_tab_map_.find((*tabs_iter)->tab_id.id()); |
| 480 DCHECK(tab_map_iter != local_tab_map_.end()); | 479 DCHECK(tab_map_iter != local_tab_map_.end()); |
| 481 specifics->set_tab_node_id(tab_map_iter->second->tab_node_id()); | 480 specifics->set_tab_node_id(tab_map_iter->second->tab_node_id()); |
| 482 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 481 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
| 483 TabNodePool::TabIdToTag(current_machine_tag_, | 482 TabNodePool::TabIdToTag(current_machine_tag_, |
| 484 specifics->tab_node_id()), | 483 specifics->tab_node_id()), |
| 485 current_session_name_, entity); | 484 current_session_name_, entity); |
| 486 list.push_back(data); | 485 list.push_back(data); |
| 487 } | 486 } |
| 488 } | 487 } |
| 489 return list; | 488 return list; |
| 490 } | 489 } |
| 491 | 490 |
| 492 bool SessionsSyncManager::GetLocalSession( | 491 bool SessionsSyncManager::GetLocalSession(const SyncedSession** local_session) { |
| 493 const sync_driver::SyncedSession** local_session) { | |
| 494 if (current_machine_tag_.empty()) | 492 if (current_machine_tag_.empty()) |
| 495 return false; | 493 return false; |
| 496 *local_session = session_tracker_.GetSession(current_machine_tag()); | 494 *local_session = session_tracker_.GetSession(current_machine_tag()); |
| 497 return true; | 495 return true; |
| 498 } | 496 } |
| 499 | 497 |
| 500 syncer::SyncError SessionsSyncManager::ProcessSyncChanges( | 498 syncer::SyncError SessionsSyncManager::ProcessSyncChanges( |
| 501 const tracked_objects::Location& from_here, | 499 const tracked_objects::Location& from_here, |
| 502 const syncer::SyncChangeList& change_list) { | 500 const syncer::SyncChangeList& change_list) { |
| 503 if (!sync_processor_.get()) { | 501 if (!sync_processor_.get()) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } else { | 570 } else { |
| 573 return syncer::SyncChange( | 571 return syncer::SyncChange( |
| 574 FROM_HERE, SyncChange::ACTION_DELETE, | 572 FROM_HERE, SyncChange::ACTION_DELETE, |
| 575 SyncData::CreateLocalDelete( | 573 SyncData::CreateLocalDelete( |
| 576 TabNodePool::TabIdToTag(current_machine_tag(), tab.tab_node_id()), | 574 TabNodePool::TabIdToTag(current_machine_tag(), tab.tab_node_id()), |
| 577 syncer::SESSIONS)); | 575 syncer::SESSIONS)); |
| 578 } | 576 } |
| 579 } | 577 } |
| 580 | 578 |
| 581 bool SessionsSyncManager::GetAllForeignSessions( | 579 bool SessionsSyncManager::GetAllForeignSessions( |
| 582 std::vector<const sync_driver::SyncedSession*>* sessions) { | 580 std::vector<const SyncedSession*>* sessions) { |
| 583 if (!session_tracker_.LookupAllForeignSessions( | 581 if (!session_tracker_.LookupAllForeignSessions( |
| 584 sessions, SyncedSessionTracker::PRESENTABLE)) | 582 sessions, SyncedSessionTracker::PRESENTABLE)) |
| 585 return false; | 583 return false; |
| 586 std::sort(sessions->begin(), sessions->end(), SessionsRecencyComparator); | 584 std::sort(sessions->begin(), sessions->end(), SessionsRecencyComparator); |
| 587 return true; | 585 return true; |
| 588 } | 586 } |
| 589 | 587 |
| 590 bool SessionsSyncManager::InitFromSyncModel( | 588 bool SessionsSyncManager::InitFromSyncModel( |
| 591 const syncer::SyncDataList& sync_data, | 589 const syncer::SyncDataList& sync_data, |
| 592 syncer::SyncDataList* restored_tabs, | 590 syncer::SyncDataList* restored_tabs, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 // reused for reassociation. | 636 // reused for reassociation. |
| 639 local_tab_pool_.AddTabNode(specifics.tab_node_id()); | 637 local_tab_pool_.AddTabNode(specifics.tab_node_id()); |
| 640 restored_tabs->push_back(*it); | 638 restored_tabs->push_back(*it); |
| 641 } | 639 } |
| 642 } | 640 } |
| 643 } | 641 } |
| 644 } | 642 } |
| 645 | 643 |
| 646 // Cleanup all foreign sessions, since orphaned tabs may have been added after | 644 // Cleanup all foreign sessions, since orphaned tabs may have been added after |
| 647 // the header. | 645 // the header. |
| 648 std::vector<const sync_driver::SyncedSession*> sessions; | 646 std::vector<const SyncedSession*> sessions; |
| 649 session_tracker_.LookupAllForeignSessions(&sessions, | 647 session_tracker_.LookupAllForeignSessions(&sessions, |
| 650 SyncedSessionTracker::RAW); | 648 SyncedSessionTracker::RAW); |
| 651 for (const auto* session : sessions) { | 649 for (const auto* session : sessions) { |
| 652 session_tracker_.CleanupSession(session->session_tag); | 650 session_tracker_.CleanupSession(session->session_tag); |
| 653 } | 651 } |
| 654 | 652 |
| 655 UMA_HISTOGRAM_COUNTS_100("Sync.SessionsBadForeignHashOnMergeCount", | 653 UMA_HISTOGRAM_COUNTS_100("Sync.SessionsBadForeignHashOnMergeCount", |
| 656 bad_foreign_hash_count); | 654 bad_foreign_hash_count); |
| 657 | 655 |
| 658 return found_current_header; | 656 return found_current_header; |
| 659 } | 657 } |
| 660 | 658 |
| 661 void SessionsSyncManager::UpdateTrackerWithForeignSession( | 659 void SessionsSyncManager::UpdateTrackerWithForeignSession( |
| 662 const sync_pb::SessionSpecifics& specifics, | 660 const sync_pb::SessionSpecifics& specifics, |
| 663 const base::Time& modification_time) { | 661 const base::Time& modification_time) { |
| 664 std::string foreign_session_tag = specifics.session_tag(); | 662 std::string foreign_session_tag = specifics.session_tag(); |
| 665 DCHECK_NE(foreign_session_tag, current_machine_tag()); | 663 DCHECK_NE(foreign_session_tag, current_machine_tag()); |
| 666 | 664 |
| 667 sync_driver::SyncedSession* foreign_session = | 665 SyncedSession* foreign_session = |
| 668 session_tracker_.GetSession(foreign_session_tag); | 666 session_tracker_.GetSession(foreign_session_tag); |
| 669 if (specifics.has_header()) { | 667 if (specifics.has_header()) { |
| 670 // Read in the header data for this foreign session. Header data is | 668 // Read in the header data for this foreign session. Header data is |
| 671 // essentially a collection of windows, each of which has an ordered id list | 669 // essentially a collection of windows, each of which has an ordered id list |
| 672 // for their tabs. | 670 // for their tabs. |
| 673 | 671 |
| 674 if (!IsValidSessionHeader(specifics.header())) { | 672 if (!IsValidSessionHeader(specifics.header())) { |
| 675 LOG(WARNING) << "Ignoring foreign session node with invalid header " | 673 LOG(WARNING) << "Ignoring foreign session node with invalid header " |
| 676 << "and tag " << foreign_session_tag << "."; | 674 << "and tag " << foreign_session_tag << "."; |
| 677 return; | 675 return; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 sync_prefs_->SetSyncSessionsGUID(current_machine_tag_); | 752 sync_prefs_->SetSyncSessionsGUID(current_machine_tag_); |
| 755 } | 753 } |
| 756 | 754 |
| 757 local_tab_pool_.SetMachineTag(current_machine_tag_); | 755 local_tab_pool_.SetMachineTag(current_machine_tag_); |
| 758 } | 756 } |
| 759 | 757 |
| 760 // static | 758 // static |
| 761 void SessionsSyncManager::PopulateSessionHeaderFromSpecifics( | 759 void SessionsSyncManager::PopulateSessionHeaderFromSpecifics( |
| 762 const sync_pb::SessionHeader& header_specifics, | 760 const sync_pb::SessionHeader& header_specifics, |
| 763 base::Time mtime, | 761 base::Time mtime, |
| 764 sync_driver::SyncedSession* session_header) { | 762 SyncedSession* session_header) { |
| 765 if (header_specifics.has_client_name()) | 763 if (header_specifics.has_client_name()) |
| 766 session_header->session_name = header_specifics.client_name(); | 764 session_header->session_name = header_specifics.client_name(); |
| 767 if (header_specifics.has_device_type()) { | 765 if (header_specifics.has_device_type()) { |
| 768 switch (header_specifics.device_type()) { | 766 switch (header_specifics.device_type()) { |
| 769 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: | 767 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: |
| 770 session_header->device_type = sync_driver::SyncedSession::TYPE_WIN; | 768 session_header->device_type = SyncedSession::TYPE_WIN; |
| 771 break; | 769 break; |
| 772 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: | 770 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: |
| 773 session_header->device_type = sync_driver::SyncedSession::TYPE_MACOSX; | 771 session_header->device_type = SyncedSession::TYPE_MACOSX; |
| 774 break; | 772 break; |
| 775 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: | 773 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: |
| 776 session_header->device_type = sync_driver::SyncedSession::TYPE_LINUX; | 774 session_header->device_type = SyncedSession::TYPE_LINUX; |
| 777 break; | 775 break; |
| 778 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: | 776 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: |
| 779 session_header->device_type = sync_driver::SyncedSession::TYPE_CHROMEOS; | 777 session_header->device_type = SyncedSession::TYPE_CHROMEOS; |
| 780 break; | 778 break; |
| 781 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: | 779 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: |
| 782 session_header->device_type = sync_driver::SyncedSession::TYPE_PHONE; | 780 session_header->device_type = SyncedSession::TYPE_PHONE; |
| 783 break; | 781 break; |
| 784 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: | 782 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: |
| 785 session_header->device_type = sync_driver::SyncedSession::TYPE_TABLET; | 783 session_header->device_type = SyncedSession::TYPE_TABLET; |
| 786 break; | 784 break; |
| 787 case sync_pb::SyncEnums_DeviceType_TYPE_OTHER: | 785 case sync_pb::SyncEnums_DeviceType_TYPE_OTHER: |
| 788 // Intentionally fall-through | 786 // Intentionally fall-through |
| 789 default: | 787 default: |
| 790 session_header->device_type = sync_driver::SyncedSession::TYPE_OTHER; | 788 session_header->device_type = SyncedSession::TYPE_OTHER; |
| 791 break; | 789 break; |
| 792 } | 790 } |
| 793 } | 791 } |
| 794 session_header->modified_time = | 792 session_header->modified_time = |
| 795 std::max(mtime, session_header->modified_time); | 793 std::max(mtime, session_header->modified_time); |
| 796 } | 794 } |
| 797 | 795 |
| 798 // static | 796 // static |
| 799 void SessionsSyncManager::BuildSyncedSessionFromSpecifics( | 797 void SessionsSyncManager::BuildSyncedSessionFromSpecifics( |
| 800 const std::string& session_tag, | 798 const std::string& session_tag, |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 FaviconCache* SessionsSyncManager::GetFaviconCache() { | 1068 FaviconCache* SessionsSyncManager::GetFaviconCache() { |
| 1071 return &favicon_cache_; | 1069 return &favicon_cache_; |
| 1072 } | 1070 } |
| 1073 | 1071 |
| 1074 SyncedWindowDelegatesGetter* | 1072 SyncedWindowDelegatesGetter* |
| 1075 SessionsSyncManager::synced_window_delegates_getter() const { | 1073 SessionsSyncManager::synced_window_delegates_getter() const { |
| 1076 return sessions_client_->GetSyncedWindowDelegatesGetter(); | 1074 return sessions_client_->GetSyncedWindowDelegatesGetter(); |
| 1077 } | 1075 } |
| 1078 | 1076 |
| 1079 void SessionsSyncManager::DoGarbageCollection() { | 1077 void SessionsSyncManager::DoGarbageCollection() { |
| 1080 std::vector<const sync_driver::SyncedSession*> sessions; | 1078 std::vector<const SyncedSession*> sessions; |
| 1081 if (!session_tracker_.LookupAllForeignSessions(&sessions, | 1079 if (!session_tracker_.LookupAllForeignSessions(&sessions, |
| 1082 SyncedSessionTracker::RAW)) | 1080 SyncedSessionTracker::RAW)) |
| 1083 return; // No foreign sessions. | 1081 return; // No foreign sessions. |
| 1084 | 1082 |
| 1085 // Iterate through all the sessions and delete any with age older than | 1083 // Iterate through all the sessions and delete any with age older than |
| 1086 // |stale_session_threshold_days_|. | 1084 // |stale_session_threshold_days_|. |
| 1087 syncer::SyncChangeList changes; | 1085 syncer::SyncChangeList changes; |
| 1088 for (const auto* session : sessions) { | 1086 for (const auto* session : sessions) { |
| 1089 int session_age_in_days = | 1087 int session_age_in_days = |
| 1090 (base::Time::Now() - session->modified_time).InDays(); | 1088 (base::Time::Now() - session->modified_time).InDays(); |
| 1091 if (session_age_in_days > stale_session_threshold_days_) { | 1089 if (session_age_in_days > stale_session_threshold_days_) { |
| 1092 std::string session_tag = session->session_tag; | 1090 std::string session_tag = session->session_tag; |
| 1093 DVLOG(1) << "Found stale session " << session_tag << " with age " | 1091 DVLOG(1) << "Found stale session " << session_tag << " with age " |
| 1094 << session_age_in_days << ", deleting."; | 1092 << session_age_in_days << ", deleting."; |
| 1095 DeleteForeignSessionInternal(session_tag, &changes); | 1093 DeleteForeignSessionInternal(session_tag, &changes); |
| 1096 } | 1094 } |
| 1097 } | 1095 } |
| 1098 | 1096 |
| 1099 if (!changes.empty()) | 1097 if (!changes.empty()) |
| 1100 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 1098 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 1101 } | 1099 } |
| 1102 | 1100 |
| 1103 // static | 1101 // static |
| 1104 std::string SessionsSyncManager::TagHashFromSpecifics( | 1102 std::string SessionsSyncManager::TagHashFromSpecifics( |
| 1105 const sync_pb::SessionSpecifics& specifics) { | 1103 const sync_pb::SessionSpecifics& specifics) { |
| 1106 return syncer::syncable::GenerateSyncableHash(syncer::SESSIONS, | 1104 return syncer::syncable::GenerateSyncableHash(syncer::SESSIONS, |
| 1107 TagFromSpecifics(specifics)); | 1105 TagFromSpecifics(specifics)); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 }; // namespace browser_sync | 1108 }; // namespace sync_sessions |
| OLD | NEW |