Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4331)

Unified Diff: base/supports_user_data.cc

Issue 10919137: SupportsUserData is not thread safe (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed indexeddb test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/supports_user_data.h ('k') | content/browser/in_process_webkit/indexed_db_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/supports_user_data.h ('k') | content/browser/in_process_webkit/indexed_db_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698