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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 8 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
9 | 9 |
10 namespace browser_sync { | 10 namespace browser_sync { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // the tab_node_ids are not always available when processing headers. | 279 // the tab_node_ids are not always available when processing headers. |
280 // We know that we will eventually process (via GetTab) every single tab node | 280 // We know that we will eventually process (via GetTab) every single tab node |
281 // in the system, so we permit ourselves to use kInvalidTabNodeID here and | 281 // in the system, so we permit ourselves to use kInvalidTabNodeID here and |
282 // rely on the later update to build the mapping (or a restart). | 282 // rely on the later update to build the mapping (or a restart). |
283 // TODO(tim): Bug 98892. Update comment when Sync API conversion finishes to | 283 // TODO(tim): Bug 98892. Update comment when Sync API conversion finishes to |
284 // mention that in the meantime, the only ill effect is that we may not be | 284 // mention that in the meantime, the only ill effect is that we may not be |
285 // able to fully clean up a stale foreign session, but it will get garbage | 285 // able to fully clean up a stale foreign session, but it will get garbage |
286 // collected eventually. | 286 // collected eventually. |
287 SessionTab* tab_ptr = GetTabImpl( | 287 SessionTab* tab_ptr = GetTabImpl( |
288 session_tag, tab_id, TabNodePool::kInvalidTabNodeID); | 288 session_tag, tab_id, TabNodePool::kInvalidTabNodeID); |
| 289 |
| 290 // It's up to the caller to ensure this never happens. Tabs should not |
| 291 // belong to more than one window or appear twice within the same window. |
| 292 // |
| 293 // If this condition were violated, we would double-free during shutdown. |
| 294 // That could cause all sorts of hard to diagnose crashes, possibly in code |
| 295 // far away from here. We crash early to avoid this. |
| 296 // |
| 297 // See http://crbug.com/360822. |
| 298 CHECK(!synced_tab_map_[session_tag][tab_id].owned); |
| 299 |
289 unmapped_tabs_.erase(tab_ptr); | 300 unmapped_tabs_.erase(tab_ptr); |
290 synced_tab_map_[session_tag][tab_id].owned = true; | 301 synced_tab_map_[session_tag][tab_id].owned = true; |
| 302 |
291 tab_ptr->window_id.set_id(window_id); | 303 tab_ptr->window_id.set_id(window_id); |
292 DVLOG(1) << " - tab " << tab_id << " added to window "<< window_id; | 304 DVLOG(1) << " - tab " << tab_id << " added to window "<< window_id; |
293 DCHECK(GetSession(session_tag)->windows.find(window_id) != | 305 DCHECK(GetSession(session_tag)->windows.find(window_id) != |
294 GetSession(session_tag)->windows.end()); | 306 GetSession(session_tag)->windows.end()); |
295 std::vector<SessionTab*>& window_tabs = | 307 std::vector<SessionTab*>& window_tabs = |
296 GetSession(session_tag)->windows[window_id]->tabs; | 308 GetSession(session_tag)->windows[window_id]->tabs; |
297 if (window_tabs.size() <= tab_index) { | 309 if (window_tabs.size() <= tab_index) { |
298 window_tabs.resize(tab_index+1, NULL); | 310 window_tabs.resize(tab_index+1, NULL); |
299 } | 311 } |
300 DCHECK(!window_tabs[tab_index]); | 312 DCHECK(!window_tabs[tab_index]); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 393 |
382 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs | 394 // Get rid of our Window/Tab maps (does not delete the actual Window/Tabs |
383 // themselves; they should have all been deleted above). | 395 // themselves; they should have all been deleted above). |
384 synced_window_map_.clear(); | 396 synced_window_map_.clear(); |
385 synced_tab_map_.clear(); | 397 synced_tab_map_.clear(); |
386 | 398 |
387 local_session_tag_.clear(); | 399 local_session_tag_.clear(); |
388 } | 400 } |
389 | 401 |
390 } // namespace browser_sync | 402 } // namespace browser_sync |
OLD | NEW |