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