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 "components/sync_sessions/synced_session_tracker.h" | 5 #include "components/sync_sessions/synced_session_tracker.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 unmapped_tabs_[session_tag].clear(); | 214 unmapped_tabs_[session_tag].clear(); |
215 } | 215 } |
216 | 216 |
217 bool SyncedSessionTracker::IsTabUnmappedForTesting(SessionID::id_type tab_id) { | 217 bool SyncedSessionTracker::IsTabUnmappedForTesting(SessionID::id_type tab_id) { |
218 auto it = unmapped_tabs_[local_session_tag_].find(tab_id); | 218 auto it = unmapped_tabs_[local_session_tag_].find(tab_id); |
219 return it != unmapped_tabs_[local_session_tag_].end(); | 219 return it != unmapped_tabs_[local_session_tag_].end(); |
220 } | 220 } |
221 | 221 |
222 void SyncedSessionTracker::PutWindowInSession(const std::string& session_tag, | 222 void SyncedSessionTracker::PutWindowInSession(const std::string& session_tag, |
223 SessionID::id_type window_id) { | 223 SessionID::id_type window_id) { |
| 224 if (GetSession(session_tag)->windows.find(window_id) != |
| 225 GetSession(session_tag)->windows.end()) { |
| 226 DVLOG(1) << "Window " << window_id << " already added to session " |
| 227 << session_tag; |
| 228 return; |
| 229 } |
224 std::unique_ptr<SyncedSessionWindow> window; | 230 std::unique_ptr<SyncedSessionWindow> window; |
225 | 231 |
226 auto iter = unmapped_windows_[session_tag].find(window_id); | 232 auto iter = unmapped_windows_[session_tag].find(window_id); |
227 if (iter != unmapped_windows_[session_tag].end()) { | 233 if (iter != unmapped_windows_[session_tag].end()) { |
228 DCHECK_EQ(synced_window_map_[session_tag][window_id], iter->second.get()); | 234 DCHECK_EQ(synced_window_map_[session_tag][window_id], iter->second.get()); |
229 window = std::move(iter->second); | 235 window = std::move(iter->second); |
230 unmapped_windows_[session_tag].erase(iter); | 236 unmapped_windows_[session_tag].erase(iter); |
231 DVLOG(1) << "Putting seen window " << window_id << " at " << window.get() | 237 DVLOG(1) << "Putting seen window " << window_id << " at " << window.get() |
232 << "in " << (session_tag == local_session_tag_ ? "local session" | 238 << "in " << (session_tag == local_session_tag_ ? "local session" |
233 : session_tag); | 239 : session_tag); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 DVLOG(1) << "Getting " | 344 DVLOG(1) << "Getting " |
339 << (session_tag == local_session_tag_ ? "local session" | 345 << (session_tag == local_session_tag_ ? "local session" |
340 : session_tag) | 346 : session_tag) |
341 << "'s new tab " << tab_id << " at " << tab_ptr; | 347 << "'s new tab " << tab_id << " at " << tab_ptr; |
342 } | 348 } |
343 DCHECK(tab_ptr); | 349 DCHECK(tab_ptr); |
344 DCHECK_EQ(tab_ptr->tab_id.id(), tab_id); | 350 DCHECK_EQ(tab_ptr->tab_id.id(), tab_id); |
345 return tab_ptr; | 351 return tab_ptr; |
346 } | 352 } |
347 | 353 |
348 void SyncedSessionTracker::CleanupForeignSession( | 354 void SyncedSessionTracker::CleanupSession(const std::string& session_tag) { |
349 const std::string& session_tag) { | |
350 DCHECK_NE(local_session_tag_, session_tag); | |
351 CleanupSessionImpl(session_tag); | 355 CleanupSessionImpl(session_tag); |
352 } | 356 } |
353 | 357 |
354 void SyncedSessionTracker::CleanupLocalTabs(std::set<int>* deleted_node_ids) { | 358 void SyncedSessionTracker::CleanupLocalTabs(std::set<int>* deleted_node_ids) { |
355 DCHECK(!local_session_tag_.empty()); | 359 DCHECK(!local_session_tag_.empty()); |
356 for (const auto& tab_pair : unmapped_tabs_[local_session_tag_]) | 360 for (const auto& tab_pair : unmapped_tabs_[local_session_tag_]) |
357 local_tab_pool_.FreeTab(tab_pair.first); | 361 local_tab_pool_.FreeTab(tab_pair.first); |
358 CleanupSessionImpl(local_session_tag_); | 362 CleanupSessionImpl(local_session_tag_); |
359 local_tab_pool_.CleanupTabNodes(deleted_node_ids); | 363 local_tab_pool_.CleanupTabNodes(deleted_node_ids); |
360 for (int tab_node_id : *deleted_node_ids) { | 364 for (int tab_node_id : *deleted_node_ids) { |
361 GetSession(local_session_tag_)->tab_node_ids.erase(tab_node_id); | 365 GetSession(local_session_tag_)->tab_node_ids.erase(tab_node_id); |
362 } | 366 } |
363 } | 367 } |
364 | 368 |
365 bool SyncedSessionTracker::GetTabNodeFromLocalTabId(SessionID::id_type tab_id, | 369 bool SyncedSessionTracker::GetTabNodeFromLocalTabId(SessionID::id_type tab_id, |
366 int* tab_node_id) { | 370 int* tab_node_id) { |
367 DCHECK(!local_session_tag_.empty()); | 371 DCHECK(!local_session_tag_.empty()); |
368 // Ensure a placeholder SessionTab is in place, if not already. | 372 // Ensure a placeholder SessionTab is in place, if not already. Although we |
369 // Although we don't need a SessionTab to fulfill this request, this forces | 373 // don't need a SessionTab to fulfill this request, this forces the creation |
370 // the | 374 // of one if it doesn't already exist. This helps to make sure we're tracking |
371 // creation of one if it doesn't already exist. This helps to make sure we're | 375 // this |tab_id| if |local_tab_pool_| is, and everyone's data structures are |
372 // tracking this |tab_id| if |local_tab_pool_| is, and everyone's data | 376 // kept in sync and as consistent as possible. |
373 // structures | |
374 // are kept in sync and as consistent as possible. | |
375 GetTab(local_session_tag_, tab_id); // Ignore result. | 377 GetTab(local_session_tag_, tab_id); // Ignore result. |
376 | 378 |
377 bool reused_existing_tab = | 379 bool reused_existing_tab = |
378 local_tab_pool_.GetTabNodeForTab(tab_id, tab_node_id); | 380 local_tab_pool_.GetTabNodeForTab(tab_id, tab_node_id); |
379 DCHECK_NE(TabNodePool::kInvalidTabNodeID, *tab_node_id); | 381 DCHECK_NE(TabNodePool::kInvalidTabNodeID, *tab_node_id); |
380 GetSession(local_session_tag_)->tab_node_ids.insert(*tab_node_id); | 382 GetSession(local_session_tag_)->tab_node_ids.insert(*tab_node_id); |
381 return reused_existing_tab; | 383 return reused_existing_tab; |
382 } | 384 } |
383 | 385 |
384 bool SyncedSessionTracker::IsLocalTabNodeAssociated(int tab_node_id) { | 386 bool SyncedSessionTracker::IsLocalTabNodeAssociated(int tab_node_id) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // Get rid of our convenience maps (does not delete the actual Window/Tabs | 450 // Get rid of our convenience maps (does not delete the actual Window/Tabs |
449 // themselves; they should have all been deleted above). | 451 // themselves; they should have all been deleted above). |
450 synced_window_map_.clear(); | 452 synced_window_map_.clear(); |
451 synced_tab_map_.clear(); | 453 synced_tab_map_.clear(); |
452 | 454 |
453 local_tab_pool_.Clear(); | 455 local_tab_pool_.Clear(); |
454 local_session_tag_.clear(); | 456 local_session_tag_.clear(); |
455 } | 457 } |
456 | 458 |
457 } // namespace sync_sessions | 459 } // namespace sync_sessions |
OLD | NEW |