Chromium Code Reviews| 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 tab_map_iter->second->set_tab(&tab); | 365 tab_map_iter->second->set_tab(&tab); |
| 366 } | 366 } |
| 367 DCHECK(tab_link); | 367 DCHECK(tab_link); |
| 368 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); | 368 DCHECK_NE(tab_link->sync_id(), syncer::kInvalidId); |
| 369 | 369 |
| 370 DVLOG(1) << "Reloading tab " << tab_id << " from window " | 370 DVLOG(1) << "Reloading tab " << tab_id << " from window " |
| 371 << tab.GetWindowId(); | 371 << tab.GetWindowId(); |
| 372 return WriteTabContentsToSyncModel(tab_link, error); | 372 return WriteTabContentsToSyncModel(tab_link, error); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // static | |
| 376 GURL SessionModelAssociator::GetCurrentVirtualURL( | |
| 377 const SyncedTabDelegate& tab_delegate) { | |
| 378 GURL new_url; | |
| 379 const int current_index = tab_delegate.GetCurrentEntryIndex(); | |
| 380 const int pending_index = tab_delegate.GetPendingEntryIndex(); | |
| 381 const NavigationEntry* current_entry = | |
| 382 (current_index == pending_index) ? | |
| 383 tab_delegate.GetPendingEntry() : | |
| 384 tab_delegate.GetEntryAtIndex(current_index); | |
| 385 return current_entry->GetVirtualURL(); | |
| 386 } | |
| 387 | |
| 375 bool SessionModelAssociator::WriteTabContentsToSyncModel( | 388 bool SessionModelAssociator::WriteTabContentsToSyncModel( |
| 376 TabLink* tab_link, | 389 TabLink* tab_link, |
| 377 syncer::SyncError* error) { | 390 syncer::SyncError* error) { |
| 378 DCHECK(CalledOnValidThread()); | 391 DCHECK(CalledOnValidThread()); |
| 379 const SyncedTabDelegate& tab = *(tab_link->tab()); | 392 const SyncedTabDelegate& tab_delegate = *(tab_link->tab()); |
| 380 const SyncedWindowDelegate& window = | |
| 381 *SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | |
| 382 tab.GetWindowId()); | |
| 383 int64 sync_id = tab_link->sync_id(); | 393 int64 sync_id = tab_link->sync_id(); |
| 384 GURL old_tab_url = tab_link->url(); | 394 GURL old_tab_url = tab_link->url(); |
| 385 | 395 |
| 386 // Load the last stored version of this tab so we can compare changes. If this | 396 // 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. | 397 // is a new tab, session_tab will be a blank/newly created SessionTab object. |
| 388 SessionTab* session_tab = | 398 SessionTab* session_tab = |
| 389 synced_session_tracker_.GetTab(GetCurrentMachineTag(), | 399 synced_session_tracker_.GetTab(GetCurrentMachineTag(), |
| 390 tab.GetSessionId()); | 400 tab_delegate.GetSessionId()); |
| 391 | 401 |
| 392 // We build a clean session tab specifics directly from the tab data. | 402 base::Time now = base::Time::Now(); |
| 393 sync_pb::SessionTab tab_s; | 403 UpdateSessionTabFromDelegate(tab_delegate, now, now, session_tab); |
| 394 | 404 |
| 395 GURL new_url; | 405 const GURL new_url = GetCurrentVirtualURL(tab_delegate); |
| 396 AssociateTabContents(window, tab, session_tab, &tab_s, &new_url); | 406 DVLOG(1) << "Local tab " << tab_delegate.GetSessionId() |
| 407 << " now has URL " << new_url.spec(); | |
| 397 | 408 |
| 398 // Trigger the favicon load if needed. We do this before opening the write | 409 // Trigger the favicon load if needed. We do this before opening the write |
| 399 // transaction to avoid jank. | 410 // transaction to avoid jank. |
| 400 tab_link->set_url(new_url); | 411 tab_link->set_url(new_url); |
| 401 if (new_url != old_tab_url) { | 412 if (new_url != old_tab_url) { |
| 402 LoadFaviconForTab(tab_link); | 413 LoadFaviconForTab(tab_link); |
| 403 } | 414 } |
| 404 | 415 |
| 405 // Update our last modified time. | 416 // Update our last modified time. |
| 406 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = | 417 synced_session_tracker_.GetSession(GetCurrentMachineTag())->modified_time = |
| 407 base::Time::Now(); | 418 base::Time::Now(); |
| 408 | 419 |
| 409 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 420 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 410 syncer::WriteNode tab_node(&trans); | 421 syncer::WriteNode tab_node(&trans); |
| 411 if (tab_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { | 422 if (tab_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { |
| 412 if (error) { | 423 if (error) { |
| 413 *error = error_handler_->CreateAndUploadError( | 424 *error = error_handler_->CreateAndUploadError( |
| 414 FROM_HERE, | 425 FROM_HERE, |
| 415 "Failed to look up local tab node", | 426 "Failed to look up local tab node", |
| 416 model_type()); | 427 model_type()); |
| 417 } | 428 } |
| 418 return false; | 429 return false; |
| 419 } | 430 } |
| 420 | 431 |
| 432 sync_pb::SessionTab tab_s = session_tab->ToSyncData(); | |
| 421 sync_pb::SessionSpecifics specifics = tab_node.GetSessionSpecifics(); | 433 sync_pb::SessionSpecifics specifics = tab_node.GetSessionSpecifics(); |
| 422 if (new_url == old_tab_url) { | 434 if (new_url == old_tab_url) { |
| 423 // Load the old specifics and copy over the favicon data if needed. | 435 // Load the old specifics and copy over the favicon data if needed. |
| 424 // TODO(zea): store local favicons in the |synced_favicons_| map and use | 436 // TODO(zea): store local favicons in the |synced_favicons_| map and use |
| 425 // that instead of reading from sync. This will be necessary to switch to | 437 // that instead of reading from sync. This will be necessary to switch to |
| 426 // the new api. | 438 // the new api. |
| 427 tab_s.set_favicon(specifics.tab().favicon()); | 439 tab_s.set_favicon(specifics.tab().favicon()); |
| 428 tab_s.set_favicon_source(specifics.tab().favicon_source()); | 440 tab_s.set_favicon_source(specifics.tab().favicon_source()); |
| 429 tab_s.set_favicon_type(specifics.tab().favicon_type()); | 441 tab_s.set_favicon_type(specifics.tab().favicon_type()); |
| 430 } | 442 } |
| 431 // Retain the base SessionSpecifics data (tag, tab_node_id, etc.), and just | 443 // Retain the base SessionSpecifics data (tag, tab_node_id, etc.), and just |
| 432 // write the new SessionTabSpecifics. | 444 // write the new SessionTabSpecifics. |
| 433 specifics.mutable_tab()->CopyFrom(tab_s); | 445 specifics.mutable_tab()->CopyFrom(tab_s); |
| 434 | 446 |
| 435 // Write into the actual sync model. | 447 // Write into the actual sync model. |
| 436 tab_node.SetSessionSpecifics(specifics); | 448 tab_node.SetSessionSpecifics(specifics); |
| 437 | 449 |
| 438 return true; | 450 return true; |
| 439 } | 451 } |
| 440 | 452 |
| 441 // Builds |sync_tab| by combining data from |prev_tab| and |new_tab|. Updates | 453 // Updates |session_tab| by combining existing data and new data from |
| 442 // |prev_tab| to reflect the newest version. | 454 // |tab_delegate|. |
| 443 // Timestamps are chosen from either |prev_tab| or base::Time::Now() based on | 455 // |
| 444 // the following rules: | 456 // Timestamps are chosen from either |session_tab| or |
| 445 // 1. If a navigation exists in both |new_tab| and |prev_tab|, as determined | 457 // |default_navigation_timestamp| based on the following rules: |
| 446 // by the unique id, and the navigation didn't just become the current | 458 // 1. If a navigation exists in both |tab_delegate| and |session_tab|, |
| 447 // navigation, we preserve the old timestamp. | 459 // as determined by the unique id, and the navigation didn't just |
| 460 // become the current navigation, we preserve the old timestamp. | |
| 448 // 2. If the navigation exists in both but just become the current navigation | 461 // 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 | 462 // (e.g. the user went back in history to this navigation), we update the |
| 450 // timestamp to Now(). | 463 // timestamp to |default_navigation_timestamp|. |
| 451 // 3. All new navigations not present in |prev_tab| have their timestamps set to | 464 // 3. All new navigations not present in |session_tab| have their |
| 452 // Now(). | 465 // timestamps set to |default_navigation_timestamp| (if they're the |
| 453 void SessionModelAssociator::AssociateTabContents( | 466 // current one) or nulled out (if not). |
| 454 const SyncedWindowDelegate& window, | 467 // |
| 455 const SyncedTabDelegate& new_tab, | 468 // static |
| 456 SessionTab* prev_tab, | 469 void SessionModelAssociator::UpdateSessionTabFromDelegate( |
| 457 sync_pb::SessionTab* sync_tab, | 470 const SyncedTabDelegate& tab_delegate, |
| 458 GURL* new_url) { | 471 base::Time mtime, |
| 459 DCHECK(prev_tab); | 472 base::Time default_navigation_timestamp, |
| 460 DCHECK(sync_tab); | 473 SessionTab* session_tab) { |
| 461 DCHECK(new_url); | 474 DCHECK(session_tab); |
| 462 SessionID::id_type tab_id = new_tab.GetSessionId(); | 475 session_tab->window_id.set_id(tab_delegate.GetWindowId()); |
| 463 sync_tab->set_tab_id(tab_id); | 476 session_tab->tab_id.set_id(tab_delegate.GetSessionId()); |
| 464 sync_tab->set_window_id(new_tab.GetWindowId()); | 477 session_tab->tab_visual_index = 0; |
| 465 const int current_index = new_tab.GetCurrentEntryIndex(); | 478 session_tab->current_navigation_index = tab_delegate.GetCurrentEntryIndex(); |
| 466 sync_tab->set_current_navigation_index(current_index); | 479 session_tab->pinned = tab_delegate.IsPinned(); |
| 480 session_tab->extension_app_id = tab_delegate.GetExtensionAppId(); | |
| 481 session_tab->user_agent_override.clear(); | |
| 482 session_tab->timestamp = mtime; | |
| 483 const int current_index = tab_delegate.GetCurrentEntryIndex(); | |
| 484 const int pending_index = tab_delegate.GetPendingEntryIndex(); | |
| 467 const int min_index = std::max(0, | 485 const int min_index = std::max(0, |
| 468 current_index - kMaxSyncNavigationCount); | 486 current_index - kMaxSyncNavigationCount); |
| 469 const int max_index = std::min(current_index + kMaxSyncNavigationCount, | 487 const int max_index = std::min(current_index + kMaxSyncNavigationCount, |
| 470 new_tab.GetEntryCount()); | 488 tab_delegate.GetEntryCount()); |
| 471 const int pending_index = new_tab.GetPendingEntryIndex(); | 489 std::vector<TabNavigation> previous_navigations; |
| 472 sync_tab->set_pinned(window.IsTabPinned(&new_tab)); | 490 previous_navigations.swap(session_tab->navigations); |
|
Nicolas Zea
2012/09/26 00:26:47
is there any reason you modify previous_navigation
akalin
2012/09/26 00:32:12
session_tab->navigations should be cleared and fil
Nicolas Zea
2012/09/26 00:35:16
Ah, right. Makes sense.
| |
| 473 if (new_tab.HasExtensionAppId()) { | |
| 474 sync_tab->set_extension_app_id(new_tab.GetExtensionAppId()); | |
| 475 } | |
| 476 | |
| 477 sync_tab->mutable_navigation()->Clear(); | |
| 478 std::vector<TabNavigation>::const_iterator prev_nav_iter = | 491 std::vector<TabNavigation>::const_iterator prev_nav_iter = |
| 479 prev_tab->navigations.begin(); | 492 previous_navigations.begin(); |
| 480 for (int i = min_index; i < max_index; ++i) { | 493 for (int i = min_index; i < max_index; ++i) { |
| 481 const NavigationEntry* entry = (i == pending_index) ? | 494 const NavigationEntry* entry = (i == pending_index) ? |
| 482 new_tab.GetPendingEntry() : new_tab.GetEntryAtIndex(i); | 495 tab_delegate.GetPendingEntry() : tab_delegate.GetEntryAtIndex(i); |
| 483 DCHECK(entry); | 496 DCHECK(entry); |
| 484 if (i == min_index) { | 497 if (i == min_index) { |
| 485 // Find the location of the first navigation within the previous list of | 498 // Find the location of the first navigation within the previous list of |
| 486 // navigations. We only need to do this once, as all subsequent | 499 // navigations. We only need to do this once, as all subsequent |
| 487 // navigations are either contiguous or completely new. | 500 // navigations are either contiguous or completely new. |
| 488 for (;prev_nav_iter != prev_tab->navigations.end(); | 501 for (;prev_nav_iter != previous_navigations.end(); |
| 489 ++prev_nav_iter) { | 502 ++prev_nav_iter) { |
| 490 if (prev_nav_iter->unique_id() == entry->GetUniqueID()) | 503 if (prev_nav_iter->unique_id() == entry->GetUniqueID()) |
| 491 break; | 504 break; |
| 492 } | 505 } |
| 493 } | 506 } |
| 494 if (entry->GetVirtualURL().is_valid()) { | 507 if (entry->GetVirtualURL().is_valid()) { |
| 495 if (i == current_index) { | 508 // TODO(akalin): Remove this logic once we have a timestamp in |
| 496 *new_url = GURL(entry->GetVirtualURL().spec()); | 509 // NavigationEntry (since we can just use those directly). |
| 497 DVLOG(1) << "Associating local tab " << new_tab.GetSessionId() | 510 base::Time timestamp; |
| 498 << " with url " << new_url->spec() << " and title " | |
| 499 << entry->GetTitle(); | |
| 500 | |
| 501 } | |
| 502 sync_pb::TabNavigation* sync_nav = sync_tab->add_navigation(); | |
| 503 const TabNavigation& navigation = | |
| 504 TabNavigation::FromNavigationEntry(i, *entry, base::Time::Now()); | |
| 505 *sync_nav = navigation.ToSyncData(); | |
| 506 | |
| 507 // If this navigation is an old one, reuse the old timestamp. Otherwise we | 511 // If this navigation is an old one, reuse the old timestamp. Otherwise we |
| 508 // leave the timestamp as the current time. | 512 // leave the timestamp as the current time. |
| 509 if (prev_nav_iter != prev_tab->navigations.end() && | 513 if (prev_nav_iter != previous_navigations.end() && |
| 510 prev_nav_iter->unique_id() == entry->GetUniqueID()) { | 514 prev_nav_iter->unique_id() == entry->GetUniqueID()) { |
| 511 // Check that we haven't gone back/foward in the nav stack to this page | 515 // Check that we haven't gone back/forward in the nav stack to this page |
| 512 // (if so, we want to refresh the timestamp). | 516 // (if so, we want to refresh the timestamp). |
| 513 if (!(current_index != prev_tab->current_navigation_index && | 517 if (!(current_index != session_tab->current_navigation_index && |
| 514 current_index == i)) { | 518 current_index == i)) { |
| 515 sync_nav->set_timestamp( | 519 timestamp = prev_nav_iter->timestamp(); |
| 516 syncer::TimeToProtoTime(prev_nav_iter->timestamp())); | 520 DVLOG(2) << "Nav to " << entry->GetVirtualURL() |
| 517 DVLOG(2) << "Nav to " << sync_nav->virtual_url() << " already known, " | 521 << " already known, reusing old timestamp " |
| 518 << "reusing old timestamp " << sync_nav->timestamp(); | 522 << timestamp.ToInternalValue(); |
| 519 } | 523 } |
| 520 // Even if the user went back in their history, they may have skipped | 524 // Even if the user went back in their history, they may have skipped |
| 521 // over navigations, so the subsequent navigation entries may need their | 525 // over navigations, so the subsequent navigation entries may need their |
| 522 // old timestamps preserved. | 526 // old timestamps preserved. |
| 523 ++prev_nav_iter; | 527 ++prev_nav_iter; |
| 524 } else if (current_index != i && | 528 } else if (current_index != i && previous_navigations.empty()) { |
| 525 prev_tab->navigations.empty()) { | |
| 526 // If this is a new tab, and has more than one navigation, we don't | 529 // If this is a new tab, and has more than one navigation, we don't |
| 527 // actually want to assign the current timestamp to other navigations. | 530 // actually want to assign the current timestamp to other navigations. |
| 528 // Override the timestamp to 0 in that case. | 531 // Override the timestamp to 0 in that case. |
| 529 // Note: this is primarily to handle restoring sessions at restart, | 532 // Note: this is primarily to handle restoring sessions at restart, |
| 530 // opening recently closed tabs, or opening tabs from other devices. | 533 // opening recently closed tabs, or opening tabs from other devices. |
| 531 // Only the current navigation should have a timestamp in those cases. | 534 // Only the current navigation should have a timestamp in those cases. |
| 532 sync_nav->set_timestamp(0); | 535 timestamp = base::Time(); |
| 536 } else { | |
| 537 timestamp = default_navigation_timestamp; | |
| 533 } | 538 } |
| 539 | |
| 540 session_tab->navigations.push_back( | |
| 541 TabNavigation::FromNavigationEntry(i, *entry, timestamp)); | |
| 534 } | 542 } |
| 535 } | 543 } |
| 536 | 544 session_tab->session_storage_persistent_id.clear(); |
| 537 // Now update our local version with the newest data. | |
| 538 PopulateSessionTabFromSpecifics(*sync_tab, | |
| 539 base::Time::Now(), | |
| 540 prev_tab); | |
| 541 } | 545 } |
| 542 | 546 |
| 543 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { | 547 void SessionModelAssociator::LoadFaviconForTab(TabLink* tab_link) { |
| 544 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 548 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 545 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) | 549 if (!command_line.HasSwitch(switches::kSyncTabFavicons)) |
| 546 return; | 550 return; |
| 547 FaviconService* favicon_service = | 551 FaviconService* favicon_service = |
| 548 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 552 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 549 if (!favicon_service) | 553 if (!favicon_service) |
| 550 return; | 554 return; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 if (tab->navigations[selected_index].virtual_url().is_valid()) | 967 if (tab->navigations[selected_index].virtual_url().is_valid()) |
| 964 previous_url = tab->navigations[selected_index].virtual_url().spec(); | 968 previous_url = tab->navigations[selected_index].virtual_url().spec(); |
| 965 if (synced_favicon_pages_.find(previous_url) == | 969 if (synced_favicon_pages_.find(previous_url) == |
| 966 synced_favicon_pages_.end()) { | 970 synced_favicon_pages_.end()) { |
| 967 // The previous url didn't have a favicon. No need to decrement it. | 971 // The previous url didn't have a favicon. No need to decrement it. |
| 968 previous_url.clear(); | 972 previous_url.clear(); |
| 969 } | 973 } |
| 970 } | 974 } |
| 971 | 975 |
| 972 // Update SessionTab based on protobuf. | 976 // Update SessionTab based on protobuf. |
| 973 PopulateSessionTabFromSpecifics(tab_s, modification_time, tab); | 977 tab->SetFromSyncData(tab_s, modification_time); |
| 974 | 978 |
| 975 // Loads the tab favicon, increments the usage counter, and updates | 979 // Loads the tab favicon, increments the usage counter, and updates |
| 976 // synced_favicon_pages_. | 980 // synced_favicon_pages_. |
| 977 LoadForeignTabFavicon(tab_s); | 981 LoadForeignTabFavicon(tab_s); |
| 978 | 982 |
| 979 // Now check to see if the favicon associated with the previous url is no | 983 // Now check to see if the favicon associated with the previous url is no |
| 980 // longer in use. This will have no effect if the current url matches the | 984 // longer in use. This will have no effect if the current url matches the |
| 981 // previous url (LoadForeignTabFavicon increments, this decrements, no net | 985 // previous url (LoadForeignTabFavicon increments, this decrements, no net |
| 982 // change in usage), or if the previous_url was not set (new tab). | 986 // change in usage), or if the previous_url was not set (new tab). |
| 983 DecrementAndCleanFaviconForURL(previous_url); | 987 DecrementAndCleanFaviconForURL(previous_url); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 << "triggered."; | 1035 << "triggered."; |
| 1032 return false; | 1036 return false; |
| 1033 } | 1037 } |
| 1034 DVLOG(1) << "Disassociating session " << foreign_session_tag; | 1038 DVLOG(1) << "Disassociating session " << foreign_session_tag; |
| 1035 return synced_session_tracker_.DeleteSession(foreign_session_tag); | 1039 return synced_session_tracker_.DeleteSession(foreign_session_tag); |
| 1036 } | 1040 } |
| 1037 | 1041 |
| 1038 // Static | 1042 // Static |
| 1039 void SessionModelAssociator::PopulateSessionHeaderFromSpecifics( | 1043 void SessionModelAssociator::PopulateSessionHeaderFromSpecifics( |
| 1040 const sync_pb::SessionHeader& header_specifics, | 1044 const sync_pb::SessionHeader& header_specifics, |
| 1041 const base::Time& mtime, | 1045 base::Time mtime, |
| 1042 SyncedSession* session_header) { | 1046 SyncedSession* session_header) { |
| 1043 if (header_specifics.has_client_name()) { | 1047 if (header_specifics.has_client_name()) { |
| 1044 session_header->session_name = header_specifics.client_name(); | 1048 session_header->session_name = header_specifics.client_name(); |
| 1045 } | 1049 } |
| 1046 if (header_specifics.has_device_type()) { | 1050 if (header_specifics.has_device_type()) { |
| 1047 switch (header_specifics.device_type()) { | 1051 switch (header_specifics.device_type()) { |
| 1048 case sync_pb::SessionHeader_DeviceType_TYPE_WIN: | 1052 case sync_pb::SessionHeader_DeviceType_TYPE_WIN: |
| 1049 session_header->device_type = SyncedSession::TYPE_WIN; | 1053 session_header->device_type = SyncedSession::TYPE_WIN; |
| 1050 break; | 1054 break; |
| 1051 case sync_pb::SessionHeader_DeviceType_TYPE_MAC: | 1055 case sync_pb::SessionHeader_DeviceType_TYPE_MAC: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1070 break; | 1074 break; |
| 1071 } | 1075 } |
| 1072 } | 1076 } |
| 1073 session_header->modified_time = mtime; | 1077 session_header->modified_time = mtime; |
| 1074 } | 1078 } |
| 1075 | 1079 |
| 1076 // Static | 1080 // Static |
| 1077 void SessionModelAssociator::PopulateSessionWindowFromSpecifics( | 1081 void SessionModelAssociator::PopulateSessionWindowFromSpecifics( |
| 1078 const std::string& session_tag, | 1082 const std::string& session_tag, |
| 1079 const sync_pb::SessionWindow& specifics, | 1083 const sync_pb::SessionWindow& specifics, |
| 1080 const base::Time& mtime, | 1084 base::Time mtime, |
| 1081 SessionWindow* session_window, | 1085 SessionWindow* session_window, |
| 1082 SyncedSessionTracker* tracker) { | 1086 SyncedSessionTracker* tracker) { |
| 1083 if (specifics.has_window_id()) | 1087 if (specifics.has_window_id()) |
| 1084 session_window->window_id.set_id(specifics.window_id()); | 1088 session_window->window_id.set_id(specifics.window_id()); |
| 1085 if (specifics.has_selected_tab_index()) | 1089 if (specifics.has_selected_tab_index()) |
| 1086 session_window->selected_tab_index = specifics.selected_tab_index(); | 1090 session_window->selected_tab_index = specifics.selected_tab_index(); |
| 1087 if (specifics.has_browser_type()) { | 1091 if (specifics.has_browser_type()) { |
| 1088 if (specifics.browser_type() == | 1092 if (specifics.browser_type() == |
| 1089 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { | 1093 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { |
| 1090 session_window->type = 1; | 1094 session_window->type = 1; |
| 1091 } else { | 1095 } else { |
| 1092 session_window->type = 2; | 1096 session_window->type = 2; |
| 1093 } | 1097 } |
| 1094 } | 1098 } |
| 1095 session_window->timestamp = mtime; | 1099 session_window->timestamp = mtime; |
| 1096 session_window->tabs.resize(specifics.tab_size(), NULL); | 1100 session_window->tabs.resize(specifics.tab_size(), NULL); |
| 1097 for (int i = 0; i < specifics.tab_size(); i++) { | 1101 for (int i = 0; i < specifics.tab_size(); i++) { |
| 1098 SessionID::id_type tab_id = specifics.tab(i); | 1102 SessionID::id_type tab_id = specifics.tab(i); |
| 1099 tracker->PutTabInWindow(session_tag, | 1103 tracker->PutTabInWindow(session_tag, |
| 1100 session_window->window_id.id(), | 1104 session_window->window_id.id(), |
| 1101 tab_id, | 1105 tab_id, |
| 1102 i); | 1106 i); |
| 1103 } | 1107 } |
| 1104 } | 1108 } |
| 1105 | 1109 |
| 1106 // Static | |
| 1107 void SessionModelAssociator::PopulateSessionTabFromSpecifics( | |
| 1108 const sync_pb::SessionTab& specifics, | |
| 1109 const base::Time& mtime, | |
| 1110 SessionTab* tab) { | |
| 1111 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); | |
| 1112 if (specifics.has_tab_id()) | |
| 1113 tab->tab_id.set_id(specifics.tab_id()); | |
| 1114 if (specifics.has_window_id()) | |
| 1115 tab->window_id.set_id(specifics.window_id()); | |
| 1116 if (specifics.has_tab_visual_index()) | |
| 1117 tab->tab_visual_index = specifics.tab_visual_index(); | |
| 1118 if (specifics.has_current_navigation_index()) | |
| 1119 tab->current_navigation_index = specifics.current_navigation_index(); | |
| 1120 if (specifics.has_pinned()) | |
| 1121 tab->pinned = specifics.pinned(); | |
| 1122 if (specifics.has_extension_app_id()) | |
| 1123 tab->extension_app_id = specifics.extension_app_id(); | |
| 1124 tab->timestamp = mtime; | |
| 1125 // Cleared in case we reuse a pre-existing SyncedSessionTab object. | |
| 1126 tab->navigations.clear(); | |
| 1127 for (int i = 0; i < specifics.navigation_size(); ++i) { | |
| 1128 tab->navigations.push_back( | |
| 1129 TabNavigation::FromSyncData(i, specifics.navigation(i))); | |
| 1130 } | |
| 1131 } | |
| 1132 | |
| 1133 void SessionModelAssociator::LoadForeignTabFavicon( | 1110 void SessionModelAssociator::LoadForeignTabFavicon( |
| 1134 const sync_pb::SessionTab& tab) { | 1111 const sync_pb::SessionTab& tab) { |
| 1135 if (!tab.has_favicon() || tab.favicon().empty()) | 1112 if (!tab.has_favicon() || tab.favicon().empty()) |
| 1136 return; | 1113 return; |
| 1137 if (!tab.has_favicon_type() || | 1114 if (!tab.has_favicon_type() || |
| 1138 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { | 1115 tab.favicon_type() != sync_pb::SessionTab::TYPE_WEB_FAVICON) { |
| 1139 DVLOG(1) << "Ignoring non-web favicon."; | 1116 DVLOG(1) << "Ignoring non-web favicon."; |
| 1140 return; | 1117 return; |
| 1141 } | 1118 } |
| 1142 if (tab.navigation_size() == 0) | 1119 if (tab.navigation_size() == 0) |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1421 | 1398 |
| 1422 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1399 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1423 // We only access the cryptographer while holding a transaction. | 1400 // We only access the cryptographer while holding a transaction. |
| 1424 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1401 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1425 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 1402 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
| 1426 return !encrypted_types.Has(SESSIONS) || | 1403 return !encrypted_types.Has(SESSIONS) || |
| 1427 sync_service_->IsCryptographerReady(&trans); | 1404 sync_service_->IsCryptographerReady(&trans); |
| 1428 } | 1405 } |
| 1429 | 1406 |
| 1430 } // namespace browser_sync | 1407 } // namespace browser_sync |
| OLD | NEW |