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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 7 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
8 | 8 |
9 namespace browser_sync { | 9 namespace browser_sync { |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 iter->second->windows.begin(); | 60 iter->second->windows.begin(); |
61 window_iter != iter->second->windows.end(); window_iter++) { | 61 window_iter != iter->second->windows.end(); window_iter++) { |
62 windows->push_back(window_iter->second); | 62 windows->push_back(window_iter->second); |
63 } | 63 } |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 bool SyncedSessionTracker::LookupSessionTab( | 67 bool SyncedSessionTracker::LookupSessionTab( |
68 const std::string& tag, | 68 const std::string& tag, |
69 SessionID::id_type tab_id, | 69 SessionID::id_type tab_id, |
70 const SessionTab** tab) const { | 70 const SyncedSessionTab** tab) const { |
71 DCHECK(tab); | 71 DCHECK(tab); |
72 SyncedTabMap::const_iterator tab_map_iter = synced_tab_map_.find(tag); | 72 SyncedTabMap::const_iterator tab_map_iter = synced_tab_map_.find(tag); |
73 if (tab_map_iter == synced_tab_map_.end()) { | 73 if (tab_map_iter == synced_tab_map_.end()) { |
74 // We have no record of this session. | 74 // We have no record of this session. |
75 *tab = NULL; | 75 *tab = NULL; |
76 return false; | 76 return false; |
77 } | 77 } |
78 IDToSessionTabMap::const_iterator tab_iter = | 78 IDToSessionTabMap::const_iterator tab_iter = |
79 tab_map_iter->second.find(tab_id); | 79 tab_map_iter->second.find(tab_id); |
80 if (tab_iter == tab_map_iter->second.end()) { | 80 if (tab_iter == tab_map_iter->second.end()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 delete window_wrapper.window_ptr; | 158 delete window_wrapper.window_ptr; |
159 return true; | 159 return true; |
160 } | 160 } |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 bool SyncedSessionTracker::DeleteOldSessionTabIfNecessary( | 164 bool SyncedSessionTracker::DeleteOldSessionTabIfNecessary( |
165 SessionTabWrapper tab_wrapper) { | 165 SessionTabWrapper tab_wrapper) { |
166 if (!tab_wrapper.owned) { | 166 if (!tab_wrapper.owned) { |
167 if (VLOG_IS_ON(1)) { | 167 if (VLOG_IS_ON(1)) { |
168 SessionTab* tab_ptr = tab_wrapper.tab_ptr; | 168 SyncedSessionTab* tab_ptr = tab_wrapper.tab_ptr; |
169 std::string title; | 169 std::string title; |
170 if (tab_ptr->navigations.size() > 0) { | 170 if (tab_ptr->navigations.size() > 0) { |
171 title = " (" + UTF16ToUTF8( | 171 title = " (" + UTF16ToUTF8( |
172 tab_ptr->navigations[tab_ptr->navigations.size()-1].title()) + ")"; | 172 tab_ptr->navigations[tab_ptr->navigations.size()-1].title()) + ")"; |
173 } | 173 } |
174 DVLOG(1) << "Deleting closed tab " << tab_ptr->tab_id.id() << title | 174 DVLOG(1) << "Deleting closed tab " << tab_ptr->tab_id.id() << title |
175 << " from window " << tab_ptr->window_id.id(); | 175 << " from window " << tab_ptr->window_id.id(); |
176 } | 176 } |
177 unmapped_tabs_.erase(tab_wrapper.tab_ptr); | 177 unmapped_tabs_.erase(tab_wrapper.tab_ptr); |
178 delete tab_wrapper.tab_ptr; | 178 delete tab_wrapper.tab_ptr; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 DCHECK(window_ptr); | 232 DCHECK(window_ptr); |
233 DCHECK_EQ(window_ptr->window_id.id(), window_id); | 233 DCHECK_EQ(window_ptr->window_id.id(), window_id); |
234 DCHECK_EQ((SessionWindow*)NULL, GetSession(session_tag)->windows[window_id]); | 234 DCHECK_EQ((SessionWindow*)NULL, GetSession(session_tag)->windows[window_id]); |
235 GetSession(session_tag)->windows[window_id] = window_ptr; | 235 GetSession(session_tag)->windows[window_id] = window_ptr; |
236 } | 236 } |
237 | 237 |
238 void SyncedSessionTracker::PutTabInWindow(const std::string& session_tag, | 238 void SyncedSessionTracker::PutTabInWindow(const std::string& session_tag, |
239 SessionID::id_type window_id, | 239 SessionID::id_type window_id, |
240 SessionID::id_type tab_id, | 240 SessionID::id_type tab_id, |
241 size_t tab_index) { | 241 size_t tab_index) { |
242 SessionTab* tab_ptr = GetTab(session_tag, tab_id); | 242 SyncedSessionTab* tab_ptr = GetTab(session_tag, tab_id); |
243 unmapped_tabs_.erase(tab_ptr); | 243 unmapped_tabs_.erase(tab_ptr); |
244 synced_tab_map_[session_tag][tab_id].owned = true; | 244 synced_tab_map_[session_tag][tab_id].owned = true; |
245 tab_ptr->window_id.set_id(window_id); | 245 tab_ptr->window_id.set_id(window_id); |
246 DVLOG(1) << " - tab " << tab_id << " added to window "<< window_id; | 246 DVLOG(1) << " - tab " << tab_id << " added to window "<< window_id; |
247 DCHECK(GetSession(session_tag)->windows.find(window_id) != | 247 DCHECK(GetSession(session_tag)->windows.find(window_id) != |
248 GetSession(session_tag)->windows.end()); | 248 GetSession(session_tag)->windows.end()); |
249 std::vector<SessionTab*>& window_tabs = | 249 std::vector<SessionTab*>& window_tabs = |
250 GetSession(session_tag)->windows[window_id]->tabs; | 250 GetSession(session_tag)->windows[window_id]->tabs; |
251 if (window_tabs.size() <= tab_index) { | 251 if (window_tabs.size() <= tab_index) { |
252 window_tabs.resize(tab_index+1, NULL); | 252 window_tabs.resize(tab_index+1, NULL); |
253 } | 253 } |
254 DCHECK_EQ((SessionTab*)NULL, window_tabs[tab_index]); | 254 DCHECK_EQ((SyncedSessionTab*)NULL, window_tabs[tab_index]); |
255 window_tabs[tab_index] = tab_ptr; | 255 window_tabs[tab_index] = tab_ptr; |
256 } | 256 } |
257 | 257 |
258 SessionTab* SyncedSessionTracker::GetTab( | 258 SyncedSessionTab* SyncedSessionTracker::GetTab( |
259 const std::string& session_tag, | 259 const std::string& session_tag, |
260 SessionID::id_type tab_id) { | 260 SessionID::id_type tab_id) { |
261 SessionTab* tab_ptr = NULL; | 261 SyncedSessionTab* tab_ptr = NULL; |
262 IDToSessionTabMap::iterator iter = | 262 IDToSessionTabMap::iterator iter = |
263 synced_tab_map_[session_tag].find(tab_id); | 263 synced_tab_map_[session_tag].find(tab_id); |
264 if (iter != synced_tab_map_[session_tag].end()) { | 264 if (iter != synced_tab_map_[session_tag].end()) { |
265 tab_ptr = iter->second.tab_ptr; | 265 tab_ptr = iter->second.tab_ptr; |
266 if (VLOG_IS_ON(1)) { | 266 if (VLOG_IS_ON(1)) { |
267 std::string title; | 267 std::string title; |
268 if (tab_ptr->navigations.size() > 0) { | 268 if (tab_ptr->navigations.size() > 0) { |
269 title = " (" + UTF16ToUTF8( | 269 title = " (" + UTF16ToUTF8( |
270 tab_ptr->navigations[tab_ptr->navigations.size()-1].title()) + ")"; | 270 tab_ptr->navigations[tab_ptr->navigations.size()-1].title()) + ")"; |
271 } | 271 } |
272 DVLOG(1) << "Getting " | 272 DVLOG(1) << "Getting " |
273 << (session_tag == local_session_tag_ ? | 273 << (session_tag == local_session_tag_ ? |
274 "local session" : session_tag) | 274 "local session" : session_tag) |
275 << "'s seen tab " << tab_id << " at " << tab_ptr << title; | 275 << "'s seen tab " << tab_id << " at " << tab_ptr << title; |
276 } | 276 } |
277 } else { | 277 } else { |
278 tab_ptr = new SessionTab(); | 278 tab_ptr = new SyncedSessionTab(); |
279 tab_ptr->tab_id.set_id(tab_id); | 279 tab_ptr->tab_id.set_id(tab_id); |
280 synced_tab_map_[session_tag][tab_id] = SessionTabWrapper(tab_ptr, false); | 280 synced_tab_map_[session_tag][tab_id] = SessionTabWrapper(tab_ptr, false); |
281 unmapped_tabs_.insert(tab_ptr); | 281 unmapped_tabs_.insert(tab_ptr); |
282 DVLOG(1) << "Getting " | 282 DVLOG(1) << "Getting " |
283 << (session_tag == local_session_tag_ ? | 283 << (session_tag == local_session_tag_ ? |
284 "local session" : session_tag) | 284 "local session" : session_tag) |
285 << "'s new tab " << tab_id << " at " << tab_ptr; | 285 << "'s new tab " << tab_id << " at " << tab_ptr; |
286 } | 286 } |
287 DCHECK(tab_ptr); | 287 DCHECK(tab_ptr); |
288 DCHECK_EQ(tab_ptr->tab_id.id(), tab_id); | 288 DCHECK_EQ(tab_ptr->tab_id.id(), tab_id); |
(...skipping 13 matching lines...) Expand all Loading... |
302 | 302 |
303 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs | 303 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs |
304 // themselves; they should have all been deleted above). | 304 // themselves; they should have all been deleted above). |
305 synced_window_map_.clear(); | 305 synced_window_map_.clear(); |
306 synced_tab_map_.clear(); | 306 synced_tab_map_.clear(); |
307 | 307 |
308 local_session_tag_.clear(); | 308 local_session_tag_.clear(); |
309 } | 309 } |
310 | 310 |
311 } // namespace browser_sync | 311 } // namespace browser_sync |
OLD | NEW |