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

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: Created 7 years, 1 month 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<LocalEventRouter> 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
50 SessionsSyncManager::~SessionsSyncManager() { 56 SessionsSyncManager::~SessionsSyncManager() {
51 } 57 }
52 58
53 // Returns the GUID-based string that should be used for 59 // Returns the GUID-based string that should be used for
54 // |SessionsSyncManager::current_machine_tag_|. 60 // |SessionsSyncManager::current_machine_tag_|.
55 static std::string BuildMachineTag(const std::string& cache_guid) { 61 static std::string BuildMachineTag(const std::string& cache_guid) {
56 std::string machine_tag = "session_sync"; 62 std::string machine_tag = "session_sync";
57 machine_tag.append(cache_guid); 63 machine_tag.append(cache_guid);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 delegate_->GetLocalSyncCacheGUID())); 115 delegate_->GetLocalSyncCacheGUID()));
110 if (current_machine_tag_.compare(sync_machine_tag) != 0) 116 if (current_machine_tag_.compare(sync_machine_tag) != 0)
111 DeleteForeignSessionInternal(sync_machine_tag, &new_changes); 117 DeleteForeignSessionInternal(sync_machine_tag, &new_changes);
112 #endif 118 #endif
113 119
114 // Check if anything has changed on the local client side. 120 // Check if anything has changed on the local client side.
115 AssociateWindows(RELOAD_TABS, &new_changes); 121 AssociateWindows(RELOAD_TABS, &new_changes);
116 122
117 merge_result.set_error( 123 merge_result.set_error(
118 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); 124 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes));
125
126 local_event_router_->StartRoutingTo(this);
119 return merge_result; 127 return merge_result;
120 } 128 }
121 129
122 void SessionsSyncManager::AssociateWindows( 130 void SessionsSyncManager::AssociateWindows(
123 ReloadTabsOption option, 131 ReloadTabsOption option,
124 syncer::SyncChangeList* change_output) { 132 syncer::SyncChangeList* change_output) {
125 const std::string local_tag = current_machine_tag(); 133 const std::string local_tag = current_machine_tag();
126 sync_pb::SessionSpecifics specifics; 134 sync_pb::SessionSpecifics specifics;
127 specifics.set_session_tag(local_tag); 135 specifics.set_session_tag(local_tag);
128 sync_pb::SessionHeader* header_s = specifics.mutable_header(); 136 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); 294 const GURL new_url = GetCurrentVirtualURL(*tab);
287 if (new_url != tab_link->url()) { 295 if (new_url != tab_link->url()) {
288 tab_link->set_url(new_url); 296 tab_link->set_url(new_url);
289 favicon_cache_.OnFaviconVisited(new_url, GetCurrentFaviconURL(*tab)); 297 favicon_cache_.OnFaviconVisited(new_url, GetCurrentFaviconURL(*tab));
290 } 298 }
291 299
292 session_tracker_.GetSession(current_machine_tag())->modified_time = 300 session_tracker_.GetSession(current_machine_tag())->modified_time =
293 base::Time::Now(); 301 base::Time::Now();
294 } 302 }
295 303
296 void SessionsSyncManager::OnLocalTabModified( 304 void SessionsSyncManager::OnLocalTabModified(SyncedTabDelegate* modified_tab) {
297 const SyncedTabDelegate& modified_tab, syncer::SyncError* error) { 305 const content::NavigationEntry* entry = modified_tab->GetActiveEntry();
298 NOTIMPLEMENTED() << "TODO(tim): SessionModelAssociator::Observe equivalent."; 306 if (!modified_tab->IsBeingDestroyed() &&
307 entry &&
308 entry->GetVirtualURL().is_valid() &&
309 entry->GetVirtualURL().spec() == kNTPOpenTabSyncURL) {
310 DVLOG(1) << "Triggering sync refresh for sessions datatype.";
311 const syncer::ModelTypeSet types(syncer::SESSIONS);
312 content::NotificationService::current()->Notify(
313 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
314 content::Source<Profile>(profile_),
315 content::Details<const syncer::ModelTypeSet>(&types));
316 }
317
318 syncer::SyncChangeList changes;
319 // Associate tabs first so the synced session tracker is aware of them.
320 AssociateTab(modified_tab, &changes);
321 // Note, we always associate windows because it's possible a tab became
322 // "interesting" by going to a valid URL, in which case it needs to be added
323 // to the window's tab information.
324 AssociateWindows(DONT_RELOAD_TABS, &changes);
325
326 syncer::SyncError error =
327 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
328 if (error.IsSet()) {
Nicolas Zea 2013/11/21 02:34:52 not necessarily for this patch, but I suspect trig
tim (not reviewing) 2013/11/21 21:38:59 Hm. Right. Well, in the old code, we'd re-associat
Nicolas Zea 2013/11/22 23:34:51 Yeah, the old version was kind of violating some l
329 // Note that if we fail to associate, it means something has gone wrong,
330 // such as our local session being deleted, so we disassociate and
331 // associate again.
332 NOTIMPLEMENTED() << "TODO(tim): Bug 98892. Full re-association.";
333 }
299 } 334 }
300 335
301 void SessionsSyncManager::OnBrowserOpened() { 336 void SessionsSyncManager::OnBrowserOpened() {
302 NOTIMPLEMENTED() << "TODO(tim): SessionModelAssociator::Observe equivalent."; 337 syncer::SyncChangeList changes;
338 AssociateWindows(DONT_RELOAD_TABS, &changes);
339 syncer::SyncError error =
340 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
Nicolas Zea 2013/11/21 02:34:52 nit: fits on one line?
tim (not reviewing) 2013/11/21 21:38:59 nope
341 if (error.IsSet()) {
Nicolas Zea 2013/11/21 02:34:52 nit: remove curly brace
tim (not reviewing) 2013/11/21 21:38:59 I'm with you, although as a rule of thumb we try t
Nicolas Zea 2013/11/22 23:34:51 I think we can probably ignore the error result. S
342 NOTIMPLEMENTED() << "TODO(tim): Bug 98892. Full re-association.";
343 }
344 }
345
346 void SessionsSyncManager::OnFaviconPageUrlsUpdated(
347 const std::set<GURL>& updated_favicon_page_urls) {
348 // TODO(zea): consider a separate container for tabs with outstanding favicon
349 // loads so we don't have to iterate through all tabs comparing urls.
350 for (std::set<GURL>::const_iterator i = updated_favicon_page_urls.begin();
351 i != updated_favicon_page_urls.end(); ++i) {
352 for (TabLinksMap::iterator tab_iter = local_tab_map_.begin();
353 tab_iter != local_tab_map_.end();
354 ++tab_iter) {
355 if (tab_iter->second->url() == *i)
356 favicon_cache_.OnPageFaviconUpdated(*i);
357 }
358 }
303 } 359 }
304 360
305 bool SessionsSyncManager::ShouldSyncTab(const SyncedTabDelegate& tab) const { 361 bool SessionsSyncManager::ShouldSyncTab(const SyncedTabDelegate& tab) const {
306 if (tab.profile() != profile_) 362 if (tab.profile() != profile_)
307 return false; 363 return false;
308 364
309 if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId( 365 if (SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
310 tab.GetWindowId()) == NULL) { 366 tab.GetWindowId()) == NULL) {
311 return false; 367 return false;
312 } 368 }
(...skipping 25 matching lines...) Expand all
338 } 394 }
339 395
340 // static. 396 // static.
341 bool SessionsSyncManager::ShouldSyncWindow( 397 bool SessionsSyncManager::ShouldSyncWindow(
342 const SyncedWindowDelegate* window) { 398 const SyncedWindowDelegate* window) {
343 if (window->IsApp()) 399 if (window->IsApp())
344 return false; 400 return false;
345 return window->IsTypeTabbed() || window->IsTypePopup(); 401 return window->IsTypeTabbed() || window->IsTypePopup();
346 } 402 }
347 403
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) { 404 void SessionsSyncManager::StopSyncing(syncer::ModelType type) {
364 NOTIMPLEMENTED(); 405 NOTIMPLEMENTED();
365 } 406 }
366 407
367 syncer::SyncDataList SessionsSyncManager::GetAllSyncData( 408 syncer::SyncDataList SessionsSyncManager::GetAllSyncData(
368 syncer::ModelType type) const { 409 syncer::ModelType type) const {
369 NOTIMPLEMENTED(); 410 NOTIMPLEMENTED();
370 return syncer::SyncDataList(); 411 return syncer::SyncDataList();
371 } 412 }
372 413
(...skipping 16 matching lines...) Expand all
389 it->sync_data().GetSpecifics().session(); 430 it->sync_data().GetSpecifics().session();
390 switch (it->change_type()) { 431 switch (it->change_type()) {
391 case syncer::SyncChange::ACTION_DELETE: 432 case syncer::SyncChange::ACTION_DELETE:
392 // Deletions are all or nothing (since we only ever delete entire 433 // 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, 434 // sessions). Therefore we don't care if it's a tab node or meta node,
394 // and just ensure we've disassociated. 435 // and just ensure we've disassociated.
395 if (current_machine_tag() == session.session_tag()) { 436 if (current_machine_tag() == session.session_tag()) {
396 // Another client has attempted to delete our local data (possibly by 437 // Another client has attempted to delete our local data (possibly by
397 // error or a clock is inaccurate). Just ignore the deletion for now 438 // error or a clock is inaccurate). Just ignore the deletion for now
398 // to avoid any possible ping-pong delete/reassociate sequence. 439 // to avoid any possible ping-pong delete/reassociate sequence.
440 // TODO(tim): Bug 98892. This corrupts TabNodePool. Perform full
441 // re-association.
399 LOG(WARNING) << "Local session data deleted. Ignoring until next " 442 LOG(WARNING) << "Local session data deleted. Ignoring until next "
400 << "local navigation event."; 443 << "local navigation event.";
401 } else if (session.has_header()) { 444 } else if (session.has_header()) {
402 // Disassociate only when header node is deleted. For tab node 445 // Disassociate only when header node is deleted. For tab node
403 // deletions, the header node will be updated and foreign tab will 446 // deletions, the header node will be updated and foreign tab will
404 // get deleted. 447 // get deleted.
405 DisassociateForeignSession(session.session_tag()); 448 DisassociateForeignSession(session.session_tag());
406 } 449 }
407 continue; 450 continue;
408 case syncer::SyncChange::ACTION_ADD: 451 case syncer::SyncChange::ACTION_ADD:
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 SerializedNavigationEntry::FromNavigationEntry( 904 SerializedNavigationEntry::FromNavigationEntry(
862 i + offset, *blocked_navigations[i])); 905 i + offset, *blocked_navigations[i]));
863 session_tab->navigations.back().set_blocked_state( 906 session_tab->navigations.back().set_blocked_state(
864 SerializedNavigationEntry::STATE_BLOCKED); 907 SerializedNavigationEntry::STATE_BLOCKED);
865 // TODO(bauerb): Add categories 908 // TODO(bauerb): Add categories
866 } 909 }
867 } 910 }
868 session_tab->session_storage_persistent_id.clear(); 911 session_tab->session_storage_persistent_id.clear();
869 } 912 }
870 913
871
872 FaviconCache* SessionsSyncManager::GetFaviconCache() { 914 FaviconCache* SessionsSyncManager::GetFaviconCache() {
873 return &favicon_cache_; 915 return &favicon_cache_;
874 } 916 }
875 917
876 }; // namespace browser_sync 918 }; // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698