OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 *header_window = window_s; | 191 *header_window = window_s; |
192 | 192 |
193 // Update this window's representation in the synced session tracker. | 193 // Update this window's representation in the synced session tracker. |
194 if (window_num >= current_session->windows.size()) { | 194 if (window_num >= current_session->windows.size()) { |
195 // This a new window, create it. | 195 // This a new window, create it. |
196 current_session->windows.push_back(new SessionWindow()); | 196 current_session->windows.push_back(new SessionWindow()); |
197 } | 197 } |
198 PopulateSessionWindowFromSpecifics( | 198 PopulateSessionWindowFromSpecifics( |
199 local_tag, | 199 local_tag, |
200 window_s, | 200 window_s, |
201 base::Time::Now().ToInternalValue(), | 201 base::Time::Now(), |
202 current_session->windows[window_num++], | 202 current_session->windows[window_num++], |
203 &synced_session_tracker_); | 203 &synced_session_tracker_); |
204 } | 204 } |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 208 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
209 sync_api::WriteNode header_node(&trans); | 209 sync_api::WriteNode header_node(&trans); |
210 if (!header_node.InitByIdLookup(local_session_syncid_)) { | 210 if (!header_node.InitByIdLookup(local_session_syncid_)) { |
211 LOG(ERROR) << "Failed to load local session header node."; | 211 LOG(ERROR) << "Failed to load local session header node."; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 tab_s->set_current_navigation_index(current_index); | 331 tab_s->set_current_navigation_index(current_index); |
332 | 332 |
333 tab_node.SetSessionSpecifics(session_s); | 333 tab_node.SetSessionSpecifics(session_s); |
334 | 334 |
335 // Convert to a local representation and store in synced session tracker. | 335 // Convert to a local representation and store in synced session tracker. |
336 SessionTab* session_tab = | 336 SessionTab* session_tab = |
337 synced_session_tracker_.GetSessionTab(GetCurrentMachineTag(), | 337 synced_session_tracker_.GetSessionTab(GetCurrentMachineTag(), |
338 tab_s->tab_id(), | 338 tab_s->tab_id(), |
339 false); | 339 false); |
340 PopulateSessionTabFromSpecifics(*tab_s, | 340 PopulateSessionTabFromSpecifics(*tab_s, |
341 base::Time::Now().ToInternalValue(), | 341 base::Time::Now(), |
342 session_tab); | 342 session_tab); |
343 return true; | 343 return true; |
344 } | 344 } |
345 | 345 |
346 // Static | 346 // Static |
347 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 347 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
348 // See http://crbug.com/67068. | 348 // See http://crbug.com/67068. |
349 void SessionModelAssociator::PopulateSessionSpecificsNavigation( | 349 void SessionModelAssociator::PopulateSessionSpecificsNavigation( |
350 const TabNavigation* navigation, | 350 const TabNavigation* navigation, |
351 sync_pb::TabNavigation* tab_navigation) { | 351 sync_pb::TabNavigation* tab_navigation) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 int64 id = root.GetFirstChildId(); | 574 int64 id = root.GetFirstChildId(); |
575 while (id != sync_api::kInvalidId) { | 575 while (id != sync_api::kInvalidId) { |
576 sync_api::ReadNode sync_node(trans); | 576 sync_api::ReadNode sync_node(trans); |
577 if (!sync_node.InitByIdLookup(id)) { | 577 if (!sync_node.InitByIdLookup(id)) { |
578 LOG(ERROR) << "Failed to fetch sync node for id " << id; | 578 LOG(ERROR) << "Failed to fetch sync node for id " << id; |
579 return false; | 579 return false; |
580 } | 580 } |
581 | 581 |
582 const sync_pb::SessionSpecifics& specifics = | 582 const sync_pb::SessionSpecifics& specifics = |
583 sync_node.GetSessionSpecifics(); | 583 sync_node.GetSessionSpecifics(); |
584 const int64 modification_time = sync_node.GetModificationTime(); | 584 const base::Time& modification_time = sync_node.GetModificationTime(); |
585 if (specifics.session_tag() != GetCurrentMachineTag()) { | 585 if (specifics.session_tag() != GetCurrentMachineTag()) { |
586 if (!AssociateForeignSpecifics(specifics, modification_time)) { | 586 if (!AssociateForeignSpecifics(specifics, modification_time)) { |
587 return false; | 587 return false; |
588 } | 588 } |
589 } else if (id != local_session_syncid_) { | 589 } else if (id != local_session_syncid_) { |
590 // This is previously stored local session information. | 590 // This is previously stored local session information. |
591 if (specifics.has_header()) { | 591 if (specifics.has_header()) { |
592 if (sync_api::kInvalidId != local_session_syncid_) | 592 if (sync_api::kInvalidId != local_session_syncid_) |
593 return false; | 593 return false; |
594 | 594 |
(...skipping 18 matching lines...) Expand all Loading... |
613 | 613 |
614 // After updating from sync model all tabid's should be free. | 614 // After updating from sync model all tabid's should be free. |
615 if (!tab_pool_.full()) | 615 if (!tab_pool_.full()) |
616 return false; | 616 return false; |
617 | 617 |
618 return true; | 618 return true; |
619 } | 619 } |
620 | 620 |
621 bool SessionModelAssociator::AssociateForeignSpecifics( | 621 bool SessionModelAssociator::AssociateForeignSpecifics( |
622 const sync_pb::SessionSpecifics& specifics, | 622 const sync_pb::SessionSpecifics& specifics, |
623 const int64 modification_time) { | 623 const base::Time& modification_time) { |
624 DCHECK(CalledOnValidThread()); | 624 DCHECK(CalledOnValidThread()); |
625 std::string foreign_session_tag = specifics.session_tag(); | 625 std::string foreign_session_tag = specifics.session_tag(); |
626 if (foreign_session_tag == GetCurrentMachineTag() && !setup_for_test_) | 626 if (foreign_session_tag == GetCurrentMachineTag() && !setup_for_test_) |
627 return false; | 627 return false; |
628 | 628 |
629 if (specifics.has_header()) { | 629 if (specifics.has_header()) { |
630 // Read in the header data for this foreign session. | 630 // Read in the header data for this foreign session. |
631 // Header data contains window information and ordered tab id's for each | 631 // Header data contains window information and ordered tab id's for each |
632 // window. | 632 // window. |
633 | 633 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 session_header->device_type = SyncedSession::TYPE_OTHER; | 707 session_header->device_type = SyncedSession::TYPE_OTHER; |
708 break; | 708 break; |
709 } | 709 } |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 // Static | 713 // Static |
714 void SessionModelAssociator::PopulateSessionWindowFromSpecifics( | 714 void SessionModelAssociator::PopulateSessionWindowFromSpecifics( |
715 const std::string& session_tag, | 715 const std::string& session_tag, |
716 const sync_pb::SessionWindow& specifics, | 716 const sync_pb::SessionWindow& specifics, |
717 int64 mtime, | 717 const base::Time& mtime, |
718 SessionWindow* session_window, | 718 SessionWindow* session_window, |
719 SyncedSessionTracker* tracker) { | 719 SyncedSessionTracker* tracker) { |
720 if (specifics.has_window_id()) | 720 if (specifics.has_window_id()) |
721 session_window->window_id.set_id(specifics.window_id()); | 721 session_window->window_id.set_id(specifics.window_id()); |
722 if (specifics.has_selected_tab_index()) | 722 if (specifics.has_selected_tab_index()) |
723 session_window->selected_tab_index = specifics.selected_tab_index(); | 723 session_window->selected_tab_index = specifics.selected_tab_index(); |
724 if (specifics.has_browser_type()) { | 724 if (specifics.has_browser_type()) { |
725 if (specifics.browser_type() == | 725 if (specifics.browser_type() == |
726 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { | 726 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { |
727 session_window->type = 1; | 727 session_window->type = 1; |
728 } else { | 728 } else { |
729 session_window->type = 2; | 729 session_window->type = 2; |
730 } | 730 } |
731 } | 731 } |
732 session_window->timestamp = base::Time::FromInternalValue(mtime); | 732 session_window->timestamp = mtime; |
733 session_window->tabs.resize(specifics.tab_size()); | 733 session_window->tabs.resize(specifics.tab_size()); |
734 for (int i = 0; i < specifics.tab_size(); i++) { | 734 for (int i = 0; i < specifics.tab_size(); i++) { |
735 SessionID::id_type tab_id = specifics.tab(i); | 735 SessionID::id_type tab_id = specifics.tab(i); |
736 session_window->tabs[i] = | 736 session_window->tabs[i] = |
737 tracker->GetSessionTab(session_tag, tab_id, true); | 737 tracker->GetSessionTab(session_tag, tab_id, true); |
738 } | 738 } |
739 } | 739 } |
740 | 740 |
741 // Static | 741 // Static |
742 void SessionModelAssociator::PopulateSessionTabFromSpecifics( | 742 void SessionModelAssociator::PopulateSessionTabFromSpecifics( |
743 const sync_pb::SessionTab& specifics, | 743 const sync_pb::SessionTab& specifics, |
744 const int64 mtime, | 744 const base::Time& mtime, |
745 SessionTab* tab) { | 745 SessionTab* tab) { |
746 if (specifics.has_tab_id()) | 746 if (specifics.has_tab_id()) |
747 tab->tab_id.set_id(specifics.tab_id()); | 747 tab->tab_id.set_id(specifics.tab_id()); |
748 if (specifics.has_window_id()) | 748 if (specifics.has_window_id()) |
749 tab->window_id.set_id(specifics.window_id()); | 749 tab->window_id.set_id(specifics.window_id()); |
750 if (specifics.has_tab_visual_index()) | 750 if (specifics.has_tab_visual_index()) |
751 tab->tab_visual_index = specifics.tab_visual_index(); | 751 tab->tab_visual_index = specifics.tab_visual_index(); |
752 if (specifics.has_current_navigation_index()) | 752 if (specifics.has_current_navigation_index()) |
753 tab->current_navigation_index = specifics.current_navigation_index(); | 753 tab->current_navigation_index = specifics.current_navigation_index(); |
754 if (specifics.has_pinned()) | 754 if (specifics.has_pinned()) |
755 tab->pinned = specifics.pinned(); | 755 tab->pinned = specifics.pinned(); |
756 if (specifics.has_extension_app_id()) | 756 if (specifics.has_extension_app_id()) |
757 tab->extension_app_id = specifics.extension_app_id(); | 757 tab->extension_app_id = specifics.extension_app_id(); |
758 tab->timestamp = base::Time::FromInternalValue(mtime); | 758 tab->timestamp = mtime; |
759 tab->navigations.clear(); // In case we are reusing a previous SessionTab. | 759 tab->navigations.clear(); // In case we are reusing a previous SessionTab. |
760 for (int i = 0; i < specifics.navigation_size(); i++) { | 760 for (int i = 0; i < specifics.navigation_size(); i++) { |
761 AppendSessionTabNavigation(specifics.navigation(i), &tab->navigations); | 761 AppendSessionTabNavigation(specifics.navigation(i), &tab->navigations); |
762 } | 762 } |
763 } | 763 } |
764 | 764 |
765 // Static | 765 // Static |
766 void SessionModelAssociator::AppendSessionTabNavigation( | 766 void SessionModelAssociator::AppendSessionTabNavigation( |
767 const sync_pb::TabNavigation& specifics, | 767 const sync_pb::TabNavigation& specifics, |
768 std::vector<TabNavigation>* navigations) { | 768 std::vector<TabNavigation>* navigations) { |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; | 1190 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; |
1191 DWORD size = sizeof(computer_name); | 1191 DWORD size = sizeof(computer_name); |
1192 if (GetComputerNameA(computer_name, &size)) { | 1192 if (GetComputerNameA(computer_name, &size)) { |
1193 return computer_name; | 1193 return computer_name; |
1194 } | 1194 } |
1195 return std::string(); | 1195 return std::string(); |
1196 } | 1196 } |
1197 #endif | 1197 #endif |
1198 | 1198 |
1199 } // namespace browser_sync | 1199 } // namespace browser_sync |
OLD | NEW |