OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync/sessions2/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions2/sessions_sync_manager.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #if !defined(OS_ANDROID) | 8 #if !defined(OS_ANDROID) |
9 #include "chrome/browser/network_time/navigation_time_helper.h" | 9 #include "chrome/browser/network_time/navigation_time_helper.h" |
10 #endif | 10 #endif |
| 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 12 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
12 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 13 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/favicon_status.h" | 15 #include "content/public/browser/favicon_status.h" |
15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
19 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
20 #include "sync/api/sync_error.h" | 21 #include "sync/api/sync_error.h" |
(...skipping 10 matching lines...) Expand all Loading... |
31 | 32 |
32 // Maximum number of favicons to sync. | 33 // Maximum number of favicons to sync. |
33 // TODO(zea): pull this from the server. | 34 // TODO(zea): pull this from the server. |
34 static const int kMaxSyncFavicons = 200; | 35 static const int kMaxSyncFavicons = 200; |
35 | 36 |
36 // The maximum number of navigations in each direction we care to sync. | 37 // The maximum number of navigations in each direction we care to sync. |
37 static const int kMaxSyncNavigationCount = 6; | 38 static const int kMaxSyncNavigationCount = 6; |
38 | 39 |
39 SessionsSyncManager::SessionsSyncManager( | 40 SessionsSyncManager::SessionsSyncManager( |
40 Profile* profile, | 41 Profile* profile, |
41 scoped_ptr<SyncPrefs> sync_prefs, | |
42 SyncInternalApiDelegate* delegate) | 42 SyncInternalApiDelegate* delegate) |
43 : favicon_cache_(profile, kMaxSyncFavicons), | 43 : favicon_cache_(profile, kMaxSyncFavicons), |
| 44 sync_prefs_(profile->GetPrefs()), |
44 profile_(profile), | 45 profile_(profile), |
45 delegate_(delegate), | 46 delegate_(delegate), |
46 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID) { | 47 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID) { |
47 sync_prefs_ = sync_prefs.Pass(); | |
48 } | 48 } |
49 | 49 |
50 SessionsSyncManager::~SessionsSyncManager() { | 50 SessionsSyncManager::~SessionsSyncManager() { |
51 } | 51 } |
52 | 52 |
53 // Returns the GUID-based string that should be used for | 53 // Returns the GUID-based string that should be used for |
54 // |SessionsSyncManager::current_machine_tag_|. | 54 // |SessionsSyncManager::current_machine_tag_|. |
55 static std::string BuildMachineTag(const std::string& cache_guid) { | 55 static std::string BuildMachineTag(const std::string& cache_guid) { |
56 std::string machine_tag = "session_sync"; | 56 std::string machine_tag = "session_sync"; |
57 machine_tag.append(cache_guid); | 57 machine_tag.append(cache_guid); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 sync_pb::SessionHeader* header_s = base_specifics->mutable_header(); | 98 sync_pb::SessionHeader* header_s = base_specifics->mutable_header(); |
99 header_s->set_client_name(current_session_name_); | 99 header_s->set_client_name(current_session_name_); |
100 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); | 100 header_s->set_device_type(DeviceInfo::GetLocalDeviceType()); |
101 syncer::SyncData data = syncer::SyncData::CreateLocalData( | 101 syncer::SyncData data = syncer::SyncData::CreateLocalData( |
102 current_machine_tag(), current_session_name_, specifics); | 102 current_machine_tag(), current_session_name_, specifics); |
103 new_changes.push_back(syncer::SyncChange( | 103 new_changes.push_back(syncer::SyncChange( |
104 FROM_HERE, syncer::SyncChange::ACTION_ADD, data)); | 104 FROM_HERE, syncer::SyncChange::ACTION_ADD, data)); |
105 } | 105 } |
106 | 106 |
107 #if defined(OS_ANDROID) | 107 #if defined(OS_ANDROID) |
108 std::string sync_machine_tag(BuildMachineTag(delegate_->GetCacheGuid())); | 108 std::string sync_machine_tag(BuildMachineTag( |
| 109 delegate_->GetLocalSyncCacheGUID())); |
109 if (current_machine_tag_.compare(sync_machine_tag) != 0) | 110 if (current_machine_tag_.compare(sync_machine_tag) != 0) |
110 DeleteForeignSession(sync_machine_tag, &new_changes); | 111 DeleteForeignSessionInternal(sync_machine_tag, &new_changes); |
111 #endif | 112 #endif |
112 | 113 |
113 // Check if anything has changed on the local client side. | 114 // Check if anything has changed on the local client side. |
114 AssociateWindows(RELOAD_TABS, &new_changes); | 115 AssociateWindows(RELOAD_TABS, &new_changes); |
115 | 116 |
116 merge_result.set_error( | 117 merge_result.set_error( |
117 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); | 118 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); |
118 return merge_result; | 119 return merge_result; |
119 } | 120 } |
120 | 121 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // static. | 340 // static. |
340 bool SessionsSyncManager::ShouldSyncWindow( | 341 bool SessionsSyncManager::ShouldSyncWindow( |
341 const SyncedWindowDelegate* window) { | 342 const SyncedWindowDelegate* window) { |
342 if (window->IsApp()) | 343 if (window->IsApp()) |
343 return false; | 344 return false; |
344 return window->IsTypeTabbed() || window->IsTypePopup(); | 345 return window->IsTypeTabbed() || window->IsTypePopup(); |
345 } | 346 } |
346 | 347 |
347 void SessionsSyncManager::ForwardRelevantFaviconUpdatesToFaviconCache( | 348 void SessionsSyncManager::ForwardRelevantFaviconUpdatesToFaviconCache( |
348 const std::set<GURL>& updated_favicon_page_urls) { | 349 const std::set<GURL>& updated_favicon_page_urls) { |
349 NOTIMPLEMENTED() << | 350 // TODO(zea): consider a separate container for tabs with outstanding favicon |
350 "TODO(tim): SessionModelAssociator::FaviconsUpdated equivalent."; | 351 // loads so we don't have to iterate through all tabs comparing urls. |
| 352 for (std::set<GURL>::const_iterator i = updated_favicon_page_urls.begin(); |
| 353 i != updated_favicon_page_urls.end(); ++i) { |
| 354 for (TabLinksMap::iterator tab_iter = local_tab_map_.begin(); |
| 355 tab_iter != local_tab_map_.end(); |
| 356 ++tab_iter) { |
| 357 if (tab_iter->second->url() == *i) |
| 358 favicon_cache_.OnPageFaviconUpdated(*i); |
| 359 } |
| 360 } |
351 } | 361 } |
352 | 362 |
353 void SessionsSyncManager::StopSyncing(syncer::ModelType type) { | 363 void SessionsSyncManager::StopSyncing(syncer::ModelType type) { |
354 NOTIMPLEMENTED(); | 364 NOTIMPLEMENTED(); |
355 } | 365 } |
356 | 366 |
357 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( | 367 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( |
358 syncer::ModelType type) const { | 368 syncer::ModelType type) const { |
359 NOTIMPLEMENTED(); | 369 NOTIMPLEMENTED(); |
360 return syncer::SyncDataList(); | 370 return syncer::SyncDataList(); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 foreign_session->modified_time = modification_time; | 554 foreign_session->modified_time = modification_time; |
545 } else { | 555 } else { |
546 LOG(WARNING) << "Ignoring foreign session node with missing header/tab " | 556 LOG(WARNING) << "Ignoring foreign session node with missing header/tab " |
547 << "fields and tag " << foreign_session_tag << "."; | 557 << "fields and tag " << foreign_session_tag << "."; |
548 } | 558 } |
549 } | 559 } |
550 | 560 |
551 void SessionsSyncManager::InitializeCurrentMachineTag() { | 561 void SessionsSyncManager::InitializeCurrentMachineTag() { |
552 DCHECK(current_machine_tag_.empty()); | 562 DCHECK(current_machine_tag_.empty()); |
553 std::string persisted_guid; | 563 std::string persisted_guid; |
554 persisted_guid = sync_prefs_->GetSyncSessionsGUID(); | 564 persisted_guid = sync_prefs_.GetSyncSessionsGUID(); |
555 if (!persisted_guid.empty()) { | 565 if (!persisted_guid.empty()) { |
556 current_machine_tag_ = persisted_guid; | 566 current_machine_tag_ = persisted_guid; |
557 DVLOG(1) << "Restoring persisted session sync guid: " << persisted_guid; | 567 DVLOG(1) << "Restoring persisted session sync guid: " << persisted_guid; |
558 } else { | 568 } else { |
559 current_machine_tag_ = BuildMachineTag(delegate_->GetCacheGuid()); | 569 current_machine_tag_ = BuildMachineTag(delegate_->GetLocalSyncCacheGUID()); |
560 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; | 570 DVLOG(1) << "Creating session sync guid: " << current_machine_tag_; |
561 sync_prefs_->SetSyncSessionsGUID(current_machine_tag_); | 571 sync_prefs_.SetSyncSessionsGUID(current_machine_tag_); |
562 } | 572 } |
563 | 573 |
564 local_tab_pool_.SetMachineTag(current_machine_tag_); | 574 local_tab_pool_.SetMachineTag(current_machine_tag_); |
565 } | 575 } |
566 | 576 |
567 // static | 577 // static |
568 void SessionsSyncManager::PopulateSessionHeaderFromSpecifics( | 578 void SessionsSyncManager::PopulateSessionHeaderFromSpecifics( |
569 const sync_pb::SessionHeader& header_specifics, | 579 const sync_pb::SessionHeader& header_specifics, |
570 base::Time mtime, | 580 base::Time mtime, |
571 SyncedSession* session_header) { | 581 SyncedSession* session_header) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 656 } |
647 } | 657 } |
648 } | 658 } |
649 | 659 |
650 bool SessionsSyncManager::GetSyncedFaviconForPageURL( | 660 bool SessionsSyncManager::GetSyncedFaviconForPageURL( |
651 const std::string& page_url, | 661 const std::string& page_url, |
652 scoped_refptr<base::RefCountedMemory>* favicon_png) const { | 662 scoped_refptr<base::RefCountedMemory>* favicon_png) const { |
653 return favicon_cache_.GetSyncedFaviconForPageURL(GURL(page_url), favicon_png); | 663 return favicon_cache_.GetSyncedFaviconForPageURL(GURL(page_url), favicon_png); |
654 } | 664 } |
655 | 665 |
656 void SessionsSyncManager::DeleteForeignSession( | 666 void SessionsSyncManager::DeleteForeignSession(const std::string& tag) { |
| 667 syncer::SyncChangeList changes; |
| 668 DeleteForeignSessionInternal(tag, &changes); |
| 669 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 670 } |
| 671 |
| 672 void SessionsSyncManager::DeleteForeignSessionInternal( |
657 const std::string& tag, syncer::SyncChangeList* change_output) { | 673 const std::string& tag, syncer::SyncChangeList* change_output) { |
658 if (tag == current_machine_tag()) { | 674 if (tag == current_machine_tag()) { |
659 LOG(ERROR) << "Attempting to delete local session. This is not currently " | 675 LOG(ERROR) << "Attempting to delete local session. This is not currently " |
660 << "supported."; | 676 << "supported."; |
661 return; | 677 return; |
662 } | 678 } |
663 | 679 |
664 std::set<int> tab_node_ids_to_delete; | 680 std::set<int> tab_node_ids_to_delete; |
665 session_tracker_.LookupTabNodeIds(tag, &tab_node_ids_to_delete); | 681 session_tracker_.LookupTabNodeIds(tag, &tab_node_ids_to_delete); |
666 if (!DisassociateForeignSession(tag)) { | 682 if (!DisassociateForeignSession(tag)) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 const int pending_index = tab_delegate.GetPendingEntryIndex(); | 731 const int pending_index = tab_delegate.GetPendingEntryIndex(); |
716 const NavigationEntry* current_entry = | 732 const NavigationEntry* current_entry = |
717 (current_index == pending_index) ? | 733 (current_index == pending_index) ? |
718 tab_delegate.GetPendingEntry() : | 734 tab_delegate.GetPendingEntry() : |
719 tab_delegate.GetEntryAtIndex(current_index); | 735 tab_delegate.GetEntryAtIndex(current_index); |
720 return (current_entry->GetFavicon().valid ? | 736 return (current_entry->GetFavicon().valid ? |
721 current_entry->GetFavicon().url : | 737 current_entry->GetFavicon().url : |
722 GURL()); | 738 GURL()); |
723 } | 739 } |
724 | 740 |
| 741 bool SessionsSyncManager::GetForeignSession( |
| 742 const std::string& tag, |
| 743 std::vector<const SessionWindow*>* windows) { |
| 744 return session_tracker_.LookupSessionWindows(tag, windows); |
| 745 } |
| 746 |
| 747 bool SessionsSyncManager::GetForeignTab( |
| 748 const std::string& tag, |
| 749 const SessionID::id_type tab_id, |
| 750 const SessionTab** tab) { |
| 751 const SessionTab* synced_tab = NULL; |
| 752 bool success = session_tracker_.LookupSessionTab(tag, |
| 753 tab_id, |
| 754 &synced_tab); |
| 755 if (success) |
| 756 *tab = synced_tab; |
| 757 return success; |
| 758 } |
| 759 |
725 void SessionsSyncManager::LocalTabDelegateToSpecifics( | 760 void SessionsSyncManager::LocalTabDelegateToSpecifics( |
726 const SyncedTabDelegate& tab_delegate, | 761 const SyncedTabDelegate& tab_delegate, |
727 sync_pb::SessionSpecifics* specifics) { | 762 sync_pb::SessionSpecifics* specifics) { |
728 SessionTab* session_tab = NULL; | 763 SessionTab* session_tab = NULL; |
729 session_tab = | 764 session_tab = |
730 session_tracker_.GetTab(current_machine_tag(), | 765 session_tracker_.GetTab(current_machine_tag(), |
731 tab_delegate.GetSessionId(), | 766 tab_delegate.GetSessionId(), |
732 tab_delegate.GetSyncId()); | 767 tab_delegate.GetSyncId()); |
733 SetSessionTabFromDelegate(tab_delegate, base::Time::Now(), session_tab); | 768 SetSessionTabFromDelegate(tab_delegate, base::Time::Now(), session_tab); |
734 sync_pb::SessionTab tab_s = session_tab->ToSyncData(); | 769 sync_pb::SessionTab tab_s = session_tab->ToSyncData(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 SerializedNavigationEntry::FromNavigationEntry( | 861 SerializedNavigationEntry::FromNavigationEntry( |
827 i + offset, *blocked_navigations[i])); | 862 i + offset, *blocked_navigations[i])); |
828 session_tab->navigations.back().set_blocked_state( | 863 session_tab->navigations.back().set_blocked_state( |
829 SerializedNavigationEntry::STATE_BLOCKED); | 864 SerializedNavigationEntry::STATE_BLOCKED); |
830 // TODO(bauerb): Add categories | 865 // TODO(bauerb): Add categories |
831 } | 866 } |
832 } | 867 } |
833 session_tab->session_storage_persistent_id.clear(); | 868 session_tab->session_storage_persistent_id.clear(); |
834 } | 869 } |
835 | 870 |
| 871 |
| 872 FaviconCache* SessionsSyncManager::GetFaviconCache() { |
| 873 return &favicon_cache_; |
| 874 } |
| 875 |
836 }; // namespace browser_sync | 876 }; // namespace browser_sync |
OLD | NEW |