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

Side by Side Diff: chrome/browser/sync/sessions2/sessions_sync_manager.cc

Issue 79973002: sync: Route local sessions events to SessionsSyncManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Richard's review Created 7 years 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 | Annotate | Revision Log
OLDNEW
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
(...skipping 19 matching lines...) Expand all
30 30
31 namespace browser_sync { 31 namespace browser_sync {
32 32
33 // Maximum number of favicons to sync. 33 // Maximum number of favicons to sync.
34 // TODO(zea): pull this from the server. 34 // TODO(zea): pull this from the server.
35 static const int kMaxSyncFavicons = 200; 35 static const int kMaxSyncFavicons = 200;
36 36
37 // 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.
38 static const int kMaxSyncNavigationCount = 6; 38 static const int kMaxSyncNavigationCount = 6;
39 39
40 // The URL at which the set of synced tabs is displayed. We treat it differently
41 // from all other URL's as accessing it triggers a sync refresh of Sessions.
42 static const char kNTPOpenTabSyncURL[] = "chrome://newtab/#open_tabs";
43
40 SessionsSyncManager::SessionsSyncManager( 44 SessionsSyncManager::SessionsSyncManager(
41 Profile* profile, 45 Profile* profile,
42 SyncInternalApiDelegate* delegate) 46 SyncInternalApiDelegate* delegate,
47 scoped_ptr<LocalSessionEventRouter> router)
43 : favicon_cache_(profile, kMaxSyncFavicons), 48 : favicon_cache_(profile, kMaxSyncFavicons),
44 sync_prefs_(profile->GetPrefs()), 49 sync_prefs_(profile->GetPrefs()),
45 profile_(profile), 50 profile_(profile),
46 delegate_(delegate), 51 delegate_(delegate),
47 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID) { 52 local_session_header_node_id_(TabNodePool2::kInvalidTabNodeID),
53 local_event_router_(router.Pass()) {
48 } 54 }
49 55
56 LocalSessionEventRouter::~LocalSessionEventRouter() {}
57
50 SessionsSyncManager::~SessionsSyncManager() { 58 SessionsSyncManager::~SessionsSyncManager() {
51 } 59 }
52 60
53 // Returns the GUID-based string that should be used for 61 // Returns the GUID-based string that should be used for
54 // |SessionsSyncManager::current_machine_tag_|. 62 // |SessionsSyncManager::current_machine_tag_|.
55 static std::string BuildMachineTag(const std::string& cache_guid) { 63 static std::string BuildMachineTag(const std::string& cache_guid) {
56 std::string machine_tag = "session_sync"; 64 std::string machine_tag = "session_sync";
57 machine_tag.append(cache_guid); 65 machine_tag.append(cache_guid);
58 return machine_tag; 66 return machine_tag;
59 } 67 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 delegate_->GetLocalSyncCacheGUID())); 117 delegate_->GetLocalSyncCacheGUID()));
110 if (current_machine_tag_.compare(sync_machine_tag) != 0) 118 if (current_machine_tag_.compare(sync_machine_tag) != 0)
111 DeleteForeignSessionInternal(sync_machine_tag, &new_changes); 119 DeleteForeignSessionInternal(sync_machine_tag, &new_changes);
112 #endif 120 #endif
113 121
114 // Check if anything has changed on the local client side. 122 // Check if anything has changed on the local client side.
115 AssociateWindows(RELOAD_TABS, &new_changes); 123 AssociateWindows(RELOAD_TABS, &new_changes);
116 124
117 merge_result.set_error( 125 merge_result.set_error(
118 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); 126 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes));
127
128 local_event_router_->StartRoutingTo(this);
119 return merge_result; 129 return merge_result;
120 } 130 }
121 131
122 void SessionsSyncManager::AssociateWindows( 132 void SessionsSyncManager::AssociateWindows(
123 ReloadTabsOption option, 133 ReloadTabsOption option,
124 syncer::SyncChangeList* change_output) { 134 syncer::SyncChangeList* change_output) {
125 const std::string local_tag = current_machine_tag(); 135 const std::string local_tag = current_machine_tag();
126 sync_pb::SessionSpecifics specifics; 136 sync_pb::SessionSpecifics specifics;
127 specifics.set_session_tag(local_tag); 137 specifics.set_session_tag(local_tag);
128 sync_pb::SessionHeader* header_s = specifics.mutable_header(); 138 sync_pb::SessionHeader* header_s = specifics.mutable_header();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 const GURL new_url = GetCurrentVirtualURL(*tab); 296 const GURL new_url = GetCurrentVirtualURL(*tab);
287 if (new_url != tab_link->url()) { 297 if (new_url != tab_link->url()) {
288 tab_link->set_url(new_url); 298 tab_link->set_url(new_url);
289 favicon_cache_.OnFaviconVisited(new_url, GetCurrentFaviconURL(*tab)); 299 favicon_cache_.OnFaviconVisited(new_url, GetCurrentFaviconURL(*tab));
290 } 300 }
291 301
292 session_tracker_.GetSession(current_machine_tag())->modified_time = 302 session_tracker_.GetSession(current_machine_tag())->modified_time =
293 base::Time::Now(); 303 base::Time::Now();
294 } 304 }
295 305
296 void SessionsSyncManager::OnLocalTabModified( 306 void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) {
297 const SyncedTabDelegate& modified_tab, syncer::SyncError* error) { 307 const content::NavigationEntry* entry = modified_tab->GetActiveEntry();
298 NOTIMPLEMENTED() << "TODO(tim): SessionModelAssociator::Observe equivalent."; 308 if (!modified_tab->IsBeingDestroyed() &&
309 entry &&
310 entry->GetVirtualURL().is_valid() &&
311 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) {
312 DVLOG(1) << "Triggering sync refresh for sessions datatype.";
313 const syncer::ModelTypeSet types(syncer::SESSIONS);
314 content::NotificationService::current()->Notify(
315 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
316 content::Source<Profile>(profile_),
317 content::Details<const syncer::ModelTypeSet>(&types));
318 }
319
320 syncer::SyncChangeList changes;
321 // Associate tabs first so the synced session tracker is aware of them.
322 AssociateTab(modified_tab, &changes);
323 // Note, we always associate windows because it's possible a tab became
324 // "interesting" by going to a valid URL, in which case it needs to be added
325 // to the window's tab information.
326 AssociateWindows(DONT_RELOAD_TABS, &changes);
327 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
299 } 328 }
300 329
301 void SessionsSyncManager::OnBrowserOpened() { 330 void SessionsSyncManager::OnFaviconPageUrlsUpdated(
302 NOTIMPLEMENTED() << "TODO(tim): SessionModelAssociator::Observe equivalent."; 331 const std::set<GURL>& updated_favicon_page_urls) {
332 // TODO(zea): consider a separate container for tabs with outstanding favicon
333 // loads so we don't have to iterate through all tabs comparing urls.
334 for (std::set<GURL>::const_iterator i = updated_favicon_page_urls.begin();
335 i != updated_favicon_page_urls.end(); ++i) {
336 for (TabLinksMap::iterator tab_iter = local_tab_map_.begin();
337 tab_iter != local_tab_map_.end();
338 ++tab_iter) {
339 if (tab_iter->second->url() == *i)
340 favicon_cache_.OnPageFaviconUpdated(*i);
341 }
342 }
303 } 343 }
304 344
305 bool SessionsSyncManager::ShouldSyncTab(const SyncedTabDelegate& tab) const { 345 bool SessionsSyncManager::ShouldSyncTab(const SyncedTabDelegate& tab) const {
306 if (tab.profile() != profile_) 346 if (tab.profile() != profile_)
307 return false; 347 return false;
308 348
309 if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId( 349 if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
310 tab.GetWindowId()) == NULL) { 350 tab.GetWindowId()) == NULL) {
311 return false; 351 return false;
312 } 352 }
(...skipping 25 matching lines...) Expand all
338 } 378 }
339 379
340 // static. 380 // static.
341 bool SessionsSyncManager::ShouldSyncWindow( 381 bool SessionsSyncManager::ShouldSyncWindow(
342 const SyncedWindowDelegate* window) { 382 const SyncedWindowDelegate* window) {
343 if (window->IsApp()) 383 if (window->IsApp())
344 return false; 384 return false;
345 return window->IsTypeTabbed() || window->IsTypePopup(); 385 return window->IsTypeTabbed() || window->IsTypePopup();
346 } 386 }
347 387
348 void SessionsSyncManager::ForwardRelevantFaviconUpdatesToFaviconCache(
349 const std::set<GURL>& updated_favicon_page_urls) {
350 // TODO(zea): consider a separate container for tabs with outstanding favicon
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 }
361 }
362
363 void SessionsSyncManager::StopSyncing(syncer::ModelType type) { 388 void SessionsSyncManager::StopSyncing(syncer::ModelType type) {
364 NOTIMPLEMENTED(); 389 NOTIMPLEMENTED();
365 } 390 }
366 391
367 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( 392 syncer::SyncDataList SessionsSyncManager::GetAllSyncData(
368 syncer::ModelType type) const { 393 syncer::ModelType type) const {
369 NOTIMPLEMENTED(); 394 NOTIMPLEMENTED();
370 return syncer::SyncDataList(); 395 return syncer::SyncDataList();
371 } 396 }
372 397
(...skipping 16 matching lines...) Expand all
389 it->sync_data().GetSpecifics().session(); 414 it->sync_data().GetSpecifics().session();
390 switch (it->change_type()) { 415 switch (it->change_type()) {
391 case syncer::SyncChange::ACTION_DELETE: 416 case syncer::SyncChange::ACTION_DELETE:
392 // Deletions are all or nothing (since we only ever delete entire 417 // Deletions are all or nothing (since we only ever delete entire
393 // sessions). Therefore we don't care if it's a tab node or meta node, 418 // sessions). Therefore we don't care if it's a tab node or meta node,
394 // and just ensure we've disassociated. 419 // and just ensure we've disassociated.
395 if (current_machine_tag() == session.session_tag()) { 420 if (current_machine_tag() == session.session_tag()) {
396 // Another client has attempted to delete our local data (possibly by 421 // Another client has attempted to delete our local data (possibly by
397 // error or a clock is inaccurate). Just ignore the deletion for now 422 // error or a clock is inaccurate). Just ignore the deletion for now
398 // to avoid any possible ping-pong delete/reassociate sequence. 423 // to avoid any possible ping-pong delete/reassociate sequence.
424 // TODO(tim): Bug 98892. This corrupts TabNodePool. Perform full
425 // re-association.
399 LOG(WARNING) << "Local session data deleted. Ignoring until next " 426 LOG(WARNING) << "Local session data deleted. Ignoring until next "
400 << "local navigation event."; 427 << "local navigation event.";
401 } else if (session.has_header()) { 428 } else if (session.has_header()) {
402 // Disassociate only when header node is deleted. For tab node 429 // Disassociate only when header node is deleted. For tab node
403 // deletions, the header node will be updated and foreign tab will 430 // deletions, the header node will be updated and foreign tab will
404 // get deleted. 431 // get deleted.
405 DisassociateForeignSession(session.session_tag()); 432 DisassociateForeignSession(session.session_tag());
406 } 433 }
407 continue; 434 continue;
408 case syncer::SyncChange::ACTION_ADD: 435 case syncer::SyncChange::ACTION_ADD:
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 SerializedNavigationEntry::FromNavigationEntry( 888 SerializedNavigationEntry::FromNavigationEntry(
862 i + offset, *blocked_navigations[i])); 889 i + offset, *blocked_navigations[i]));
863 session_tab->navigations.back().set_blocked_state( 890 session_tab->navigations.back().set_blocked_state(
864 SerializedNavigationEntry::STATE_BLOCKED); 891 SerializedNavigationEntry::STATE_BLOCKED);
865 // TODO(bauerb): Add categories 892 // TODO(bauerb): Add categories
866 } 893 }
867 } 894 }
868 session_tab->session_storage_persistent_id.clear(); 895 session_tab->session_storage_persistent_id.clear();
869 } 896 }
870 897
871
872 FaviconCache* SessionsSyncManager::GetFaviconCache() { 898 FaviconCache* SessionsSyncManager::GetFaviconCache() {
873 return &favicon_cache_; 899 return &favicon_cache_;
874 } 900 }
875 901
876 }; // namespace browser_sync 902 }; // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698