Chromium Code Reviews| 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/supports_user_data.h" | 5 #include "base/supports_user_data.h" |
| 6 | 6 |
| 7 namespace base { | 7 namespace base { |
| 8 | 8 |
| 9 SupportsUserData::SupportsUserData() { | 9 SupportsUserData::SupportsUserData() { |
| 10 // Harmless to construct on a different thread to subsequent usage. | 10 // Harmless to construct on a different thread to subsequent usage. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 DCHECK(thread_checker_.CalledOnValidThread()); | 28 DCHECK(thread_checker_.CalledOnValidThread()); |
| 29 user_data_.erase(key); | 29 user_data_.erase(key); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SupportsUserData::DetachUserDataThread() { | 32 void SupportsUserData::DetachUserDataThread() { |
| 33 thread_checker_.DetachFromThread(); | 33 thread_checker_.DetachFromThread(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 SupportsUserData::~SupportsUserData() { | 36 SupportsUserData::~SupportsUserData() { |
| 37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); | 37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); |
| 38 DataMap local_user_data; | |
| 39 user_data_.swap(local_user_data); | |
| 40 // Now this->user_data_ is empty, and any destructors called transitively from | |
| 41 // the destruction of |local_user_data| will see it that way instead of | |
| 42 // calling into a being-destroyed object. | |
|
Peter Kasting
2014/05/28 03:44:13
Nit: calling into -> examining
Jeffrey Yasskin
2014/05/28 05:45:26
Done.
| |
| 38 } | 43 } |
| 39 | 44 |
| 40 } // namespace base | 45 } // namespace base |
| OLD | NEW |