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

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

Issue 10917231: Revamp TabNavigation class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac Created 8 years, 3 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // unrecoverable error. 249 // unrecoverable error.
250 return false; 250 return false;
251 } 251 }
252 } 252 }
253 253
254 // If the tab is valid, it would have been added to the tracker either 254 // If the tab is valid, it would have been added to the tracker either
255 // by the above AssociateTab call (at association time), or by the 255 // by the above AssociateTab call (at association time), or by the
256 // change processor calling AssociateTab for all modified tabs. 256 // change processor calling AssociateTab for all modified tabs.
257 // Therefore, we can key whether this window has valid tabs based on 257 // Therefore, we can key whether this window has valid tabs based on
258 // the tab's presence in the tracker. 258 // the tab's presence in the tracker.
259 const SyncedSessionTab* tab; 259 const SessionTab* tab = NULL;
260 if (synced_session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) { 260 if (synced_session_tracker_.LookupSessionTab(local_tag, tab_id, &tab)) {
261 found_tabs = true; 261 found_tabs = true;
262 window_s.add_tab(tab_id); 262 window_s.add_tab(tab_id);
263 } 263 }
264 } 264 }
265 // Only add a window if it contains valid tabs. 265 // Only add a window if it contains valid tabs.
266 if (found_tabs) { 266 if (found_tabs) {
267 sync_pb::SessionWindow* header_window = header_s->add_window(); 267 sync_pb::SessionWindow* header_window = header_s->add_window();
268 *header_window = window_s; 268 *header_window = window_s;
269 269
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 DCHECK(CalledOnValidThread()); 378 DCHECK(CalledOnValidThread());
379 const SyncedTabDelegate& tab = *(tab_link->tab()); 379 const SyncedTabDelegate& tab = *(tab_link->tab());
380 const SyncedWindowDelegate& window = 380 const SyncedWindowDelegate& window =
381 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( 381 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId(
382 tab.GetWindowId()); 382 tab.GetWindowId());
383 int64 sync_id = tab_link->sync_id(); 383 int64 sync_id = tab_link->sync_id();
384 GURL old_tab_url = tab_link->url(); 384 GURL old_tab_url = tab_link->url();
385 385
386 // Load the last stored version of this tab so we can compare changes. If this 386 // Load the last stored version of this tab so we can compare changes. If this
387 // is a new tab, session_tab will be a blank/newly created SessionTab object. 387 // is a new tab, session_tab will be a blank/newly created SessionTab object.
388 SyncedSessionTab* session_tab = 388 SessionTab* session_tab =
389 synced_session_tracker_.GetTab(GetCurrentMachineTag(), 389 synced_session_tracker_.GetTab(GetCurrentMachineTag(),
390 tab.GetSessionId()); 390 tab.GetSessionId());
391 391
392 // We build a clean session tab specifics directly from the tab data. 392 // We build a clean session tab specifics directly from the tab data.
393 sync_pb::SessionTab tab_s; 393 sync_pb::SessionTab tab_s;
394 394
395 GURL new_url; 395 GURL new_url;
396 AssociateTabContents(window, tab, session_tab, &tab_s, &new_url); 396 AssociateTabContents(window, tab, session_tab, &tab_s, &new_url);
397 397
398 // Trigger the favicon load if needed. We do this before opening the write 398 // Trigger the favicon load if needed. We do this before opening the write
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // by the unique id, and the navigation didn't just become the current 446 // by the unique id, and the navigation didn't just become the current
447 // navigation, we preserve the old timestamp. 447 // navigation, we preserve the old timestamp.
448 // 2. If the navigation exists in both but just become the current navigation 448 // 2. If the navigation exists in both but just become the current navigation
449 // (e.g. the user went back in history to this navigation), we update the 449 // (e.g. the user went back in history to this navigation), we update the
450 // timestamp to Now(). 450 // timestamp to Now().
451 // 3. All new navigations not present in |prev_tab| have their timestamps set to 451 // 3. All new navigations not present in |prev_tab| have their timestamps set to
452 // Now(). 452 // Now().
453 void SessionModelAssociator::AssociateTabContents( 453 void SessionModelAssociator::AssociateTabContents(
454 const SyncedWindowDelegate& window, 454 const SyncedWindowDelegate& window,
455 const SyncedTabDelegate& new_tab, 455 const SyncedTabDelegate& new_tab,
456 SyncedSessionTab* prev_tab, 456 SessionTab* prev_tab,
457 sync_pb::SessionTab* sync_tab, 457 sync_pb::SessionTab* sync_tab,
458 GURL* new_url) { 458 GURL* new_url) {
459 DCHECK(prev_tab); 459 DCHECK(prev_tab);
460 DCHECK(sync_tab); 460 DCHECK(sync_tab);
461 DCHECK(new_url); 461 DCHECK(new_url);
462 SessionID::id_type tab_id = new_tab.GetSessionId(); 462 SessionID::id_type tab_id = new_tab.GetSessionId();
463 sync_tab->set_tab_id(tab_id); 463 sync_tab->set_tab_id(tab_id);
464 sync_tab->set_window_id(new_tab.GetWindowId()); 464 sync_tab->set_window_id(new_tab.GetWindowId());
465 const int current_index = new_tab.GetCurrentEntryIndex(); 465 const int current_index = new_tab.GetCurrentEntryIndex();
466 sync_tab->set_current_navigation_index(current_index); 466 sync_tab->set_current_navigation_index(current_index);
467 const int min_index = std::max(0, 467 const int min_index = std::max(0,
468 current_index - kMaxSyncNavigationCount); 468 current_index - kMaxSyncNavigationCount);
469 const int max_index = std::min(current_index + kMaxSyncNavigationCount, 469 const int max_index = std::min(current_index + kMaxSyncNavigationCount,
470 new_tab.GetEntryCount()); 470 new_tab.GetEntryCount());
471 const int pending_index = new_tab.GetPendingEntryIndex(); 471 const int pending_index = new_tab.GetPendingEntryIndex();
472 sync_tab->set_pinned(window.IsTabPinned(&new_tab)); 472 sync_tab->set_pinned(window.IsTabPinned(&new_tab));
473 if (new_tab.HasExtensionAppId()) { 473 if (new_tab.HasExtensionAppId()) {
474 sync_tab->set_extension_app_id(new_tab.GetExtensionAppId()); 474 sync_tab->set_extension_app_id(new_tab.GetExtensionAppId());
475 } 475 }
476 476
477 sync_tab->mutable_navigation()->Clear(); 477 sync_tab->mutable_navigation()->Clear();
478 std::vector<SyncedTabNavigation>::const_iterator prev_nav_iter = 478 std::vector<TabNavigation>::const_iterator prev_nav_iter =
479 prev_tab->synced_tab_navigations.begin(); 479 prev_tab->navigations.begin();
480 for (int i = min_index; i < max_index; ++i) { 480 for (int i = min_index; i < max_index; ++i) {
481 const NavigationEntry* entry = (i == pending_index) ? 481 const NavigationEntry* entry = (i == pending_index) ?
482 new_tab.GetPendingEntry() : new_tab.GetEntryAtIndex(i); 482 new_tab.GetPendingEntry() : new_tab.GetEntryAtIndex(i);
483 DCHECK(entry); 483 DCHECK(entry);
484 if (i == min_index) { 484 if (i == min_index) {
485 // Find the location of the first navigation within the previous list of 485 // Find the location of the first navigation within the previous list of
486 // navigations. We only need to do this once, as all subsequent 486 // navigations. We only need to do this once, as all subsequent
487 // navigations are either contiguous or completely new. 487 // navigations are either contiguous or completely new.
488 for (;prev_nav_iter != prev_tab->synced_tab_navigations.end(); 488 for (;prev_nav_iter != prev_tab->navigations.end();
489 ++prev_nav_iter) { 489 ++prev_nav_iter) {
490 if (prev_nav_iter->unique_id() == entry->GetUniqueID()) 490 if (prev_nav_iter->unique_id() == entry->GetUniqueID())
491 break; 491 break;
492 } 492 }
493 } 493 }
494 if (entry->GetVirtualURL().is_valid()) { 494 if (entry->GetVirtualURL().is_valid()) {
495 if (i == current_index) { 495 if (i == current_index) {
496 *new_url = GURL(entry->GetVirtualURL().spec()); 496 *new_url = GURL(entry->GetVirtualURL().spec());
497 DVLOG(1) << "Associating local tab " << new_tab.GetSessionId() 497 DVLOG(1) << "Associating local tab " << new_tab.GetSessionId()
498 << " with url " << new_url->spec() << " and title " 498 << " with url " << new_url->spec() << " and title "
499 << entry->GetTitle(); 499 << entry->GetTitle();
500 500
501 } 501 }
502 sync_pb::TabNavigation* sync_nav = sync_tab->add_navigation(); 502 sync_pb::TabNavigation* sync_nav = sync_tab->add_navigation();
503 PopulateSessionSpecificsNavigation(*entry, sync_nav); 503 const TabNavigation& navigation =
504 TabNavigation::FromNavigationEntry(i, *entry, base::Time::Now());
505 *sync_nav = navigation.ToSyncData();
504 506
505 // If this navigation is an old one, reuse the old timestamp. Otherwise we 507 // If this navigation is an old one, reuse the old timestamp. Otherwise we
506 // leave the timestamp as the current time. 508 // leave the timestamp as the current time.
507 if (prev_nav_iter != prev_tab->synced_tab_navigations.end() && 509 if (prev_nav_iter != prev_tab->navigations.end() &&
508 prev_nav_iter->unique_id() == entry->GetUniqueID()) { 510 prev_nav_iter->unique_id() == entry->GetUniqueID()) {
509 // Check that we haven't gone back/foward in the nav stack to this page 511 // Check that we haven't gone back/foward in the nav stack to this page
510 // (if so, we want to refresh the timestamp). 512 // (if so, we want to refresh the timestamp).
511 if (!(current_index != prev_tab->current_navigation_index && 513 if (!(current_index != prev_tab->current_navigation_index &&
512 current_index == i)) { 514 current_index == i)) {
513 sync_nav->set_timestamp( 515 sync_nav->set_timestamp(
514 syncer::TimeToProtoTime(prev_nav_iter->timestamp())); 516 syncer::TimeToProtoTime(prev_nav_iter->timestamp()));
515 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, " 517 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, "
516 << "reusing old timestamp " << sync_nav->timestamp(); 518 << "reusing old timestamp " << sync_nav->timestamp();
517 } 519 }
518 // Even if the user went back in their history, they may have skipped 520 // Even if the user went back in their history, they may have skipped
519 // over navigations, so the subsequent navigation entries may need their 521 // over navigations, so the subsequent navigation entries may need their
520 // old timestamps preserved. 522 // old timestamps preserved.
521 ++prev_nav_iter; 523 ++prev_nav_iter;
522 } else if (current_index != i && 524 } else if (current_index != i &&
523 prev_tab->synced_tab_navigations.empty()) { 525 prev_tab->navigations.empty()) {
524 // If this is a new tab, and has more than one navigation, we don't 526 // If this is a new tab, and has more than one navigation, we don't
525 // actually want to assign the current timestamp to other navigations. 527 // actually want to assign the current timestamp to other navigations.
526 // Override the timestamp to 0 in that case. 528 // Override the timestamp to 0 in that case.
527 // Note: this is primarily to handle restoring sessions at restart, 529 // Note: this is primarily to handle restoring sessions at restart,
528 // opening recently closed tabs, or opening tabs from other devices. 530 // opening recently closed tabs, or opening tabs from other devices.
529 // Only the current navigation should have a timestamp in those cases. 531 // Only the current navigation should have a timestamp in those cases.
530 sync_nav->set_timestamp(0); 532 sync_nav->set_timestamp(0);
531 } 533 }
532 } 534 }
533 } 535 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // where we rewrite tab specifics every time a favicon changes, since some 642 // where we rewrite tab specifics every time a favicon changes, since some
641 // favicons can in fact be web-controlled/animated. 643 // favicons can in fact be web-controlled/animated.
642 if (tab_iter->second->url() == *i && 644 if (tab_iter->second->url() == *i &&
643 tab_iter->second->favicon_load_handle() != 0) { 645 tab_iter->second->favicon_load_handle() != 0) {
644 LoadFaviconForTab(tab_iter->second.get()); 646 LoadFaviconForTab(tab_iter->second.get());
645 } 647 }
646 } 648 }
647 } 649 }
648 } 650 }
649 651
650 // Static
651 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well?
652 // See http://crbug.com/67068.
653 void SessionModelAssociator::PopulateSessionSpecificsNavigation(
654 const NavigationEntry& navigation,
655 sync_pb::TabNavigation* tab_navigation) {
656 tab_navigation->set_virtual_url(navigation.GetVirtualURL().spec());
657 // FIXME(zea): Support referrer policy?
658 tab_navigation->set_referrer(navigation.GetReferrer().url.spec());
659 tab_navigation->set_title(UTF16ToUTF8(navigation.GetTitle()));
660 switch (navigation.GetTransitionType()) {
661 case content::PAGE_TRANSITION_LINK:
662 tab_navigation->set_page_transition(
663 sync_pb::SyncEnums_PageTransition_LINK);
664 break;
665 case content::PAGE_TRANSITION_TYPED:
666 tab_navigation->set_page_transition(
667 sync_pb::SyncEnums_PageTransition_TYPED);
668 break;
669 case content::PAGE_TRANSITION_AUTO_BOOKMARK:
670 tab_navigation->set_page_transition(
671 sync_pb::SyncEnums_PageTransition_AUTO_BOOKMARK);
672 break;
673 case content::PAGE_TRANSITION_AUTO_SUBFRAME:
674 tab_navigation->set_page_transition(
675 sync_pb::SyncEnums_PageTransition_AUTO_SUBFRAME);
676 break;
677 case content::PAGE_TRANSITION_MANUAL_SUBFRAME:
678 tab_navigation->set_page_transition(
679 sync_pb::SyncEnums_PageTransition_MANUAL_SUBFRAME);
680 break;
681 case content::PAGE_TRANSITION_GENERATED:
682 tab_navigation->set_page_transition(
683 sync_pb::SyncEnums_PageTransition_GENERATED);
684 break;
685 case content::PAGE_TRANSITION_AUTO_TOPLEVEL:
686 tab_navigation->set_page_transition(
687 sync_pb::SyncEnums_PageTransition_AUTO_TOPLEVEL);
688 break;
689 case content::PAGE_TRANSITION_FORM_SUBMIT:
690 tab_navigation->set_page_transition(
691 sync_pb::SyncEnums_PageTransition_FORM_SUBMIT);
692 break;
693 case content::PAGE_TRANSITION_RELOAD:
694 tab_navigation->set_page_transition(
695 sync_pb::SyncEnums_PageTransition_RELOAD);
696 break;
697 case content::PAGE_TRANSITION_KEYWORD:
698 tab_navigation->set_page_transition(
699 sync_pb::SyncEnums_PageTransition_KEYWORD);
700 break;
701 case content::PAGE_TRANSITION_KEYWORD_GENERATED:
702 tab_navigation->set_page_transition(
703 sync_pb::SyncEnums_PageTransition_KEYWORD_GENERATED);
704 break;
705 case content::PAGE_TRANSITION_CHAIN_START:
706 tab_navigation->set_page_transition(
707 sync_pb::SyncEnums_PageTransition_CHAIN_START);
708 break;
709 case content::PAGE_TRANSITION_CHAIN_END:
710 tab_navigation->set_page_transition(
711 sync_pb::SyncEnums_PageTransition_CHAIN_END);
712 break;
713 case content::PAGE_TRANSITION_CLIENT_REDIRECT:
714 tab_navigation->set_navigation_qualifier(
715 sync_pb::SyncEnums_PageTransitionQualifier_CLIENT_REDIRECT);
716 break;
717 case content::PAGE_TRANSITION_SERVER_REDIRECT:
718 tab_navigation->set_navigation_qualifier(
719 sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT);
720 break;
721 default:
722 tab_navigation->set_page_transition(
723 sync_pb::SyncEnums_PageTransition_TYPED);
724 }
725 tab_navigation->set_unique_id(navigation.GetUniqueID());
726 tab_navigation->set_timestamp(
727 syncer::TimeToProtoTime(base::Time::Now()));
728 }
729
730 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, 652 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab,
731 int64 sync_id) { 653 int64 sync_id) {
732 NOTIMPLEMENTED(); 654 NOTIMPLEMENTED();
733 } 655 }
734 656
735 void SessionModelAssociator::Disassociate(int64 sync_id) { 657 void SessionModelAssociator::Disassociate(int64 sync_id) {
736 DCHECK(CalledOnValidThread()); 658 DCHECK(CalledOnValidThread());
737 NOTIMPLEMENTED(); 659 NOTIMPLEMENTED();
738 } 660 }
739 661
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 modification_time, 941 modification_time,
1020 foreign_session->windows[window_id], 942 foreign_session->windows[window_id],
1021 &synced_session_tracker_); 943 &synced_session_tracker_);
1022 } 944 }
1023 945
1024 // Delete any closed windows and unused tabs as necessary. 946 // Delete any closed windows and unused tabs as necessary.
1025 synced_session_tracker_.CleanupSession(foreign_session_tag); 947 synced_session_tracker_.CleanupSession(foreign_session_tag);
1026 } else if (specifics.has_tab()) { 948 } else if (specifics.has_tab()) {
1027 const sync_pb::SessionTab& tab_s = specifics.tab(); 949 const sync_pb::SessionTab& tab_s = specifics.tab();
1028 SessionID::id_type tab_id = tab_s.tab_id(); 950 SessionID::id_type tab_id = tab_s.tab_id();
1029 SyncedSessionTab* tab = 951 SessionTab* tab =
1030 synced_session_tracker_.GetTab(foreign_session_tag, tab_id); 952 synced_session_tracker_.GetTab(foreign_session_tag, tab_id);
1031 953
1032 // Figure out what the previous url for this tab was (may be empty string 954 // Figure out what the previous url for this tab was (may be empty string
1033 // if this is a new tab). 955 // if this is a new tab).
1034 std::string previous_url; 956 std::string previous_url;
1035 if (tab->navigations.size() > 0) { 957 if (tab->navigations.size() > 0) {
1036 int selected_index = tab->current_navigation_index; 958 int selected_index = tab->current_navigation_index;
1037 selected_index = std::max( 959 selected_index = std::max(
1038 0, 960 0,
1039 std::min(selected_index, 961 std::min(selected_index,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 session_window->window_id.id(), 1100 session_window->window_id.id(),
1179 tab_id, 1101 tab_id,
1180 i); 1102 i);
1181 } 1103 }
1182 } 1104 }
1183 1105
1184 // Static 1106 // Static
1185 void SessionModelAssociator::PopulateSessionTabFromSpecifics( 1107 void SessionModelAssociator::PopulateSessionTabFromSpecifics(
1186 const sync_pb::SessionTab& specifics, 1108 const sync_pb::SessionTab& specifics,
1187 const base::Time& mtime, 1109 const base::Time& mtime,
1188 SyncedSessionTab* tab) { 1110 SessionTab* tab) {
1189 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); 1111 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id());
1190 if (specifics.has_tab_id()) 1112 if (specifics.has_tab_id())
1191 tab->tab_id.set_id(specifics.tab_id()); 1113 tab->tab_id.set_id(specifics.tab_id());
1192 if (specifics.has_window_id()) 1114 if (specifics.has_window_id())
1193 tab->window_id.set_id(specifics.window_id()); 1115 tab->window_id.set_id(specifics.window_id());
1194 if (specifics.has_tab_visual_index()) 1116 if (specifics.has_tab_visual_index())
1195 tab->tab_visual_index = specifics.tab_visual_index(); 1117 tab->tab_visual_index = specifics.tab_visual_index();
1196 if (specifics.has_current_navigation_index()) 1118 if (specifics.has_current_navigation_index())
1197 tab->current_navigation_index = specifics.current_navigation_index(); 1119 tab->current_navigation_index = specifics.current_navigation_index();
1198 if (specifics.has_pinned()) 1120 if (specifics.has_pinned())
1199 tab->pinned = specifics.pinned(); 1121 tab->pinned = specifics.pinned();
1200 if (specifics.has_extension_app_id()) 1122 if (specifics.has_extension_app_id())
1201 tab->extension_app_id = specifics.extension_app_id(); 1123 tab->extension_app_id = specifics.extension_app_id();
1202 tab->timestamp = mtime; 1124 tab->timestamp = mtime;
1203 // Cleared in case we reuse a pre-existing SyncedSessionTab object. 1125 // Cleared in case we reuse a pre-existing SyncedSessionTab object.
1204 tab->navigations.clear(); 1126 tab->navigations.clear();
1205 tab->synced_tab_navigations.clear();
1206 for (int i = 0; i < specifics.navigation_size(); ++i) { 1127 for (int i = 0; i < specifics.navigation_size(); ++i) {
1207 AppendSessionTabNavigation(specifics.navigation(i), 1128 tab->navigations.push_back(
1208 tab); 1129 TabNavigation::FromSyncData(i, specifics.navigation(i)));
1209 } 1130 }
1210 } 1131 }
1211 1132
1212 // Static
1213 void SessionModelAssociator::AppendSessionTabNavigation(
1214 const sync_pb::TabNavigation& specifics,
1215 SyncedSessionTab* tab) {
1216 int index = 0;
1217 GURL virtual_url;
1218 GURL referrer;
1219 string16 title;
1220 std::string state;
1221 content::PageTransition transition(content::PAGE_TRANSITION_LINK);
1222 base::Time timestamp;
1223 int unique_id = 0;
1224 if (specifics.has_virtual_url()) {
1225 GURL gurl(specifics.virtual_url());
1226 virtual_url = gurl;
1227 }
1228 if (specifics.has_referrer()) {
1229 GURL gurl(specifics.referrer());
1230 referrer = gurl;
1231 }
1232 if (specifics.has_title())
1233 title = UTF8ToUTF16(specifics.title());
1234 if (specifics.has_state())
1235 state = specifics.state();
1236 if (specifics.has_page_transition() ||
1237 specifics.has_navigation_qualifier()) {
1238 switch (specifics.page_transition()) {
1239 case sync_pb::SyncEnums_PageTransition_LINK:
1240 transition = content::PAGE_TRANSITION_LINK;
1241 break;
1242 case sync_pb::SyncEnums_PageTransition_TYPED:
1243 transition = content::PAGE_TRANSITION_TYPED;
1244 break;
1245 case sync_pb::SyncEnums_PageTransition_AUTO_BOOKMARK:
1246 transition = content::PAGE_TRANSITION_AUTO_BOOKMARK;
1247 break;
1248 case sync_pb::SyncEnums_PageTransition_AUTO_SUBFRAME:
1249 transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
1250 break;
1251 case sync_pb::SyncEnums_PageTransition_MANUAL_SUBFRAME:
1252 transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
1253 break;
1254 case sync_pb::SyncEnums_PageTransition_GENERATED:
1255 transition = content::PAGE_TRANSITION_GENERATED;
1256 break;
1257 case sync_pb::SyncEnums_PageTransition_AUTO_TOPLEVEL:
1258 transition = content::PAGE_TRANSITION_AUTO_TOPLEVEL;
1259 break;
1260 case sync_pb::SyncEnums_PageTransition_FORM_SUBMIT:
1261 transition = content::PAGE_TRANSITION_FORM_SUBMIT;
1262 break;
1263 case sync_pb::SyncEnums_PageTransition_RELOAD:
1264 transition = content::PAGE_TRANSITION_RELOAD;
1265 break;
1266 case sync_pb::SyncEnums_PageTransition_KEYWORD:
1267 transition = content::PAGE_TRANSITION_KEYWORD;
1268 break;
1269 case sync_pb::SyncEnums_PageTransition_KEYWORD_GENERATED:
1270 transition = content::PAGE_TRANSITION_KEYWORD_GENERATED;
1271 break;
1272 case sync_pb::SyncEnums_PageTransition_CHAIN_START:
1273 transition = content::PAGE_TRANSITION_CHAIN_START;
1274 break;
1275 case sync_pb::SyncEnums_PageTransition_CHAIN_END:
1276 transition = content::PAGE_TRANSITION_CHAIN_END;
1277 break;
1278 default:
1279 switch (specifics.navigation_qualifier()) {
1280 case sync_pb::SyncEnums_PageTransitionQualifier_CLIENT_REDIRECT:
1281 transition = content::PAGE_TRANSITION_CLIENT_REDIRECT;
1282 break;
1283 case sync_pb::SyncEnums_PageTransitionQualifier_SERVER_REDIRECT:
1284 transition = content::PAGE_TRANSITION_SERVER_REDIRECT;
1285 break;
1286 default:
1287 transition = content::PAGE_TRANSITION_TYPED;
1288 }
1289 }
1290 }
1291 if (specifics.has_timestamp()) {
1292 timestamp = syncer::ProtoTimeToTime(specifics.timestamp());
1293 }
1294 if (specifics.has_unique_id()) {
1295 unique_id = specifics.unique_id();
1296 }
1297 SyncedTabNavigation tab_navigation(
1298 index, virtual_url,
1299 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title,
1300 state, transition, unique_id, timestamp);
1301 // We insert it twice, once for our SyncedTabNavigations, once for the normal
1302 // TabNavigation (used by the session restore UI).
1303 tab->synced_tab_navigations.insert(tab->synced_tab_navigations.end(),
1304 tab_navigation);
1305 tab->navigations.insert(tab->navigations.end(),
1306 tab_navigation);
1307 }
1308
1309 void SessionModelAssociator::LoadForeignTabFavicon( 1133 void SessionModelAssociator::LoadForeignTabFavicon(
1310 const sync_pb::SessionTab& tab) { 1134 const sync_pb::SessionTab& tab) {
1311 if (!tab.has_favicon() || tab.favicon().empty()) 1135 if (!tab.has_favicon() || tab.favicon().empty())
1312 return; 1136 return;
1313 if (!tab.has_favicon_type() || 1137 if (!tab.has_favicon_type() ||
1314 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { 1138 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) {
1315 DVLOG(1) << "Ignoring non-web favicon."; 1139 DVLOG(1) << "Ignoring non-web favicon.";
1316 return; 1140 return;
1317 } 1141 }
1318 if (tab.navigation_size() == 0) 1142 if (tab.navigation_size() == 0)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 std::vector<const SessionWindow*>* windows) { 1267 std::vector<const SessionWindow*>* windows) {
1444 DCHECK(CalledOnValidThread()); 1268 DCHECK(CalledOnValidThread());
1445 return synced_session_tracker_.LookupSessionWindows(tag, windows); 1269 return synced_session_tracker_.LookupSessionWindows(tag, windows);
1446 } 1270 }
1447 1271
1448 bool SessionModelAssociator::GetForeignTab( 1272 bool SessionModelAssociator::GetForeignTab(
1449 const std::string& tag, 1273 const std::string& tag,
1450 const SessionID::id_type tab_id, 1274 const SessionID::id_type tab_id,
1451 const SessionTab** tab) { 1275 const SessionTab** tab) {
1452 DCHECK(CalledOnValidThread()); 1276 DCHECK(CalledOnValidThread());
1453 const SyncedSessionTab* synced_tab; 1277 const SessionTab* synced_tab = NULL;
1454 bool success = synced_session_tracker_.LookupSessionTab(tag, 1278 bool success = synced_session_tracker_.LookupSessionTab(tag,
1455 tab_id, 1279 tab_id,
1456 &synced_tab); 1280 &synced_tab);
1457 if (success) 1281 if (success)
1458 *tab = synced_tab; 1282 *tab = synced_tab;
1459 return success; 1283 return success;
1460 } 1284 }
1461 1285
1462 void SessionModelAssociator::DeleteStaleSessions() { 1286 void SessionModelAssociator::DeleteStaleSessions() {
1463 DCHECK(CalledOnValidThread()); 1287 DCHECK(CalledOnValidThread());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 1421
1598 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1422 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1599 // We only access the cryptographer while holding a transaction. 1423 // We only access the cryptographer while holding a transaction.
1600 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1424 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1601 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 1425 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
1602 return !encrypted_types.Has(SESSIONS) || 1426 return !encrypted_types.Has(SESSIONS) ||
1603 sync_service_->IsCryptographerReady(&trans); 1427 sync_service_->IsCryptographerReady(&trans);
1604 } 1428 }
1605 1429
1606 } // namespace browser_sync 1430 } // 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