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. |
11 thread_checker_.DetachFromThread(); | 11 thread_checker_.DetachFromThread(); |
12 } | 12 } |
13 | 13 |
| 14 SupportsUserData::~SupportsUserData() { |
| 15 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); |
| 16 } |
| 17 |
14 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { | 18 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { |
15 DCHECK(thread_checker_.CalledOnValidThread()); | 19 DCHECK(thread_checker_.CalledOnValidThread()); |
16 DataMap::const_iterator found = user_data_.find(key); | 20 DataMap::const_iterator found = user_data_.find(key); |
17 if (found != user_data_.end()) | 21 if (found != user_data_.end()) |
18 return found->second.get(); | 22 return found->second.get(); |
19 return NULL; | 23 return NULL; |
20 } | 24 } |
21 | 25 |
22 void SupportsUserData::SetUserData(const void* key, Data* data) { | 26 void SupportsUserData::SetUserData(const void* key, Data* data) { |
23 DCHECK(thread_checker_.CalledOnValidThread()); | 27 DCHECK(thread_checker_.CalledOnValidThread()); |
24 user_data_[key] = linked_ptr<Data>(data); | 28 user_data_[key] = linked_ptr<Data>(data); |
25 } | 29 } |
26 | 30 |
27 void SupportsUserData::RemoveUserData(const void* key) { | 31 void SupportsUserData::RemoveUserData(const void* key) { |
28 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
29 user_data_.erase(key); | 33 user_data_.erase(key); |
30 } | 34 } |
31 | 35 |
32 void SupportsUserData::DetachUserDataThread() { | 36 void SupportsUserData::DetachUserDataThread() { |
33 thread_checker_.DetachFromThread(); | 37 thread_checker_.DetachFromThread(); |
34 } | 38 } |
35 | 39 |
36 SupportsUserData::~SupportsUserData() { | |
37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); | |
38 } | |
39 | |
40 } // namespace base | 40 } // namespace base |
OLD | NEW |