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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator.cc

Issue 10125002: [Sync] Add per-navigation timestamps/unique ids to tab sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 8 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/glue/session_model_associator.h" 5 #include "chrome/browser/sync/glue/session_model_associator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
32 #include "sync/internal_api/read_node.h" 32 #include "sync/internal_api/read_node.h"
33 #include "sync/internal_api/read_transaction.h" 33 #include "sync/internal_api/read_transaction.h"
34 #include "sync/internal_api/write_node.h" 34 #include "sync/internal_api/write_node.h"
35 #include "sync/internal_api/write_transaction.h" 35 #include "sync/internal_api/write_transaction.h"
36 #include "sync/protocol/session_specifics.pb.h" 36 #include "sync/protocol/session_specifics.pb.h"
37 #include "sync/syncable/model_type.h" 37 #include "sync/syncable/model_type.h"
38 #include "sync/syncable/model_type_payload_map.h" 38 #include "sync/syncable/model_type_payload_map.h"
39 #include "sync/syncable/syncable.h" 39 #include "sync/syncable/syncable.h"
40 #include "sync/util/get_session_name.h" 40 #include "sync/util/get_session_name.h"
41 #include "sync/util/time.h"
41 #if defined(OS_LINUX) 42 #if defined(OS_LINUX)
42 #include "base/linux_util.h" 43 #include "base/linux_util.h"
43 #elif defined(OS_WIN) 44 #elif defined(OS_WIN)
44 #include <windows.h> 45 #include <windows.h>
45 #elif defined(OS_ANDROID) 46 #elif defined(OS_ANDROID)
46 #include "sync/util/session_utils_android.h" 47 #include "sync/util/session_utils_android.h"
47 #endif 48 #endif
48 49
49 using content::BrowserThread; 50 using content::BrowserThread;
50 using content::NavigationEntry; 51 using content::NavigationEntry;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 window_s.set_browser_type( 220 window_s.set_browser_type(
220 sync_pb::SessionWindow_BrowserType_TYPE_TABBED); 221 sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
221 } else { 222 } else {
222 window_s.set_browser_type( 223 window_s.set_browser_type(
223 sync_pb::SessionWindow_BrowserType_TYPE_POPUP); 224 sync_pb::SessionWindow_BrowserType_TYPE_POPUP);
224 } 225 }
225 226
226 // Store the order of tabs. 227 // Store the order of tabs.
227 bool found_tabs = false; 228 bool found_tabs = false;
228 for (int j = 0; j < (*i)->GetTabCount(); ++j) { 229 for (int j = 0; j < (*i)->GetTabCount(); ++j) {
229 const SessionTab* tab;
230 SessionID::id_type tab_id = (*i)->GetTabIdAt(j); 230 SessionID::id_type tab_id = (*i)->GetTabIdAt(j);
231 231
232 if (reload_tabs) { 232 if (reload_tabs) {
233 SyncedTabDelegate* tab = (*i)->GetTabAt(j); 233 SyncedTabDelegate* tab = (*i)->GetTabAt(j);
234 // It's possible for GetTabAt to return a null tab if it's not in 234 // It's possible for GetTabAt to return a null tab if it's not in
235 // memory. We can assume this means the tab already existed but hasn't 235 // memory. We can assume this means the tab already existed but hasn't
236 // changed, so no need to reassociate. 236 // changed, so no need to reassociate.
237 if (tab && !AssociateTab(*tab, error)) { 237 if (tab && !AssociateTab(*tab, error)) {
238 // Association failed. Either we need to re-associate, or this is an 238 // Association failed. Either we need to re-associate, or this is an
239 // unrecoverable error. 239 // unrecoverable error.
240 return false; 240 return false;
241 } 241 }
242 } 242 }
243 243
244 // If the tab is valid, it would have been added to the tracker either 244 // If the tab is valid, it would have been added to the tracker either
245 // by the above AssociateTab call (at association time), or by the 245 // by the above AssociateTab call (at association time), or by the
246 // change processor calling AssociateTab for all modified tabs. 246 // change processor calling AssociateTab for all modified tabs.
247 // Therefore, we can key whether this window has valid tabs based on 247 // Therefore, we can key whether this window has valid tabs based on
248 // the tab's presence in the tracker. 248 // the tab's presence in the tracker.
249 const SyncedSessionTab* tab;
249 if (synced_session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) { 250 if (synced_session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) {
250 found_tabs = true; 251 found_tabs = true;
251 window_s.add_tab(tab_id); 252 window_s.add_tab(tab_id);
252 } 253 }
253 } 254 }
254 // Only add a window if it contains valid tabs. 255 // Only add a window if it contains valid tabs.
255 if (found_tabs) { 256 if (found_tabs) {
256 sync_pb::SessionWindow* header_window = header_s->add_window(); 257 sync_pb::SessionWindow* header_window = header_s->add_window();
257 *header_window = window_s; 258 *header_window = window_s;
258 259
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 bool SessionModelAssociator::WriteTabContentsToSyncModel(TabLink* tab_link, 365 bool SessionModelAssociator::WriteTabContentsToSyncModel(TabLink* tab_link,
365 SyncError* error) { 366 SyncError* error) {
366 DCHECK(CalledOnValidThread()); 367 DCHECK(CalledOnValidThread());
367 const SyncedTabDelegate& tab = *(tab_link->tab()); 368 const SyncedTabDelegate& tab = *(tab_link->tab());
368 const SyncedWindowDelegate& window = 369 const SyncedWindowDelegate& window =
369 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( 370 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
370 tab.GetWindowId()); 371 tab.GetWindowId());
371 int64 sync_id = tab_link->sync_id(); 372 int64 sync_id = tab_link->sync_id();
372 GURL old_tab_url = tab_link->url(); 373 GURL old_tab_url = tab_link->url();
373 374
375 // Load the last stored version of this tab so we can compare changes. If this
376 // is a new tab, session_tab will be a blank/newly created SessionTab object.
377 SyncedSessionTab* session_tab =
378 synced_session_tracker_.GetTab(GetCurrentMachineTag(),
379 tab.GetSessionId());
380
374 // We build a clean session specifics directly from the tab data. 381 // We build a clean session specifics directly from the tab data.
375 sync_pb::SessionSpecifics session_s; 382 sync_pb::SessionSpecifics session_s;
376 session_s.set_session_tag(GetCurrentMachineTag()); 383 session_s.set_session_tag(GetCurrentMachineTag());
377 sync_pb::SessionTab* tab_s = session_s.mutable_tab(); 384 sync_pb::SessionTab* tab_s = session_s.mutable_tab();
378 SessionID::id_type tab_id = tab.GetSessionId(); 385
379 tab_s->set_tab_id(tab_id); 386 GURL new_url;
380 tab_s->set_window_id(tab.GetWindowId()); 387 AssociateTabContents(window, tab, session_tab, tab_s, &new_url);
381 const int current_index = tab.GetCurrentEntryIndex(); 388
382 const int min_index = std::max(0, 389 // Trigger the favicon load if needed. We do this before opening the write
383 current_index - kMaxSyncNavigationCount); 390 // transaction to avoid jank.
384 const int max_index = std::min(current_index + kMaxSyncNavigationCount, 391 tab_link->set_url(new_url);
385 tab.GetEntryCount()); 392 if (new_url != old_tab_url) {
386 const int pending_index = tab.GetPendingEntryIndex(); 393 LoadFaviconForTab(tab_link);
387 tab_s->set_pinned(window.IsTabPinned(&tab));
388 if (tab.HasExtensionAppId()) {
389 tab_s->set_extension_app_id(tab.GetExtensionAppId());
390 } 394 }
391 tab_s->mutable_navigation()->Clear();
392 for (int i = min_index; i < max_index; ++i) {
393 const NavigationEntry* entry = (i == pending_index) ?
394 tab.GetPendingEntry() : tab.GetEntryAtIndex(i);
395 DCHECK(entry);
396 if (entry->GetVirtualURL().is_valid()) {
397 if (i == current_index && entry->GetVirtualURL().is_valid()) {
398 tab_link->set_url(entry->GetVirtualURL());
399 DVLOG(1) << "Associating tab " << tab_id << " with sync id " << sync_id
400 << ", url " << entry->GetVirtualURL().spec()
401 << " and title " << entry->GetTitle();
402 }
403 TabNavigation tab_nav;
404 tab_nav.SetFromNavigationEntry(*entry);
405 sync_pb::TabNavigation* nav_s = tab_s->add_navigation();
406 PopulateSessionSpecificsNavigation(&tab_nav, nav_s);
407 }
408 }
409 tab_s->set_current_navigation_index(current_index);
410 395
411 // Convert to a local representation and store in synced session tracker for 396 // Update our last modified time.
412 // bookkeeping purposes.
413 SessionTab* session_tab =
414 synced_session_tracker_.GetTab(GetCurrentMachineTag(),
415 tab_s->tab_id());
416 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = 397 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time =
417 base::Time::Now(); 398 base::Time::Now();
418 PopulateSessionTabFromSpecifics(*tab_s,
419 base::Time::Now(),
420 session_tab);
421
422 // If the url changed, kick off the favicon load for the new url.
423 bool url_changed = false;
424 if (tab_link->url().is_valid() && tab_link->url() != old_tab_url) {
425 url_changed = true;
426 LoadFaviconForTab(tab_link);
427 }
428 399
429 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 400 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
430 sync_api::WriteNode tab_node(&trans); 401 sync_api::WriteNode tab_node(&trans);
431 if (tab_node.InitByIdLookup(sync_id) != sync_api::BaseNode::INIT_OK) { 402 if (tab_node.InitByIdLookup(sync_id) != sync_api::BaseNode::INIT_OK) {
432 if (error) { 403 if (error) {
433 *error = error_handler_->CreateAndUploadError( 404 *error = error_handler_->CreateAndUploadError(
434 FROM_HERE, 405 FROM_HERE,
435 "Failed to look up local tab node", 406 "Failed to look up local tab node",
436 model_type()); 407 model_type());
437 } 408 }
438 return false; 409 return false;
439 } 410 }
440 411
441 // Preserve the existing favicon only if the url didn't change. 412 if (new_url == old_tab_url) {
442 if (!url_changed) { 413 // Load the old specifics and copy over the favicon data if needed.
443 tab_s->set_favicon(tab_node.GetSessionSpecifics().tab().favicon()); 414 // TODO(zea): store local favicons in the |synced_favicons_| map and use
444 tab_s->set_favicon_source( 415 // that instead of reading from sync. This will be necessary to switch to
445 tab_node.GetSessionSpecifics().tab().favicon_source()); 416 // the new api.
446 } // else store the empty favicon data back in. 417 const sync_pb::SessionSpecifics old_specifics =
418 tab_node.GetSessionSpecifics();
419 tab_s->set_favicon(old_specifics.tab().favicon());
420 tab_s->set_favicon_source(old_specifics.tab().favicon_source());
421 }
447 422
448 // Write into the actual sync model. 423 // Write into the actual sync model.
449 tab_node.SetSessionSpecifics(session_s); 424 tab_node.SetSessionSpecifics(session_s);
450 425
451 return true; 426 return true;
452 } 427 }
453 428
429 // Builds |sync_tab| by combining data from |prev_tab| and |new_tab|. Updates
430 // |prev_tab| to reflect the newest version.
431 // Timestamps are chosen from either |prev_tab| or base::Time::Now() based on
432 // the following rules:
433 // 1. If a navigation exists in both |new_tab| and |prev_tab|, as determined
434 // by the unique id, and the navigation didn't just become the current
435 // navigation, we preserve the old timestamp.
436 // 2. If the navigation exists in both but just become the current navigation
437 // (e.g. the user went back in history to this navigation), we update the
438 // timestamp to Now().
439 // 3. All new navigations not present in |prev_tab| have their timestamps set to
440 // Now().
441 void SessionModelAssociator::AssociateTabContents(
442 const SyncedWindowDelegate& window,
443 const SyncedTabDelegate& new_tab,
444 SyncedSessionTab* prev_tab,
445 sync_pb::SessionTab* sync_tab,
446 GURL* new_url) {
447 DCHECK(prev_tab);
448 DCHECK(sync_tab);
449 DCHECK(new_url);
450 SessionID::id_type tab_id = new_tab.GetSessionId();
451 sync_tab->set_tab_id(tab_id);
452 sync_tab->set_window_id(new_tab.GetWindowId());
453 const int current_index = new_tab.GetCurrentEntryIndex();
454 sync_tab->set_current_navigation_index(current_index);
455 const int min_index = std::max(0,
456 current_index - kMaxSyncNavigationCount);
457 const int max_index = std::min(current_index + kMaxSyncNavigationCount,
458 new_tab.GetEntryCount());
459 const int pending_index = new_tab.GetPendingEntryIndex();
460 sync_tab->set_pinned(window.IsTabPinned(&new_tab));
461 if (new_tab.HasExtensionAppId()) {
462 sync_tab->set_extension_app_id(new_tab.GetExtensionAppId());
463 }
464
465 sync_tab->mutable_navigation()->Clear();
466 std::vector<SyncedTabNavigation>::const_iterator prev_nav_iter;
467 for (int i = min_index; i < max_index; ++i) {
468 const NavigationEntry* entry = (i == pending_index) ?
469 new_tab.GetPendingEntry() : new_tab.GetEntryAtIndex(i);
470 DCHECK(entry);
471 if (i == min_index) {
472 // Find the location of the first navigation within the previous list of
473 // navigations. We only need to do this once, as all subsequent
474 // navigations are either contiguous or completely new.
475 for (prev_nav_iter = prev_tab->synced_tab_navigations.begin();
476 prev_nav_iter != prev_tab->synced_tab_navigations.end();
477 ++prev_nav_iter) {
478 if (prev_nav_iter->unique_id() == entry->GetUniqueID())
479 break;
480 }
481 }
482 if (entry->GetVirtualURL().is_valid()) {
483 if (i == current_index) {
484 *new_url = GURL(entry->GetVirtualURL().spec());
485 DVLOG(1) << "Associating local tab " << new_tab.GetSessionId()
486 << " with url " << new_url->spec() << " and title "
487 << entry->GetTitle();
488
489 }
490 sync_pb::TabNavigation* sync_nav = sync_tab->add_navigation();
491 PopulateSessionSpecificsNavigation(*entry, sync_nav);
492
493 // If this navigation is an old one, reuse the old timestamp. Otherwise we
494 // leave the timestamp as the current time.
495 if (prev_nav_iter != prev_tab->synced_tab_navigations.end() &&
496 prev_nav_iter->unique_id() == entry->GetUniqueID()) {
497 // Check that we haven't gone back/foward in the nav stack to this page
498 // (if so, we want to refresh the timestamp).
499 if (!(current_index != prev_tab->current_navigation_index &&
500 current_index == i)) {
501 sync_nav->set_timestamp(TimeToProtoTime(prev_nav_iter->timestamp()));
502 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, "
503 << "reusing old timestamp " << sync_nav->timestamp();
504 }
505 // Even if the user went back in their history, they may have skipped
506 // over navigations, so the subsequent navigation entries may need their
507 // old timestamps preserved.
508 ++prev_nav_iter;
509 }
510 }
511 }
512
513 // Now update our local version with the newest data.
514 PopulateSessionTabFromSpecifics(*sync_tab,
515 base::Time::Now(),
516 prev_tab);
517 }
518
454 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { 519 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) {
455 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 520 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
456 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) 521 if (!command_line.HasSwitch(switches::kSyncTabFavicons))
457 return; 522 return;
458 FaviconService* favicon_service = 523 FaviconService* favicon_service =
459 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); 524 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
460 if (!favicon_service) 525 if (!favicon_service)
461 return; 526 return;
462 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); 527 SessionID::id_type tab_id = tab_link->tab()->GetSessionId();
463 if (tab_link->favicon_load_handle()) { 528 if (tab_link->favicon_load_handle()) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 LoadFaviconForTab(tab_iter->second.get()); 619 LoadFaviconForTab(tab_iter->second.get());
555 } 620 }
556 } 621 }
557 } 622 }
558 } 623 }
559 624
560 // Static 625 // Static
561 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? 626 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well?
562 // See http://crbug.com/67068. 627 // See http://crbug.com/67068.
563 void SessionModelAssociator::PopulateSessionSpecificsNavigation( 628 void SessionModelAssociator::PopulateSessionSpecificsNavigation(
564 const TabNavigation* navigation, 629 const NavigationEntry& navigation,
565 sync_pb::TabNavigation* tab_navigation) { 630 sync_pb::TabNavigation* tab_navigation) {
566 tab_navigation->set_index(navigation->index()); 631 tab_navigation->set_virtual_url(navigation.GetVirtualURL().spec());
567 tab_navigation->set_virtual_url(navigation->virtual_url().spec());
568 // FIXME(zea): Support referrer policy? 632 // FIXME(zea): Support referrer policy?
569 tab_navigation->set_referrer(navigation->referrer().url.spec()); 633 tab_navigation->set_referrer(navigation.GetReferrer().url.spec());
570 tab_navigation->set_title(UTF16ToUTF8(navigation->title())); 634 tab_navigation->set_title(UTF16ToUTF8(navigation.GetTitle()));
571 switch (navigation->transition()) { 635 switch (navigation.GetTransitionType()) {
572 case content::PAGE_TRANSITION_LINK: 636 case content::PAGE_TRANSITION_LINK:
573 tab_navigation->set_page_transition( 637 tab_navigation->set_page_transition(
574 sync_pb::TabNavigation_PageTransition_LINK); 638 sync_pb::TabNavigation_PageTransition_LINK);
575 break; 639 break;
576 case content::PAGE_TRANSITION_TYPED: 640 case content::PAGE_TRANSITION_TYPED:
577 tab_navigation->set_page_transition( 641 tab_navigation->set_page_transition(
578 sync_pb::TabNavigation_PageTransition_TYPED); 642 sync_pb::TabNavigation_PageTransition_TYPED);
579 break; 643 break;
580 case content::PAGE_TRANSITION_AUTO_BOOKMARK: 644 case content::PAGE_TRANSITION_AUTO_BOOKMARK:
581 tab_navigation->set_page_transition( 645 tab_navigation->set_page_transition(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 sync_pb::TabNavigation_PageTransitionQualifier_CLIENT_REDIRECT); 690 sync_pb::TabNavigation_PageTransitionQualifier_CLIENT_REDIRECT);
627 break; 691 break;
628 case content::PAGE_TRANSITION_SERVER_REDIRECT: 692 case content::PAGE_TRANSITION_SERVER_REDIRECT:
629 tab_navigation->set_navigation_qualifier( 693 tab_navigation->set_navigation_qualifier(
630 sync_pb::TabNavigation_PageTransitionQualifier_SERVER_REDIRECT); 694 sync_pb::TabNavigation_PageTransitionQualifier_SERVER_REDIRECT);
631 break; 695 break;
632 default: 696 default:
633 tab_navigation->set_page_transition( 697 tab_navigation->set_page_transition(
634 sync_pb::TabNavigation_PageTransition_TYPED); 698 sync_pb::TabNavigation_PageTransition_TYPED);
635 } 699 }
700 tab_navigation->set_unique_id(navigation.GetUniqueID());
701 tab_navigation->set_timestamp(TimeToProtoTime(base::Time::Now()));
636 } 702 }
637 703
638 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, 704 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab,
639 int64 sync_id) { 705 int64 sync_id) {
640 NOTIMPLEMENTED(); 706 NOTIMPLEMENTED();
641 } 707 }
642 708
643 void SessionModelAssociator::Disassociate(int64 sync_id) { 709 void SessionModelAssociator::Disassociate(int64 sync_id) {
644 DCHECK(CalledOnValidThread()); 710 DCHECK(CalledOnValidThread());
645 NOTIMPLEMENTED(); 711 NOTIMPLEMENTED();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 modification_time, 965 modification_time,
900 foreign_session->windows[window_id], 966 foreign_session->windows[window_id],
901 &synced_session_tracker_); 967 &synced_session_tracker_);
902 } 968 }
903 969
904 // Delete any closed windows and unused tabs as necessary. 970 // Delete any closed windows and unused tabs as necessary.
905 synced_session_tracker_.CleanupSession(foreign_session_tag); 971 synced_session_tracker_.CleanupSession(foreign_session_tag);
906 } else if (specifics.has_tab()) { 972 } else if (specifics.has_tab()) {
907 const sync_pb::SessionTab& tab_s = specifics.tab(); 973 const sync_pb::SessionTab& tab_s = specifics.tab();
908 SessionID::id_type tab_id = tab_s.tab_id(); 974 SessionID::id_type tab_id = tab_s.tab_id();
909 SessionTab* tab = 975 SyncedSessionTab* tab =
910 synced_session_tracker_.GetTab(foreign_session_tag, tab_id); 976 synced_session_tracker_.GetTab(foreign_session_tag, tab_id);
911 977
912 // Figure out what the previous url for this tab was (may be empty string 978 // Figure out what the previous url for this tab was (may be empty string
913 // if this is a new tab). 979 // if this is a new tab).
914 std::string previous_url; 980 std::string previous_url;
915 if (tab->navigations.size() > 0) { 981 if (tab->navigations.size() > 0) {
916 int selected_index = tab->current_navigation_index; 982 int selected_index = tab->current_navigation_index;
917 selected_index = std::max( 983 selected_index = std::max(
918 0, 984 0,
919 std::min(selected_index, 985 std::min(selected_index,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 session_window->window_id.id(), 1119 session_window->window_id.id(),
1054 tab_id, 1120 tab_id,
1055 i); 1121 i);
1056 } 1122 }
1057 } 1123 }
1058 1124
1059 // Static 1125 // Static
1060 void SessionModelAssociator::PopulateSessionTabFromSpecifics( 1126 void SessionModelAssociator::PopulateSessionTabFromSpecifics(
1061 const sync_pb::SessionTab& specifics, 1127 const sync_pb::SessionTab& specifics,
1062 const base::Time& mtime, 1128 const base::Time& mtime,
1063 SessionTab* tab) { 1129 SyncedSessionTab* tab) {
1064 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); 1130 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id());
1065 if (specifics.has_tab_id()) 1131 if (specifics.has_tab_id())
1066 tab->tab_id.set_id(specifics.tab_id()); 1132 tab->tab_id.set_id(specifics.tab_id());
1067 if (specifics.has_window_id()) 1133 if (specifics.has_window_id())
1068 tab->window_id.set_id(specifics.window_id()); 1134 tab->window_id.set_id(specifics.window_id());
1069 if (specifics.has_tab_visual_index()) 1135 if (specifics.has_tab_visual_index())
1070 tab->tab_visual_index = specifics.tab_visual_index(); 1136 tab->tab_visual_index = specifics.tab_visual_index();
1071 if (specifics.has_current_navigation_index()) 1137 if (specifics.has_current_navigation_index())
1072 tab->current_navigation_index = specifics.current_navigation_index(); 1138 tab->current_navigation_index = specifics.current_navigation_index();
1073 if (specifics.has_pinned()) 1139 if (specifics.has_pinned())
1074 tab->pinned = specifics.pinned(); 1140 tab->pinned = specifics.pinned();
1075 if (specifics.has_extension_app_id()) 1141 if (specifics.has_extension_app_id())
1076 tab->extension_app_id = specifics.extension_app_id(); 1142 tab->extension_app_id = specifics.extension_app_id();
1077 tab->timestamp = mtime; 1143 tab->timestamp = mtime;
1078 tab->navigations.clear(); // In case we are reusing a previous SessionTab. 1144 // Cleared in case we reuse a pre-existing SyncedSessionTab object.
1079 for (int i = 0; i < specifics.navigation_size(); i++) { 1145 tab->navigations.clear();
1080 AppendSessionTabNavigation(specifics.navigation(i), &tab->navigations); 1146 tab->synced_tab_navigations.clear();
1147 for (int i = 0; i < specifics.navigation_size(); ++i) {
1148 AppendSessionTabNavigation(specifics.navigation(i),
1149 tab);
1081 } 1150 }
1082 } 1151 }
1083 1152
1084 // Static 1153 // Static
1085 void SessionModelAssociator::AppendSessionTabNavigation( 1154 void SessionModelAssociator::AppendSessionTabNavigation(
1086 const sync_pb::TabNavigation& specifics, 1155 const sync_pb::TabNavigation& specifics,
1087 std::vector<TabNavigation>* navigations) { 1156 SyncedSessionTab* tab) {
1088 int index = 0; 1157 int index = 0;
1089 GURL virtual_url; 1158 GURL virtual_url;
1090 GURL referrer; 1159 GURL referrer;
1091 string16 title; 1160 string16 title;
1092 std::string state; 1161 std::string state;
1093 content::PageTransition transition(content::PAGE_TRANSITION_LINK); 1162 content::PageTransition transition(content::PAGE_TRANSITION_LINK);
1094 if (specifics.has_index()) 1163 base::Time timestamp;
1095 index = specifics.index(); 1164 int unique_id = 0;
1096 if (specifics.has_virtual_url()) { 1165 if (specifics.has_virtual_url()) {
1097 GURL gurl(specifics.virtual_url()); 1166 GURL gurl(specifics.virtual_url());
1098 virtual_url = gurl; 1167 virtual_url = gurl;
1099 } 1168 }
1100 if (specifics.has_referrer()) { 1169 if (specifics.has_referrer()) {
1101 GURL gurl(specifics.referrer()); 1170 GURL gurl(specifics.referrer());
1102 referrer = gurl; 1171 referrer = gurl;
1103 } 1172 }
1104 if (specifics.has_title()) 1173 if (specifics.has_title())
1105 title = UTF8ToUTF16(specifics.title()); 1174 title = UTF8ToUTF16(specifics.title());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 break; 1224 break;
1156 case sync_pb:: 1225 case sync_pb::
1157 TabNavigation_PageTransitionQualifier_SERVER_REDIRECT: 1226 TabNavigation_PageTransitionQualifier_SERVER_REDIRECT:
1158 transition = content::PAGE_TRANSITION_SERVER_REDIRECT; 1227 transition = content::PAGE_TRANSITION_SERVER_REDIRECT;
1159 break; 1228 break;
1160 default: 1229 default:
1161 transition = content::PAGE_TRANSITION_TYPED; 1230 transition = content::PAGE_TRANSITION_TYPED;
1162 } 1231 }
1163 } 1232 }
1164 } 1233 }
1165 TabNavigation tab_navigation( 1234 if (specifics.has_timestamp()) {
1235 timestamp = ProtoTimeToTime(specifics.timestamp());
1236 }
1237 if (specifics.has_unique_id()) {
1238 unique_id = specifics.unique_id();
1239 }
1240 SyncedTabNavigation tab_navigation(
1166 index, virtual_url, 1241 index, virtual_url,
1167 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title, 1242 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title,
1168 state, transition); 1243 state, transition, unique_id, timestamp);
1169 navigations->insert(navigations->end(), tab_navigation); 1244 // We insert it twice, once for our SyncedTabNavigations, once for the normal
1245 // TabNavigation (used by the session restore UI).
1246 tab->synced_tab_navigations.insert(tab->synced_tab_navigations.end(),
1247 tab_navigation);
1248 tab->navigations.insert(tab->navigations.end(),
1249 tab_navigation);
1170 } 1250 }
1171 1251
1172 void SessionModelAssociator::LoadForeignTabFavicon( 1252 void SessionModelAssociator::LoadForeignTabFavicon(
1173 const sync_pb::SessionTab& tab) { 1253 const sync_pb::SessionTab& tab) {
1174 if (!tab.has_favicon() || tab.favicon().empty()) 1254 if (!tab.has_favicon() || tab.favicon().empty())
1175 return; 1255 return;
1176 if (!tab.has_favicon_type() || 1256 if (!tab.has_favicon_type() ||
1177 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { 1257 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) {
1178 DVLOG(1) << "Ignoring non-web favicon."; 1258 DVLOG(1) << "Ignoring non-web favicon.";
1179 return; 1259 return;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 std::vector<const SessionWindow*>* windows) { 1383 std::vector<const SessionWindow*>* windows) {
1304 DCHECK(CalledOnValidThread()); 1384 DCHECK(CalledOnValidThread());
1305 return synced_session_tracker_.LookupSessionWindows(tag, windows); 1385 return synced_session_tracker_.LookupSessionWindows(tag, windows);
1306 } 1386 }
1307 1387
1308 bool SessionModelAssociator::GetForeignTab( 1388 bool SessionModelAssociator::GetForeignTab(
1309 const std::string& tag, 1389 const std::string& tag,
1310 const SessionID::id_type tab_id, 1390 const SessionID::id_type tab_id,
1311 const SessionTab** tab) { 1391 const SessionTab** tab) {
1312 DCHECK(CalledOnValidThread()); 1392 DCHECK(CalledOnValidThread());
1313 return synced_session_tracker_.LookupSessionTab(tag, tab_id, tab); 1393 const SyncedSessionTab* synced_tab;
1394 bool success = synced_session_tracker_.LookupSessionTab(tag,
1395 tab_id,
1396 &synced_tab);
1397 if (success)
1398 *tab = synced_tab;
1399 return success;
1314 } 1400 }
1315 1401
1316 void SessionModelAssociator::DeleteStaleSessions() { 1402 void SessionModelAssociator::DeleteStaleSessions() {
1317 DCHECK(CalledOnValidThread()); 1403 DCHECK(CalledOnValidThread());
1318 std::vector<const SyncedSession*> sessions; 1404 std::vector<const SyncedSession*> sessions;
1319 if (!GetAllForeignSessions(&sessions)) 1405 if (!GetAllForeignSessions(&sessions))
1320 return; // No foreign sessions. 1406 return; // No foreign sessions.
1321 1407
1322 // Iterate through all the sessions and delete any with age older than 1408 // Iterate through all the sessions and delete any with age older than
1323 // |stale_session_threshold_days_|. 1409 // |stale_session_threshold_days_|.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1538 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1453 // We only access the cryptographer while holding a transaction. 1539 // We only access the cryptographer while holding a transaction.
1454 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1540 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1455 const syncable::ModelTypeSet encrypted_types = 1541 const syncable::ModelTypeSet encrypted_types =
1456 sync_api::GetEncryptedTypes(&trans); 1542 sync_api::GetEncryptedTypes(&trans);
1457 return !encrypted_types.Has(SESSIONS) || 1543 return !encrypted_types.Has(SESSIONS) ||
1458 sync_service_->IsCryptographerReady(&trans); 1544 sync_service_->IsCryptographerReady(&trans);
1459 } 1545 }
1460 1546
1461 } // namespace browser_sync 1547 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.h ('k') | chrome/browser/sync/glue/session_model_associator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698