Chromium Code Reviews| Index: base/supports_user_data.cc |
| diff --git a/base/supports_user_data.cc b/base/supports_user_data.cc |
| index b2f1228ce341295f2eba55271b371551df16613d..2a0263ed0d1881e6552f04b44a34fadf3e441cb2 100644 |
| --- a/base/supports_user_data.cc |
| +++ b/base/supports_user_data.cc |
| @@ -6,9 +6,13 @@ |
| namespace base { |
| -SupportsUserData::SupportsUserData() {} |
| +SupportsUserData::SupportsUserData() { |
| + // Harmless to construct on a different thread to subsequent usage. |
|
Avi (use Gerrit)
2012/09/08 17:33:51
Technically speaking, it might not be. If it's imm
joth
2012/09/08 21:33:41
Even if the subclass sends |this| to another threa
Avi (use Gerrit)
2012/09/09 00:03:58
That's an assumption that surprises me. Do we put
|
| + thread_checker_.DetachFromThread(); |
| +} |
| SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| DataMap::const_iterator found = user_data_.find(key); |
| if (found != user_data_.end()) |
| return found->second.get(); |
| @@ -16,13 +20,21 @@ SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { |
| } |
| void SupportsUserData::SetUserData(const void* key, Data* data) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| user_data_[key] = linked_ptr<Data>(data); |
| } |
| void SupportsUserData::RemoveUserData(const void* key) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| user_data_.erase(key); |
| } |
| -SupportsUserData::~SupportsUserData() {} |
| +void SupportsUserData::DetachUserDataThread() { |
| + thread_checker_.DetachFromThread(); |
| +} |
| + |
| +SupportsUserData::~SupportsUserData() { |
| + DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); |
|
Avi (use Gerrit)
2012/09/08 17:33:51
Not entirely convinced this is technically safe, b
joth
2012/09/08 21:33:41
yep... I converged on the same compromise in Notif
|
| +} |
| } // namespace base |