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 |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sessions/session_id.h" | |
16 #include "chrome/browser/sessions/session_service_factory.h" | 17 #include "chrome/browser/sessions/session_service_factory.h" |
17 #include "chrome/browser/sync/api/sync_error.h" | 18 #include "chrome/browser/sync/api/sync_error.h" |
18 #include "chrome/browser/sync/glue/synced_session.h" | 19 #include "chrome/browser/sync/glue/synced_session.h" |
19 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 20 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
20 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 21 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
21 #include "chrome/browser/sync/internal_api/read_node.h" | 22 #include "chrome/browser/sync/internal_api/read_node.h" |
22 #include "chrome/browser/sync/internal_api/read_transaction.h" | 23 #include "chrome/browser/sync/internal_api/read_transaction.h" |
23 #include "chrome/browser/sync/internal_api/write_node.h" | 24 #include "chrome/browser/sync/internal_api/write_node.h" |
24 #include "chrome/browser/sync/internal_api/write_transaction.h" | 25 #include "chrome/browser/sync/internal_api/write_transaction.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 NOTREACHED(); | 123 NOTREACHED(); |
123 return false; | 124 return false; |
124 } | 125 } |
125 | 126 |
126 void SessionModelAssociator::ReassociateWindows(bool reload_tabs) { | 127 void SessionModelAssociator::ReassociateWindows(bool reload_tabs) { |
127 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
128 std::string local_tag = GetCurrentMachineTag(); | 129 std::string local_tag = GetCurrentMachineTag(); |
129 sync_pb::SessionSpecifics specifics; | 130 sync_pb::SessionSpecifics specifics; |
130 specifics.set_session_tag(local_tag); | 131 specifics.set_session_tag(local_tag); |
131 sync_pb::SessionHeader* header_s = specifics.mutable_header(); | 132 sync_pb::SessionHeader* header_s = specifics.mutable_header(); |
132 SyncedSession* current_session = | 133 SyncedSession* current_session = |
akalin
2011/10/01 01:54:14
i think with the changes suggested below there's n
| |
133 synced_session_tracker_.GetSession(local_tag); | 134 synced_session_tracker_.GetSession(local_tag); |
134 header_s->set_client_name(current_session_name_); | 135 header_s->set_client_name(current_session_name_); |
135 #if defined(OS_LINUX) | 136 #if defined(OS_LINUX) |
136 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX); | 137 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX); |
137 #elif defined(OS_MACOSX) | 138 #elif defined(OS_MACOSX) |
138 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_MAC); | 139 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_MAC); |
139 #elif defined(OS_WIN) | 140 #elif defined(OS_WIN) |
140 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); | 141 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); |
141 #elif defined(OS_CHROMEOS) | 142 #elif defined(OS_CHROMEOS) |
142 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_CROS); | 143 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_CROS); |
143 #else | 144 #else |
144 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_OTHER); | 145 header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_OTHER); |
145 #endif | 146 #endif |
146 | 147 |
147 size_t window_num = 0; | 148 synced_session_tracker_.ResetSessionTracking(local_tag); |
148 std::set<SyncedWindowDelegate*> windows = | 149 std::set<SyncedWindowDelegate*> windows = |
149 SyncedWindowDelegate::GetSyncedWindowDelegates(); | 150 SyncedWindowDelegate::GetSyncedWindowDelegates(); |
150 current_session->windows.reserve(windows.size()); | |
151 for (std::set<SyncedWindowDelegate*>::const_iterator i = | 151 for (std::set<SyncedWindowDelegate*>::const_iterator i = |
152 windows.begin(); i != windows.end(); ++i) { | 152 windows.begin(); i != windows.end(); ++i) { |
153 // Make sure the window has tabs and a viewable window. The viewable window | 153 // Make sure the window has tabs and a viewable window. The viewable window |
154 // check is necessary because, for example, when a browser is closed the | 154 // check is necessary because, for example, when a browser is closed the |
155 // destructor is not necessarily run immediately. This means its possible | 155 // destructor is not necessarily run immediately. This means its possible |
156 // for us to get a handle to a browser that is about to be removed. If | 156 // for us to get a handle to a browser that is about to be removed. If |
157 // the tab count is 0 or the window is NULL, the browser is about to be | 157 // the tab count is 0 or the window is NULL, the browser is about to be |
158 // deleted, so we ignore it. | 158 // deleted, so we ignore it. |
159 if (ShouldSyncWindow(*i) && (*i)->GetTabCount() && | 159 if (ShouldSyncWindow(*i) && (*i)->GetTabCount() && (*i)->HasWindow()) { |
160 (*i)->HasWindow()) { | |
161 sync_pb::SessionWindow window_s; | 160 sync_pb::SessionWindow window_s; |
162 SessionID::id_type window_id = (*i)->GetSessionId(); | 161 SessionID::id_type window_id = (*i)->GetSessionId(); |
163 VLOG(1) << "Reassociating window " << window_id << " with " << | 162 VLOG(1) << "Reassociating window " << window_id << " with " << |
164 (*i)->GetTabCount() << " tabs."; | 163 (*i)->GetTabCount() << " tabs."; |
165 window_s.set_window_id(window_id); | 164 window_s.set_window_id(window_id); |
166 window_s.set_selected_tab_index((*i)->GetActiveIndex()); | 165 window_s.set_selected_tab_index((*i)->GetActiveIndex()); |
167 if ((*i)->IsTypeTabbed()) { | 166 if ((*i)->IsTypeTabbed()) { |
168 window_s.set_browser_type( | 167 window_s.set_browser_type( |
169 sync_pb::SessionWindow_BrowserType_TYPE_TABBED); | 168 sync_pb::SessionWindow_BrowserType_TYPE_TABBED); |
170 } else { | 169 } else { |
(...skipping 13 matching lines...) Expand all Loading... | |
184 ReassociateTab(*tab); | 183 ReassociateTab(*tab); |
185 } | 184 } |
186 } | 185 } |
187 } | 186 } |
188 // Only add a window if it contains valid tabs. | 187 // Only add a window if it contains valid tabs. |
189 if (found_tabs) { | 188 if (found_tabs) { |
190 sync_pb::SessionWindow* header_window = header_s->add_window(); | 189 sync_pb::SessionWindow* header_window = header_s->add_window(); |
191 *header_window = window_s; | 190 *header_window = window_s; |
192 | 191 |
193 // Update this window's representation in the synced session tracker. | 192 // Update this window's representation in the synced session tracker. |
194 if (window_num >= current_session->windows.size()) { | 193 synced_session_tracker_.PutWindowInSession(local_tag, window_id); |
akalin
2011/10/01 01:54:14
see comment below about making PutWindowInSession
| |
195 // This a new window, create it. | |
196 current_session->windows.push_back(new SessionWindow()); | |
197 } | |
198 PopulateSessionWindowFromSpecifics( | 194 PopulateSessionWindowFromSpecifics( |
199 local_tag, | 195 local_tag, |
200 window_s, | 196 window_s, |
201 base::Time::Now(), | 197 base::Time::Now(), |
202 current_session->windows[window_num++], | 198 current_session->windows[window_id], |
203 &synced_session_tracker_); | 199 &synced_session_tracker_); |
204 } | 200 } |
205 } | 201 } |
206 } | 202 } |
203 // Free memory for closed windows and tabs. | |
204 synced_session_tracker_.CleanupSession(local_tag); | |
207 | 205 |
208 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 206 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
209 sync_api::WriteNode header_node(&trans); | 207 sync_api::WriteNode header_node(&trans); |
210 if (!header_node.InitByIdLookup(local_session_syncid_)) { | 208 if (!header_node.InitByIdLookup(local_session_syncid_)) { |
211 LOG(ERROR) << "Failed to load local session header node."; | 209 LOG(ERROR) << "Failed to load local session header node."; |
212 return; | 210 return; |
213 } | 211 } |
214 header_node.SetSessionSpecifics(specifics); | 212 header_node.SetSessionSpecifics(specifics); |
215 if (waiting_for_change_) QuitLoopForSubtleTesting(); | 213 if (waiting_for_change_) QuitLoopForSubtleTesting(); |
216 } | 214 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 sync_pb::TabNavigation* nav_s = tab_s->add_navigation(); | 325 sync_pb::TabNavigation* nav_s = tab_s->add_navigation(); |
328 PopulateSessionSpecificsNavigation(&tab_nav, nav_s); | 326 PopulateSessionSpecificsNavigation(&tab_nav, nav_s); |
329 } | 327 } |
330 } | 328 } |
331 tab_s->set_current_navigation_index(current_index); | 329 tab_s->set_current_navigation_index(current_index); |
332 | 330 |
333 tab_node.SetSessionSpecifics(session_s); | 331 tab_node.SetSessionSpecifics(session_s); |
334 | 332 |
335 // Convert to a local representation and store in synced session tracker. | 333 // Convert to a local representation and store in synced session tracker. |
336 SessionTab* session_tab = | 334 SessionTab* session_tab = |
337 synced_session_tracker_.GetSessionTab(GetCurrentMachineTag(), | 335 synced_session_tracker_.GetTab(GetCurrentMachineTag(), |
338 tab_s->tab_id(), | 336 tab_s->tab_id()); |
339 false); | |
340 PopulateSessionTabFromSpecifics(*tab_s, | 337 PopulateSessionTabFromSpecifics(*tab_s, |
341 base::Time::Now(), | 338 base::Time::Now(), |
342 session_tab); | 339 session_tab); |
343 return true; | 340 return true; |
344 } | 341 } |
345 | 342 |
346 // Static | 343 // Static |
347 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 344 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
348 // See http://crbug.com/67068. | 345 // See http://crbug.com/67068. |
349 void SessionModelAssociator::PopulateSessionSpecificsNavigation( | 346 void SessionModelAssociator::PopulateSessionSpecificsNavigation( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 void SessionModelAssociator::Disassociate(int64 sync_id) { | 420 void SessionModelAssociator::Disassociate(int64 sync_id) { |
424 DCHECK(CalledOnValidThread()); | 421 DCHECK(CalledOnValidThread()); |
425 NOTIMPLEMENTED(); | 422 NOTIMPLEMENTED(); |
426 // TODO(zea): we will need this once we support deleting foreign sessions. | 423 // TODO(zea): we will need this once we support deleting foreign sessions. |
427 } | 424 } |
428 | 425 |
429 bool SessionModelAssociator::AssociateModels(SyncError* error) { | 426 bool SessionModelAssociator::AssociateModels(SyncError* error) { |
430 DCHECK(CalledOnValidThread()); | 427 DCHECK(CalledOnValidThread()); |
431 | 428 |
432 // Ensure that we disassociated properly, otherwise memory might leak. | 429 // Ensure that we disassociated properly, otherwise memory might leak. |
433 DCHECK(synced_session_tracker_.empty()); | 430 DCHECK(synced_session_tracker_.Empty()); |
434 DCHECK_EQ(0U, tab_pool_.capacity()); | 431 DCHECK_EQ(0U, tab_pool_.capacity()); |
435 | 432 |
436 local_session_syncid_ = sync_api::kInvalidId; | 433 local_session_syncid_ = sync_api::kInvalidId; |
437 | 434 |
438 // Read any available foreign sessions and load any session data we may have. | 435 // Read any available foreign sessions and load any session data we may have. |
439 // If we don't have any local session data in the db, create a header node. | 436 // If we don't have any local session data in the db, create a header node. |
440 { | 437 { |
441 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 438 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
442 | 439 |
443 sync_api::ReadNode root(&trans); | 440 sync_api::ReadNode root(&trans); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 // Check if anything has changed on the client side. | 477 // Check if anything has changed on the client side. |
481 UpdateSyncModelDataFromClient(); | 478 UpdateSyncModelDataFromClient(); |
482 | 479 |
483 VLOG(1) << "Session models associated."; | 480 VLOG(1) << "Session models associated."; |
484 | 481 |
485 return true; | 482 return true; |
486 } | 483 } |
487 | 484 |
488 bool SessionModelAssociator::DisassociateModels(SyncError* error) { | 485 bool SessionModelAssociator::DisassociateModels(SyncError* error) { |
489 DCHECK(CalledOnValidThread()); | 486 DCHECK(CalledOnValidThread()); |
490 synced_session_tracker_.clear(); | 487 synced_session_tracker_.Clear(); |
491 tab_map_.clear(); | 488 tab_map_.clear(); |
492 tab_pool_.clear(); | 489 tab_pool_.clear(); |
493 local_session_syncid_ = sync_api::kInvalidId; | 490 local_session_syncid_ = sync_api::kInvalidId; |
494 current_machine_tag_ = ""; | 491 current_machine_tag_ = ""; |
495 current_session_name_ = ""; | 492 current_session_name_ = ""; |
496 | 493 |
497 // There is no local model stored with which to disassociate, just notify | 494 // There is no local model stored with which to disassociate, just notify |
498 // foreign session handlers. | 495 // foreign session handlers. |
499 NotificationService::current()->Notify( | 496 NotificationService::current()->Notify( |
500 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, | 497 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 return false; | 624 return false; |
628 | 625 |
629 if (specifics.has_header()) { | 626 if (specifics.has_header()) { |
630 // Read in the header data for this foreign session. | 627 // Read in the header data for this foreign session. |
631 // Header data contains window information and ordered tab id's for each | 628 // Header data contains window information and ordered tab id's for each |
632 // window. | 629 // window. |
633 | 630 |
634 // Load (or create) the SyncedSession object for this client. | 631 // Load (or create) the SyncedSession object for this client. |
635 SyncedSession* foreign_session = | 632 SyncedSession* foreign_session = |
636 synced_session_tracker_.GetSession(foreign_session_tag); | 633 synced_session_tracker_.GetSession(foreign_session_tag); |
637 | |
638 const sync_pb::SessionHeader& header = specifics.header(); | 634 const sync_pb::SessionHeader& header = specifics.header(); |
639 PopulateSessionHeaderFromSpecifics(header, foreign_session); | 635 PopulateSessionHeaderFromSpecifics(header, foreign_session); |
640 foreign_session->windows.reserve(header.window_size()); | 636 |
641 VLOG(1) << "Associating " << foreign_session_tag << " with " << | 637 // Reset the tab/window tracking for this session (must do this before |
642 header.window_size() << " windows."; | 638 // we start calling PutWindowInSessino and PutTabInWindow so that all |
akalin
2011/10/01 01:54:14
Sessino -> Session
Nicolas Zea
2011/10/03 18:36:50
Done.
| |
643 size_t i; | 639 // unused tabs/windows get cleared by the CleanupSession(...) call). |
644 for (i = 0; i < static_cast<size_t>(header.window_size()); ++i) { | 640 synced_session_tracker_.ResetSessionTracking(foreign_session_tag); |
645 if (i >= foreign_session->windows.size()) { | 641 |
646 // This a new window, create it. | 642 // Process all the windows and their tab information. |
647 foreign_session->windows.push_back(new SessionWindow()); | 643 int num_windows = header.window_size(); |
648 } | 644 VLOG(1) << "Associating " << foreign_session_tag << " with " |
645 << num_windows << " windows."; | |
646 for (int i = 0; i < num_windows; ++i) { | |
649 const sync_pb::SessionWindow& window_s = header.window(i); | 647 const sync_pb::SessionWindow& window_s = header.window(i); |
648 SessionID::id_type window_id = window_s.window_id(); | |
649 synced_session_tracker_.PutWindowInSession(foreign_session_tag, | |
650 window_id); | |
650 PopulateSessionWindowFromSpecifics(foreign_session_tag, | 651 PopulateSessionWindowFromSpecifics(foreign_session_tag, |
akalin
2011/10/01 01:54:14
I think the PopulateSessionWindowFromSpecifics log
| |
651 window_s, | 652 window_s, |
652 modification_time, | 653 modification_time, |
653 foreign_session->windows[i], | 654 foreign_session->windows[window_id], |
654 &synced_session_tracker_); | 655 &synced_session_tracker_); |
655 } | 656 } |
656 // Remove any remaining windows (in case windows were closed) | 657 |
657 for (; i < foreign_session->windows.size(); ++i) { | 658 // Delete any closed windows and unused tabs as necessary. |
658 delete foreign_session->windows[i]; | 659 synced_session_tracker_.CleanupSession(foreign_session_tag); |
659 } | |
660 foreign_session->windows.resize(header.window_size()); | |
661 } else if (specifics.has_tab()) { | 660 } else if (specifics.has_tab()) { |
662 const sync_pb::SessionTab& tab_s = specifics.tab(); | 661 const sync_pb::SessionTab& tab_s = specifics.tab(); |
663 SessionID::id_type tab_id = tab_s.tab_id(); | 662 SessionID::id_type tab_id = tab_s.tab_id(); |
664 SessionTab* tab = | 663 SessionTab* tab = |
akalin
2011/10/01 01:54:14
I think there's a similar need to rename GetTab to
Nicolas Zea
2011/10/03 18:36:50
But it's not necessarily windowless. It's possible
| |
665 synced_session_tracker_.GetSessionTab(foreign_session_tag, | 664 synced_session_tracker_.GetTab(foreign_session_tag, tab_id); |
666 tab_id, | |
667 false); | |
668 PopulateSessionTabFromSpecifics(tab_s, modification_time, tab); | 665 PopulateSessionTabFromSpecifics(tab_s, modification_time, tab); |
669 } else { | 666 } else { |
670 NOTREACHED(); | 667 NOTREACHED(); |
671 return false; | 668 return false; |
672 } | 669 } |
673 | 670 |
674 return true; | 671 return true; |
675 } | 672 } |
676 | 673 |
677 void SessionModelAssociator::DisassociateForeignSession( | 674 void SessionModelAssociator::DisassociateForeignSession( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 session_window->selected_tab_index = specifics.selected_tab_index(); | 720 session_window->selected_tab_index = specifics.selected_tab_index(); |
724 if (specifics.has_browser_type()) { | 721 if (specifics.has_browser_type()) { |
725 if (specifics.browser_type() == | 722 if (specifics.browser_type() == |
726 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { | 723 sync_pb::SessionWindow_BrowserType_TYPE_TABBED) { |
727 session_window->type = 1; | 724 session_window->type = 1; |
728 } else { | 725 } else { |
729 session_window->type = 2; | 726 session_window->type = 2; |
730 } | 727 } |
731 } | 728 } |
732 session_window->timestamp = mtime; | 729 session_window->timestamp = mtime; |
733 session_window->tabs.resize(specifics.tab_size()); | 730 session_window->tabs.resize(specifics.tab_size(), NULL); |
734 for (int i = 0; i < specifics.tab_size(); i++) { | 731 for (int i = 0; i < specifics.tab_size(); i++) { |
735 SessionID::id_type tab_id = specifics.tab(i); | 732 SessionID::id_type tab_id = specifics.tab(i); |
736 session_window->tabs[i] = | 733 tracker->PutTabInWindow(session_tag, |
737 tracker->GetSessionTab(session_tag, tab_id, true); | 734 session_window->window_id.id(), |
735 tab_id, | |
736 i); | |
738 } | 737 } |
739 } | 738 } |
740 | 739 |
741 // Static | 740 // Static |
742 void SessionModelAssociator::PopulateSessionTabFromSpecifics( | 741 void SessionModelAssociator::PopulateSessionTabFromSpecifics( |
743 const sync_pb::SessionTab& specifics, | 742 const sync_pb::SessionTab& specifics, |
744 const base::Time& mtime, | 743 const base::Time& mtime, |
745 SessionTab* tab) { | 744 SessionTab* tab) { |
745 DCHECK_EQ(tab->tab_id.id(), specifics.tab_id()); | |
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(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
906 return tab_syncid_pool_[static_cast<size_t>(tab_pool_fp_--)]; | 906 return tab_syncid_pool_[static_cast<size_t>(tab_pool_fp_--)]; |
907 } | 907 } |
908 } | 908 } |
909 | 909 |
910 void SessionModelAssociator::TabNodePool::FreeTabNode(int64 sync_id) { | 910 void SessionModelAssociator::TabNodePool::FreeTabNode(int64 sync_id) { |
911 // Pool size should always match # of free tab nodes. | 911 // Pool size should always match # of free tab nodes. |
912 DCHECK_LT(tab_pool_fp_, static_cast<int64>(tab_syncid_pool_.size())); | 912 DCHECK_LT(tab_pool_fp_, static_cast<int64>(tab_syncid_pool_.size())); |
913 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; | 913 tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; |
914 } | 914 } |
915 | 915 |
916 bool SessionModelAssociator::GetLocalSession( | 916 bool SessionModelAssociator::GetLocalSession( |
akalin
2011/10/01 01:54:14
This is needed for test only, right? Append "ForT
Nicolas Zea
2011/10/03 18:36:50
This and the methods below are used in (or are mea
| |
917 const SyncedSession* * local_session) { | 917 const SyncedSession* * local_session) { |
918 DCHECK(CalledOnValidThread()); | 918 DCHECK(CalledOnValidThread()); |
919 if (current_machine_tag_.empty()) | 919 if (current_machine_tag_.empty()) |
920 return false; | 920 return false; |
921 *local_session = | 921 *local_session = synced_session_tracker_.GetSession(GetCurrentMachineTag()); |
922 synced_session_tracker_.GetSession(GetCurrentMachineTag()); | |
923 return true; | 922 return true; |
924 } | 923 } |
925 | 924 |
926 bool SessionModelAssociator::GetAllForeignSessions( | 925 bool SessionModelAssociator::GetAllForeignSessions( |
akalin
2011/10/01 01:54:14
append ForTest, return vector directly
| |
927 std::vector<const SyncedSession*>* sessions) { | 926 std::vector<const SyncedSession*>* sessions) { |
928 DCHECK(CalledOnValidThread()); | 927 DCHECK(CalledOnValidThread()); |
929 return synced_session_tracker_.LookupAllForeignSessions(sessions); | 928 return synced_session_tracker_.LookupAllForeignSessions(sessions); |
930 } | 929 } |
931 | 930 |
932 bool SessionModelAssociator::GetForeignSession( | 931 bool SessionModelAssociator::GetForeignSession( |
akalin
2011/10/01 01:54:14
append ForTest, return vector directly
| |
933 const std::string& tag, | 932 const std::string& tag, |
934 std::vector<SessionWindow*>* windows) { | 933 std::vector<const SessionWindow*>* windows) { |
935 DCHECK(CalledOnValidThread()); | 934 DCHECK(CalledOnValidThread()); |
936 return synced_session_tracker_.LookupSessionWindows(tag, windows); | 935 return synced_session_tracker_.LookupSessionWindows(tag, windows); |
937 } | 936 } |
938 | 937 |
939 bool SessionModelAssociator::GetForeignTab( | 938 bool SessionModelAssociator::GetForeignTab( |
940 const std::string& tag, | 939 const std::string& tag, |
941 const SessionID::id_type tab_id, | 940 const SessionID::id_type tab_id, |
942 const SessionTab** tab) { | 941 const SessionTab** tab) { |
943 DCHECK(CalledOnValidThread()); | 942 DCHECK(CalledOnValidThread()); |
944 return synced_session_tracker_.LookupSessionTab(tag, tab_id, tab); | 943 return synced_session_tracker_.LookupSessionTab(tag, tab_id, tab); |
945 } | 944 } |
946 | 945 |
947 // Static | |
948 bool SessionModelAssociator::SessionWindowHasNoTabsToSync( | |
949 const SessionWindow& window) { | |
950 int num_populated = 0; | |
951 for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin(); | |
952 i != window.tabs.end(); ++i) { | |
953 const SessionTab* tab = *i; | |
954 if (IsValidSessionTab(*tab)) | |
955 num_populated++; | |
956 } | |
957 if (num_populated == 0) | |
958 return true; | |
959 return false; | |
960 } | |
961 | |
962 // Valid local tab? | 946 // Valid local tab? |
963 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) { | 947 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) const { |
964 DCHECK(CalledOnValidThread()); | 948 DCHECK(CalledOnValidThread()); |
965 if ((tab.profile() == sync_service_->profile() || | 949 if ((tab.profile() == sync_service_->profile() || |
966 sync_service_->profile() == NULL)) { // For tests. | 950 sync_service_->profile() == NULL)) { // For tests. |
967 const SyncedWindowDelegate* window = | 951 const SyncedWindowDelegate* window = |
968 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | 952 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
969 tab.GetWindowId()); | 953 tab.GetWindowId()); |
970 if (!window) | 954 if (!window) |
971 return false; | 955 return false; |
972 const NavigationEntry* entry = tab.GetActiveEntry(); | 956 const NavigationEntry* entry = tab.GetActiveEntry(); |
973 if (!entry) | 957 if (!entry) |
974 return false; | 958 return false; |
975 if (entry->virtual_url().is_valid() && | 959 if (entry->virtual_url().is_valid() && |
976 (entry->virtual_url().GetOrigin() != GURL(chrome::kChromeUINewTabURL) || | 960 (entry->virtual_url().GetOrigin() != GURL(chrome::kChromeUINewTabURL) || |
977 tab.GetEntryCount() > 1)) { | 961 tab.GetEntryCount() > 1)) { |
978 return true; | 962 return true; |
979 } | 963 } |
980 } | 964 } |
981 return false; | 965 return false; |
982 } | 966 } |
983 | 967 |
984 // Static. | |
985 bool SessionModelAssociator::IsValidSessionTab(const SessionTab& tab) { | |
986 if (tab.navigations.empty()) | |
987 return false; | |
988 int selected_index = tab.current_navigation_index; | |
989 selected_index = std::max( | |
990 0, | |
991 std::min(selected_index, | |
992 static_cast<int>(tab.navigations.size() - 1))); | |
993 if (selected_index == 0 && | |
994 tab.navigations.size() == 1 && | |
995 tab.navigations.at(selected_index).virtual_url().GetOrigin() == | |
996 GURL(chrome::kChromeUINewTabURL)) { | |
997 // This is a new tab with no further history, skip. | |
998 return false; | |
999 } | |
1000 return true; | |
1001 } | |
1002 | |
1003 | |
1004 void SessionModelAssociator::QuitLoopForSubtleTesting() { | 968 void SessionModelAssociator::QuitLoopForSubtleTesting() { |
1005 if (waiting_for_change_) { | 969 if (waiting_for_change_) { |
1006 VLOG(1) << "Quitting MessageLoop for test."; | 970 VLOG(1) << "Quitting MessageLoop for test."; |
1007 waiting_for_change_ = false; | 971 waiting_for_change_ = false; |
1008 test_method_factory_.RevokeAll(); | 972 test_method_factory_.RevokeAll(); |
1009 MessageLoop::current()->Quit(); | 973 MessageLoop::current()->Quit(); |
1010 } | 974 } |
1011 } | 975 } |
1012 | 976 |
1013 void SessionModelAssociator::BlockUntilLocalChangeForTest( | 977 void SessionModelAssociator::BlockUntilLocalChangeForTest( |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1190 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; | 1154 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; |
1191 DWORD size = sizeof(computer_name); | 1155 DWORD size = sizeof(computer_name); |
1192 if (GetComputerNameA(computer_name, &size)) { | 1156 if (GetComputerNameA(computer_name, &size)) { |
1193 return computer_name; | 1157 return computer_name; |
1194 } | 1158 } |
1195 return std::string(); | 1159 return std::string(); |
1196 } | 1160 } |
1197 #endif | 1161 #endif |
1198 | 1162 |
1199 } // namespace browser_sync | 1163 } // namespace browser_sync |
OLD | NEW |