Chromium Code Reviews| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 for (std::vector<SyncedTabDelegate*>::const_iterator i = tabs.begin(); | 209 for (std::vector<SyncedTabDelegate*>::const_iterator i = tabs.begin(); |
| 210 i != tabs.end(); | 210 i != tabs.end(); |
| 211 ++i) { | 211 ++i) { |
| 212 ReassociateTab(**i); | 212 ReassociateTab(**i); |
| 213 } | 213 } |
| 214 if (waiting_for_change_) QuitLoopForTest(); | 214 if (waiting_for_change_) QuitLoopForTest(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void SessionModelAssociator::ReassociateTab(const SyncedTabDelegate& tab) { | 217 void SessionModelAssociator::ReassociateTab(const SyncedTabDelegate& tab) { |
| 218 DCHECK(CalledOnValidThread()); | 218 DCHECK(CalledOnValidThread()); |
| 219 if (!IsValidTab(tab)) | |
| 220 return; | |
| 221 | |
| 222 int64 sync_id; | 219 int64 sync_id; |
| 223 SessionID::id_type id = tab.GetSessionId(); | 220 SessionID::id_type id = tab.GetSessionId(); |
| 224 if (tab.IsBeingDestroyed()) { | 221 if (tab.IsBeingDestroyed()) { |
| 225 // This tab is closing. | 222 // This tab is closing. |
| 226 TabLinksMap::iterator tab_iter = tab_map_.find(id); | 223 TabLinksMap::iterator tab_iter = tab_map_.find(id); |
| 227 if (tab_iter == tab_map_.end()) { | 224 if (tab_iter == tab_map_.end()) { |
| 228 // We aren't tracking this tab (for example, sync setting page). | 225 // We aren't tracking this tab (for example, sync setting page). |
| 229 return; | 226 return; |
| 230 } | 227 } |
| 231 tab_pool_.FreeTabNode(tab_iter->second.sync_id()); | 228 tab_pool_.FreeTabNode(tab_iter->second.sync_id()); |
| 232 tab_map_.erase(tab_iter); | 229 tab_map_.erase(tab_iter); |
| 233 return; | 230 return; |
| 234 } | 231 } |
| 235 | 232 |
| 233 if (!IsValidTab(tab)) | |
| 234 return; | |
| 235 | |
| 236 TabLinksMap::const_iterator tablink = tab_map_.find(id); | 236 TabLinksMap::const_iterator tablink = tab_map_.find(id); |
| 237 if (tablink == tab_map_.end()) { | 237 if (tablink == tab_map_.end()) { |
| 238 // This is a new tab, get a sync node for it. | 238 // This is a new tab, get a sync node for it. |
| 239 sync_id = tab_pool_.GetFreeTabNode(); | 239 sync_id = tab_pool_.GetFreeTabNode(); |
| 240 } else { | 240 } else { |
| 241 // This tab is already associated with a sync node, reuse it. | 241 // This tab is already associated with a sync node, reuse it. |
| 242 sync_id = tablink->second.sync_id(); | 242 sync_id = tablink->second.sync_id(); |
| 243 } | 243 } |
| 244 Associate(&tab, sync_id); | 244 Associate(&tab, sync_id); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, | 247 void SessionModelAssociator::Associate(const SyncedTabDelegate* tab, |
| 248 int64 sync_id) { | 248 int64 sync_id) { |
| 249 DCHECK(CalledOnValidThread()); | 249 DCHECK(CalledOnValidThread()); |
| 250 SessionID::id_type session_id = tab->GetSessionId(); | 250 SessionID::id_type session_id = tab->GetSessionId(); |
| 251 const SyncedWindowDelegate* window = | 251 const SyncedWindowDelegate* window = |
| 252 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | 252 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( |
| 253 tab->GetWindowId()); | 253 tab->GetWindowId()); |
| 254 if (!window) { // Can happen for weird things like developer console. | 254 DCHECK(window); |
| 255 tab_pool_.FreeTabNode(sync_id); | |
| 256 return; | |
| 257 } | |
| 258 | 255 |
| 259 TabLinks t(sync_id, tab); | 256 TabLinks t(sync_id, tab); |
| 260 tab_map_[session_id] = t; | 257 tab_map_[session_id] = t; |
| 261 | 258 |
| 262 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 259 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 263 WriteTabContentsToSyncModel(*window, *tab, sync_id, &trans); | 260 WriteTabContentsToSyncModel(*window, *tab, sync_id, &trans); |
| 264 } | 261 } |
| 265 | 262 |
| 266 bool SessionModelAssociator::WriteTabContentsToSyncModel( | 263 bool SessionModelAssociator::WriteTabContentsToSyncModel( |
| 267 const SyncedWindowDelegate& window, | 264 const SyncedWindowDelegate& window, |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 foreign_session->windows.resize(header.window_size()); | 573 foreign_session->windows.resize(header.window_size()); |
| 577 } else if (specifics.has_tab()) { | 574 } else if (specifics.has_tab()) { |
| 578 const sync_pb::SessionTab& tab_s = specifics.tab(); | 575 const sync_pb::SessionTab& tab_s = specifics.tab(); |
| 579 SessionID::id_type tab_id = tab_s.tab_id(); | 576 SessionID::id_type tab_id = tab_s.tab_id(); |
| 580 SessionTab* tab = | 577 SessionTab* tab = |
| 581 synced_session_tracker_.GetSessionTab(foreign_session_tag, | 578 synced_session_tracker_.GetSessionTab(foreign_session_tag, |
| 582 tab_id, | 579 tab_id, |
| 583 false); | 580 false); |
| 584 PopulateSessionTabFromSpecifics(tab_s, modification_time, tab); | 581 PopulateSessionTabFromSpecifics(tab_s, modification_time, tab); |
| 585 } else { | 582 } else { |
| 586 NOTREACHED(); | 583 NOTREACHED(); |
|
Yaron
2011/08/23 00:31:54
Do you still want to leave this in? It seems like
| |
| 587 return false; | 584 return false; |
| 588 } | 585 } |
| 589 | 586 |
| 590 return true; | 587 return true; |
| 591 } | 588 } |
| 592 | 589 |
| 593 void SessionModelAssociator::DisassociateForeignSession( | 590 void SessionModelAssociator::DisassociateForeignSession( |
| 594 const std::string& foreign_session_tag) { | 591 const std::string& foreign_session_tag) { |
| 595 DCHECK(CalledOnValidThread()); | 592 DCHECK(CalledOnValidThread()); |
| 596 synced_session_tracker_.DeleteSession(foreign_session_tag); | 593 synced_session_tracker_.DeleteSession(foreign_session_tag); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 } | 838 } |
| 842 if (num_populated == 0) | 839 if (num_populated == 0) |
| 843 return true; | 840 return true; |
| 844 return false; | 841 return false; |
| 845 } | 842 } |
| 846 | 843 |
| 847 // Valid local tab? | 844 // Valid local tab? |
| 848 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) { | 845 bool SessionModelAssociator::IsValidTab(const SyncedTabDelegate& tab) { |
| 849 DCHECK(CalledOnValidThread()); | 846 DCHECK(CalledOnValidThread()); |
| 850 if ((tab.profile() == sync_service_->profile() || | 847 if ((tab.profile() == sync_service_->profile() || |
| 851 sync_service_->profile() == NULL)) { | 848 sync_service_->profile() == NULL)) { // For tests. |
| 849 const SyncedWindowDelegate* window = | |
| 850 SyncedWindowDelegate::FindSyncedWindowDelegateWithId( | |
| 851 tab.GetWindowId()); | |
| 852 if (!window) | |
| 853 return false; | |
| 852 const NavigationEntry* entry = tab.GetActiveEntry(); | 854 const NavigationEntry* entry = tab.GetActiveEntry(); |
| 853 if (!entry) | 855 if (!entry) |
| 854 return false; | 856 return false; |
| 855 if (entry->virtual_url().is_valid() && | 857 if (entry->virtual_url().is_valid() && |
| 856 (entry->virtual_url() != GURL(chrome::kChromeUINewTabURL) || | 858 (entry->virtual_url() != GURL(chrome::kChromeUINewTabURL) || |
| 857 tab.GetEntryCount() > 1)) { | 859 tab.GetEntryCount() > 1)) { |
| 858 return true; | 860 return true; |
| 859 } | 861 } |
| 860 } | 862 } |
| 861 return false; | 863 return false; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1058 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
| 1057 // We only access the cryptographer while holding a transaction. | 1059 // We only access the cryptographer while holding a transaction. |
| 1058 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1060 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 1059 syncable::ModelTypeSet encrypted_types; | 1061 syncable::ModelTypeSet encrypted_types; |
| 1060 encrypted_types = sync_api::GetEncryptedTypes(&trans); | 1062 encrypted_types = sync_api::GetEncryptedTypes(&trans); |
| 1061 return encrypted_types.count(syncable::SESSIONS) == 0 || | 1063 return encrypted_types.count(syncable::SESSIONS) == 0 || |
| 1062 sync_service_->IsCryptographerReady(&trans); | 1064 sync_service_->IsCryptographerReady(&trans); |
| 1063 } | 1065 } |
| 1064 | 1066 |
| 1065 } // namespace browser_sync | 1067 } // namespace browser_sync |
| OLD | NEW |