OLD | NEW |
---|---|
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 Loading... | |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
36 #include "sync/protocol/session_specifics.pb.h" | 36 #include "sync/protocol/session_specifics.pb.h" |
37 #include "sync/syncable/syncable.h" | 37 #include "sync/syncable/syncable.h" |
38 #include "sync/syncable/model_type.h" | 38 #include "sync/syncable/model_type.h" |
39 #include "sync/syncable/model_type_payload_map.h" | 39 #include "sync/syncable/model_type_payload_map.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 Loading... | |
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 bool SessionModelAssociator::WriteTabContentsToSyncModel(TabLink* tab_link, | 364 bool SessionModelAssociator::WriteTabContentsToSyncModel(TabLink* tab_link, |
364 SyncError* error) { | 365 SyncError* error) { |
365 DCHECK(CalledOnValidThread()); | 366 DCHECK(CalledOnValidThread()); |
366 const SyncedTabDelegate& tab = *(tab_link->tab()); | 367 const SyncedTabDelegate& tab = *(tab_link->tab()); |
367 const SyncedWindowDelegate& window = | 368 const SyncedWindowDelegate& window = |
368 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | 369 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
369 tab.GetWindowId()); | 370 tab.GetWindowId()); |
370 int64 sync_id = tab_link->sync_id(); | 371 int64 sync_id = tab_link->sync_id(); |
371 GURL old_tab_url = tab_link->url(); | 372 GURL old_tab_url = tab_link->url(); |
372 | 373 |
374 // Load the last stored version of this tab so we can compare changes. If this | |
375 // is a new tab, session_tab will be a blank/newly created SessionTab object. | |
376 SyncedSessionTab* session_tab = | |
377 synced_session_tracker_.GetTab(GetCurrentMachineTag(), | |
378 tab.GetSessionId()); | |
379 | |
373 // We build a clean session specifics directly from the tab data. | 380 // We build a clean session specifics directly from the tab data. |
374 sync_pb::SessionSpecifics session_s; | 381 sync_pb::SessionSpecifics session_s; |
375 session_s.set_session_tag(GetCurrentMachineTag()); | 382 session_s.set_session_tag(GetCurrentMachineTag()); |
376 sync_pb::SessionTab* tab_s = session_s.mutable_tab(); | 383 sync_pb::SessionTab* tab_s = session_s.mutable_tab(); |
377 SessionID::id_type tab_id = tab.GetSessionId(); | 384 |
378 tab_s->set_tab_id(tab_id); | 385 GURL new_url; |
379 tab_s->set_window_id(tab.GetWindowId()); | 386 AssociateTabContents(window, tab, session_tab, tab_s, &new_url); |
380 const int current_index = tab.GetCurrentEntryIndex(); | 387 |
381 const int min_index = std::max(0, | 388 // Trigger the favicon load if needed. We do this before opening the write |
382 current_index - kMaxSyncNavigationCount); | 389 // transaction to avoid jank. |
383 const int max_index = std::min(current_index + kMaxSyncNavigationCount, | 390 tab_link->set_url(new_url); |
384 tab.GetEntryCount()); | 391 if (new_url != old_tab_url) { |
385 const int pending_index = tab.GetPendingEntryIndex(); | 392 LoadFaviconForTab(tab_link); |
386 tab_s->set_pinned(window.IsTabPinned(&tab)); | |
387 if (tab.HasExtensionAppId()) { | |
388 tab_s->set_extension_app_id(tab.GetExtensionAppId()); | |
389 } | 393 } |
390 tab_s->mutable_navigation()->Clear(); | |
391 for (int i = min_index; i < max_index; ++i) { | |
392 const NavigationEntry* entry = (i == pending_index) ? | |
393 tab.GetPendingEntry() : tab.GetEntryAtIndex(i); | |
394 DCHECK(entry); | |
395 if (entry->GetVirtualURL().is_valid()) { | |
396 if (i == current_index && entry->GetVirtualURL().is_valid()) { | |
397 tab_link->set_url(entry->GetVirtualURL()); | |
398 DVLOG(1) << "Associating tab " << tab_id << " with sync id " << sync_id | |
399 << ", url " << entry->GetVirtualURL().spec() | |
400 << " and title " << entry->GetTitle(); | |
401 } | |
402 TabNavigation tab_nav; | |
403 tab_nav.SetFromNavigationEntry(*entry); | |
404 sync_pb::TabNavigation* nav_s = tab_s->add_navigation(); | |
405 PopulateSessionSpecificsNavigation(&tab_nav, nav_s); | |
406 } | |
407 } | |
408 tab_s->set_current_navigation_index(current_index); | |
409 | 394 |
410 // Convert to a local representation and store in synced session tracker for | 395 // Update our last modified time. |
411 // bookkeeping purposes. | |
412 SessionTab* session_tab = | |
413 synced_session_tracker_.GetTab(GetCurrentMachineTag(), | |
414 tab_s->tab_id()); | |
415 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = | 396 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = |
416 base::Time::Now(); | 397 base::Time::Now(); |
417 PopulateSessionTabFromSpecifics(*tab_s, | |
418 base::Time::Now(), | |
419 session_tab); | |
420 | |
421 // If the url changed, kick off the favicon load for the new url. | |
422 bool url_changed = false; | |
423 if (tab_link->url().is_valid() && tab_link->url() != old_tab_url) { | |
424 url_changed = true; | |
425 LoadFaviconForTab(tab_link); | |
426 } | |
427 | 398 |
428 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 399 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
429 sync_api::WriteNode tab_node(&trans); | 400 sync_api::WriteNode tab_node(&trans); |
430 if (!tab_node.InitByIdLookup(sync_id)) { | 401 if (!tab_node.InitByIdLookup(sync_id)) { |
431 if (error) { | 402 if (error) { |
432 *error = error_handler_->CreateAndUploadError( | 403 *error = error_handler_->CreateAndUploadError( |
433 FROM_HERE, | 404 FROM_HERE, |
434 "Failed to look up local tab node", | 405 "Failed to look up local tab node", |
435 model_type()); | 406 model_type()); |
436 } | 407 } |
437 return false; | 408 return false; |
438 } | 409 } |
439 | 410 |
440 // Preserve the existing favicon only if the url didn't change. | 411 if (new_url == old_tab_url) { |
441 if (!url_changed) { | 412 // Load the old specifics and copy over the favicon data if needed. |
442 tab_s->set_favicon(tab_node.GetSessionSpecifics().tab().favicon()); | 413 // TODO(zea): store local favicons in the |synced_favicons_| map and use |
443 tab_s->set_favicon_source( | 414 // that instead of reading from sync. This will be necessary to switch to |
444 tab_node.GetSessionSpecifics().tab().favicon_source()); | 415 // the new api. |
445 } // else store the empty favicon data back in. | 416 const sync_pb::SessionSpecifics old_specifics = |
Andrew T Wilson (Slow)
2012/04/23 23:43:11
Does this imply if there's a pending load for the
Nicolas Zea
2012/04/24 22:09:49
Yes. Either we've already loaded the favicon for t
| |
417 tab_node.GetSessionSpecifics(); | |
418 tab_s->set_favicon(old_specifics.tab().favicon()); | |
419 tab_s->set_favicon_source(old_specifics.tab().favicon_source()); | |
420 } | |
446 | 421 |
447 // Write into the actual sync model. | 422 // Write into the actual sync model. |
448 tab_node.SetSessionSpecifics(session_s); | 423 tab_node.SetSessionSpecifics(session_s); |
449 | 424 |
450 return true; | 425 return true; |
451 } | 426 } |
452 | 427 |
428 // Builds |sync_tab| by combining data from |prev_tab| and |new_tab|. Updates | |
429 // |prev_tab| to reflect the newest version. | |
430 // Timestamps are chosen from either |prev_tab| or base::Time::Now() based on | |
431 // the following rules: | |
432 // 1. If a navigation exists in both |new_tab| and |prev_tab|, as determined | |
433 // by the unique id, and the navigation didn't just become the current | |
434 // navigation, we preserve the old timestamp. | |
435 // 2. If the navigation exists in both but just become the current navigation | |
436 // (e.g. the user went back in history to this navigation), we update the | |
437 // timestamp to Now(). | |
438 // 3. All new navigations not present in |prev_tab| have their timestamps set to | |
439 // Now(). | |
440 void SessionModelAssociator::AssociateTabContents( | |
441 const SyncedWindowDelegate& window, | |
442 const SyncedTabDelegate& new_tab, | |
443 SyncedSessionTab* prev_tab, | |
444 sync_pb::SessionTab* sync_tab, | |
445 GURL* new_url) { | |
446 DCHECK(prev_tab); | |
447 DCHECK(sync_tab); | |
448 DCHECK(new_url); | |
449 SessionID::id_type tab_id = new_tab.GetSessionId(); | |
450 sync_tab->set_tab_id(tab_id); | |
451 sync_tab->set_window_id(new_tab.GetWindowId()); | |
452 const int current_index = new_tab.GetCurrentEntryIndex(); | |
453 sync_tab->set_current_navigation_index(current_index); | |
454 const int min_index = std::max(0, | |
455 current_index - kMaxSyncNavigationCount); | |
456 const int max_index = std::min(current_index + kMaxSyncNavigationCount, | |
457 new_tab.GetEntryCount()); | |
458 const int pending_index = new_tab.GetPendingEntryIndex(); | |
459 sync_tab->set_pinned(window.IsTabPinned(&new_tab)); | |
460 if (new_tab.HasExtensionAppId()) { | |
461 sync_tab->set_extension_app_id(new_tab.GetExtensionAppId()); | |
462 } | |
463 | |
464 sync_tab->mutable_navigation()->Clear(); | |
465 std::vector<SyncedTabNavigation>::const_iterator prev_nav_iter; | |
466 for (int i = min_index; i < max_index; ++i) { | |
467 const NavigationEntry* entry = (i == pending_index) ? | |
468 new_tab.GetPendingEntry() : new_tab.GetEntryAtIndex(i); | |
469 DCHECK(entry); | |
470 if (i == min_index) { | |
471 // Find the location of the first navigation within the previous list of | |
Andrew T Wilson (Slow)
2012/04/23 23:43:11
I was trying to see if there's a good way to move
Nicolas Zea
2012/04/24 22:09:49
Yeah, if I did I'd have to load the entry anyways,
| |
472 // navigations. We only need to do this once, as all subsequent | |
473 // navigations are either contiguous or completely new. | |
474 for (prev_nav_iter = prev_tab->synced_tab_navigations.begin(); | |
475 prev_nav_iter != prev_tab->synced_tab_navigations.end(); | |
476 ++prev_nav_iter) { | |
477 if (prev_nav_iter->unique_id() == entry->GetUniqueID()) | |
478 break; | |
479 } | |
480 } | |
481 if (entry->GetVirtualURL().is_valid()) { | |
482 if (i == current_index) { | |
483 *new_url = GURL(entry->GetVirtualURL().spec()); | |
484 DVLOG(1) << "Associating local tab " << new_tab.GetSessionId() | |
485 << " with url " << new_url->spec() << " and title " | |
486 << entry->GetTitle(); | |
487 | |
488 } | |
489 sync_pb::TabNavigation* sync_nav = sync_tab->add_navigation(); | |
490 PopulateSessionSpecificsNavigation(*entry, sync_nav); | |
491 | |
492 // If this navigation is an old one, reuse the old timestamp. Otherwise we | |
493 // leave the timestamp as the current time. | |
494 if (prev_nav_iter != prev_tab->synced_tab_navigations.end() && | |
495 prev_nav_iter->unique_id() == entry->GetUniqueID()) { | |
496 // Check that we haven't gone back/foward in the nav stack to this page | |
497 // (if so, we want to refresh the timestamp). | |
498 if (!(current_index != prev_tab->current_navigation_index && | |
499 current_index == i)) { | |
500 sync_nav->set_timestamp(TimeToProtoTime(prev_nav_iter->timestamp())); | |
501 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, " | |
502 << "reusing old timestamp " << sync_nav->timestamp(); | |
503 } | |
504 // Even if the user went back in their history, they may have skipped | |
505 // over navigations, so the subsequent navigation entries may need their | |
506 // old timestamps preserved. | |
507 ++prev_nav_iter; | |
508 } | |
509 } | |
510 } | |
511 | |
512 // Now update our local version with the newest data. | |
513 PopulateSessionTabFromSpecifics(*sync_tab, | |
514 base::Time::Now(), | |
515 prev_tab); | |
516 } | |
517 | |
453 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { | 518 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { |
454 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 519 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
455 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) | 520 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) |
456 return; | 521 return; |
457 FaviconService* favicon_service = | 522 FaviconService* favicon_service = |
458 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 523 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
459 if (!favicon_service) | 524 if (!favicon_service) |
460 return; | 525 return; |
461 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); | 526 SessionID::id_type tab_id = tab_link->tab()->GetSessionId(); |
462 if (tab_link->favicon_load_handle()) { | 527 if (tab_link->favicon_load_handle()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 LoadFaviconForTab(tab_iter->second.get()); | 617 LoadFaviconForTab(tab_iter->second.get()); |
553 } | 618 } |
554 } | 619 } |
555 } | 620 } |
556 } | 621 } |
557 | 622 |
558 // Static | 623 // Static |
559 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 624 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
560 // See http://crbug.com/67068. | 625 // See http://crbug.com/67068. |
561 void SessionModelAssociator::PopulateSessionSpecificsNavigation( | 626 void SessionModelAssociator::PopulateSessionSpecificsNavigation( |
562 const TabNavigation* navigation, | 627 const NavigationEntry& navigation, |
563 sync_pb::TabNavigation* tab_navigation) { | 628 sync_pb::TabNavigation* tab_navigation) { |
564 tab_navigation->set_index(navigation->index()); | 629 tab_navigation->set_virtual_url(navigation.GetVirtualURL().spec()); |
565 tab_navigation->set_virtual_url(navigation->virtual_url().spec()); | |
566 // FIXME(zea): Support referrer policy? | 630 // FIXME(zea): Support referrer policy? |
567 tab_navigation->set_referrer(navigation->referrer().url.spec()); | 631 tab_navigation->set_referrer(navigation.GetReferrer().url.spec()); |
568 tab_navigation->set_title(UTF16ToUTF8(navigation->title())); | 632 tab_navigation->set_title(UTF16ToUTF8(navigation.GetTitle())); |
569 switch (navigation->transition()) { | 633 switch (navigation.GetTransitionType()) { |
570 case content::PAGE_TRANSITION_LINK: | 634 case content::PAGE_TRANSITION_LINK: |
571 tab_navigation->set_page_transition( | 635 tab_navigation->set_page_transition( |
572 sync_pb::TabNavigation_PageTransition_LINK); | 636 sync_pb::TabNavigation_PageTransition_LINK); |
573 break; | 637 break; |
574 case content::PAGE_TRANSITION_TYPED: | 638 case content::PAGE_TRANSITION_TYPED: |
575 tab_navigation->set_page_transition( | 639 tab_navigation->set_page_transition( |
576 sync_pb::TabNavigation_PageTransition_TYPED); | 640 sync_pb::TabNavigation_PageTransition_TYPED); |
577 break; | 641 break; |
578 case content::PAGE_TRANSITION_AUTO_BOOKMARK: | 642 case content::PAGE_TRANSITION_AUTO_BOOKMARK: |
579 tab_navigation->set_page_transition( | 643 tab_navigation->set_page_transition( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 sync_pb::TabNavigation_PageTransitionQualifier_CLIENT_REDIRECT); | 688 sync_pb::TabNavigation_PageTransitionQualifier_CLIENT_REDIRECT); |
625 break; | 689 break; |
626 case content::PAGE_TRANSITION_SERVER_REDIRECT: | 690 case content::PAGE_TRANSITION_SERVER_REDIRECT: |
627 tab_navigation->set_navigation_qualifier( | 691 tab_navigation->set_navigation_qualifier( |
628 sync_pb::TabNavigation_PageTransitionQualifier_SERVER_REDIRECT); | 692 sync_pb::TabNavigation_PageTransitionQualifier_SERVER_REDIRECT); |
629 break; | 693 break; |
630 default: | 694 default: |
631 tab_navigation->set_page_transition( | 695 tab_navigation->set_page_transition( |
632 sync_pb::TabNavigation_PageTransition_TYPED); | 696 sync_pb::TabNavigation_PageTransition_TYPED); |
633 } | 697 } |
698 tab_navigation->set_unique_id(navigation.GetUniqueID()); | |
699 tab_navigation->set_timestamp(TimeToProtoTime(base::Time::Now())); | |
634 } | 700 } |
635 | 701 |
636 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, | 702 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, |
637 int64 sync_id) { | 703 int64 sync_id) { |
638 NOTIMPLEMENTED(); | 704 NOTIMPLEMENTED(); |
639 } | 705 } |
640 | 706 |
641 void SessionModelAssociator::Disassociate(int64 sync_id) { | 707 void SessionModelAssociator::Disassociate(int64 sync_id) { |
642 DCHECK(CalledOnValidThread()); | 708 DCHECK(CalledOnValidThread()); |
643 NOTIMPLEMENTED(); | 709 NOTIMPLEMENTED(); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 modification_time, | 962 modification_time, |
897 foreign_session->windows[window_id], | 963 foreign_session->windows[window_id], |
898 &synced_session_tracker_); | 964 &synced_session_tracker_); |
899 } | 965 } |
900 | 966 |
901 // Delete any closed windows and unused tabs as necessary. | 967 // Delete any closed windows and unused tabs as necessary. |
902 synced_session_tracker_.CleanupSession(foreign_session_tag); | 968 synced_session_tracker_.CleanupSession(foreign_session_tag); |
903 } else if (specifics.has_tab()) { | 969 } else if (specifics.has_tab()) { |
904 const sync_pb::SessionTab& tab_s = specifics.tab(); | 970 const sync_pb::SessionTab& tab_s = specifics.tab(); |
905 SessionID::id_type tab_id = tab_s.tab_id(); | 971 SessionID::id_type tab_id = tab_s.tab_id(); |
906 SessionTab* tab = | 972 SyncedSessionTab* tab = |
907 synced_session_tracker_.GetTab(foreign_session_tag, tab_id); | 973 synced_session_tracker_.GetTab(foreign_session_tag, tab_id); |
908 | 974 |
909 // Figure out what the previous url for this tab was (may be empty string | 975 // Figure out what the previous url for this tab was (may be empty string |
910 // if this is a new tab). | 976 // if this is a new tab). |
911 std::string previous_url; | 977 std::string previous_url; |
912 if (tab->navigations.size() > 0) { | 978 if (tab->navigations.size() > 0) { |
913 int selected_index = tab->current_navigation_index; | 979 int selected_index = tab->current_navigation_index; |
914 selected_index = std::max( | 980 selected_index = std::max( |
915 0, | 981 0, |
916 std::min(selected_index, | 982 std::min(selected_index, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 session_window->window_id.id(), | 1116 session_window->window_id.id(), |
1051 tab_id, | 1117 tab_id, |
1052 i); | 1118 i); |
1053 } | 1119 } |
1054 } | 1120 } |
1055 | 1121 |
1056 // Static | 1122 // Static |
1057 void SessionModelAssociator::PopulateSessionTabFromSpecifics( | 1123 void SessionModelAssociator::PopulateSessionTabFromSpecifics( |
1058 const sync_pb::SessionTab& specifics, | 1124 const sync_pb::SessionTab& specifics, |
1059 const base::Time& mtime, | 1125 const base::Time& mtime, |
1060 SessionTab* tab) { | 1126 SyncedSessionTab* tab) { |
1061 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); | 1127 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); |
1062 if (specifics.has_tab_id()) | 1128 if (specifics.has_tab_id()) |
1063 tab->tab_id.set_id(specifics.tab_id()); | 1129 tab->tab_id.set_id(specifics.tab_id()); |
1064 if (specifics.has_window_id()) | 1130 if (specifics.has_window_id()) |
1065 tab->window_id.set_id(specifics.window_id()); | 1131 tab->window_id.set_id(specifics.window_id()); |
1066 if (specifics.has_tab_visual_index()) | 1132 if (specifics.has_tab_visual_index()) |
1067 tab->tab_visual_index = specifics.tab_visual_index(); | 1133 tab->tab_visual_index = specifics.tab_visual_index(); |
1068 if (specifics.has_current_navigation_index()) | 1134 if (specifics.has_current_navigation_index()) |
1069 tab->current_navigation_index = specifics.current_navigation_index(); | 1135 tab->current_navigation_index = specifics.current_navigation_index(); |
1070 if (specifics.has_pinned()) | 1136 if (specifics.has_pinned()) |
1071 tab->pinned = specifics.pinned(); | 1137 tab->pinned = specifics.pinned(); |
1072 if (specifics.has_extension_app_id()) | 1138 if (specifics.has_extension_app_id()) |
1073 tab->extension_app_id = specifics.extension_app_id(); | 1139 tab->extension_app_id = specifics.extension_app_id(); |
1074 tab->timestamp = mtime; | 1140 tab->timestamp = mtime; |
1075 tab->navigations.clear(); // In case we are reusing a previous SessionTab. | 1141 // Cleared in case we reuse a pre-existing SyncedSessionTab object. |
1076 for (int i = 0; i < specifics.navigation_size(); i++) { | 1142 tab->navigations.clear(); |
1077 AppendSessionTabNavigation(specifics.navigation(i), &tab->navigations); | 1143 tab->synced_tab_navigations.clear(); |
1144 for (int i = 0; i < specifics.navigation_size(); ++i) { | |
1145 AppendSessionTabNavigation(specifics.navigation(i), | |
1146 tab); | |
1078 } | 1147 } |
1079 } | 1148 } |
1080 | 1149 |
1081 // Static | 1150 // Static |
1082 void SessionModelAssociator::AppendSessionTabNavigation( | 1151 void SessionModelAssociator::AppendSessionTabNavigation( |
1083 const sync_pb::TabNavigation& specifics, | 1152 const sync_pb::TabNavigation& specifics, |
1084 std::vector<TabNavigation>* navigations) { | 1153 SyncedSessionTab* tab) { |
1085 int index = 0; | 1154 int index = 0; |
1086 GURL virtual_url; | 1155 GURL virtual_url; |
1087 GURL referrer; | 1156 GURL referrer; |
1088 string16 title; | 1157 string16 title; |
1089 std::string state; | 1158 std::string state; |
1090 content::PageTransition transition(content::PAGE_TRANSITION_LINK); | 1159 content::PageTransition transition(content::PAGE_TRANSITION_LINK); |
1091 if (specifics.has_index()) | 1160 base::Time timestamp; |
1092 index = specifics.index(); | 1161 int unique_id = 0; |
1093 if (specifics.has_virtual_url()) { | 1162 if (specifics.has_virtual_url()) { |
1094 GURL gurl(specifics.virtual_url()); | 1163 GURL gurl(specifics.virtual_url()); |
1095 virtual_url = gurl; | 1164 virtual_url = gurl; |
1096 } | 1165 } |
1097 if (specifics.has_referrer()) { | 1166 if (specifics.has_referrer()) { |
1098 GURL gurl(specifics.referrer()); | 1167 GURL gurl(specifics.referrer()); |
1099 referrer = gurl; | 1168 referrer = gurl; |
1100 } | 1169 } |
1101 if (specifics.has_title()) | 1170 if (specifics.has_title()) |
1102 title = UTF8ToUTF16(specifics.title()); | 1171 title = UTF8ToUTF16(specifics.title()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 break; | 1221 break; |
1153 case sync_pb:: | 1222 case sync_pb:: |
1154 TabNavigation_PageTransitionQualifier_SERVER_REDIRECT: | 1223 TabNavigation_PageTransitionQualifier_SERVER_REDIRECT: |
1155 transition = content::PAGE_TRANSITION_SERVER_REDIRECT; | 1224 transition = content::PAGE_TRANSITION_SERVER_REDIRECT; |
1156 break; | 1225 break; |
1157 default: | 1226 default: |
1158 transition = content::PAGE_TRANSITION_TYPED; | 1227 transition = content::PAGE_TRANSITION_TYPED; |
1159 } | 1228 } |
1160 } | 1229 } |
1161 } | 1230 } |
1162 TabNavigation tab_navigation( | 1231 if (specifics.has_timestamp()) { |
1232 timestamp = ProtoTimeToTime(specifics.timestamp()); | |
1233 } | |
1234 if (specifics.has_unique_id()) { | |
1235 unique_id = specifics.unique_id(); | |
1236 } | |
1237 SyncedTabNavigation tab_navigation( | |
1163 index, virtual_url, | 1238 index, virtual_url, |
1164 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title, | 1239 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), title, |
1165 state, transition); | 1240 state, transition, unique_id, timestamp); |
1166 navigations->insert(navigations->end(), tab_navigation); | 1241 // We insert it twice, once for our SyncedTabNavigations, once for the normal |
1242 // TabNavigation (used by the session restore UI). | |
1243 tab->synced_tab_navigations.insert(tab->synced_tab_navigations.end(), | |
1244 tab_navigation); | |
1245 tab->navigations.insert(tab->navigations.end(), | |
1246 tab_navigation); | |
1167 } | 1247 } |
1168 | 1248 |
1169 void SessionModelAssociator::LoadForeignTabFavicon( | 1249 void SessionModelAssociator::LoadForeignTabFavicon( |
1170 const sync_pb::SessionTab& tab) { | 1250 const sync_pb::SessionTab& tab) { |
1171 if (!tab.has_favicon() || tab.favicon().empty()) | 1251 if (!tab.has_favicon() || tab.favicon().empty()) |
1172 return; | 1252 return; |
1173 if (!tab.has_favicon_type() || | 1253 if (!tab.has_favicon_type() || |
1174 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { | 1254 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { |
1175 DVLOG(1) << "Ignoring non-web favicon."; | 1255 DVLOG(1) << "Ignoring non-web favicon."; |
1176 return; | 1256 return; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 std::vector<const SessionWindow*>* windows) { | 1380 std::vector<const SessionWindow*>* windows) { |
1301 DCHECK(CalledOnValidThread()); | 1381 DCHECK(CalledOnValidThread()); |
1302 return synced_session_tracker_.LookupSessionWindows(tag, windows); | 1382 return synced_session_tracker_.LookupSessionWindows(tag, windows); |
1303 } | 1383 } |
1304 | 1384 |
1305 bool SessionModelAssociator::GetForeignTab( | 1385 bool SessionModelAssociator::GetForeignTab( |
1306 const std::string& tag, | 1386 const std::string& tag, |
1307 const SessionID::id_type tab_id, | 1387 const SessionID::id_type tab_id, |
1308 const SessionTab** tab) { | 1388 const SessionTab** tab) { |
1309 DCHECK(CalledOnValidThread()); | 1389 DCHECK(CalledOnValidThread()); |
1310 return synced_session_tracker_.LookupSessionTab(tag, tab_id, tab); | 1390 const SyncedSessionTab* synced_tab; |
1391 bool success = synced_session_tracker_.LookupSessionTab(tag, | |
1392 tab_id, | |
1393 &synced_tab); | |
1394 if (success) | |
1395 *tab = synced_tab; | |
1396 return success; | |
1311 } | 1397 } |
1312 | 1398 |
1313 void SessionModelAssociator::DeleteStaleSessions() { | 1399 void SessionModelAssociator::DeleteStaleSessions() { |
1314 DCHECK(CalledOnValidThread()); | 1400 DCHECK(CalledOnValidThread()); |
1315 std::vector<const SyncedSession*> sessions; | 1401 std::vector<const SyncedSession*> sessions; |
1316 if (!GetAllForeignSessions(&sessions)) | 1402 if (!GetAllForeignSessions(&sessions)) |
1317 return; // No foreign sessions. | 1403 return; // No foreign sessions. |
1318 | 1404 |
1319 // Iterate through all the sessions and delete any with age older than | 1405 // Iterate through all the sessions and delete any with age older than |
1320 // |stale_session_threshold_days_|. | 1406 // |stale_session_threshold_days_|. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1449 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1535 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1450 // We only access the cryptographer while holding a transaction. | 1536 // We only access the cryptographer while holding a transaction. |
1451 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1537 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1452 const syncable::ModelTypeSet encrypted_types = | 1538 const syncable::ModelTypeSet encrypted_types = |
1453 sync_api::GetEncryptedTypes(&trans); | 1539 sync_api::GetEncryptedTypes(&trans); |
1454 return !encrypted_types.Has(SESSIONS) || | 1540 return !encrypted_types.Has(SESSIONS) || |
1455 sync_service_->IsCryptographerReady(&trans); | 1541 sync_service_->IsCryptographerReady(&trans); |
1456 } | 1542 } |
1457 | 1543 |
1458 } // namespace browser_sync | 1544 } // namespace browser_sync |
OLD | NEW |