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

Side by Side Diff: base/supports_user_data.cc

Issue 2597773002: Make SupportsUserData sequence-affine instead of thread-affine. (Closed)
Patch Set: leave thread_checker.h include for now Created 4 years 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 unified diff | Download patch
OLDNEW
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 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 SupportsUserData::SupportsUserData() { 11 SupportsUserData::SupportsUserData() {
12 // Harmless to construct on a different thread to subsequent usage. 12 // Harmless to construct on a different execution sequence to subsequent
13 thread_checker_.DetachFromThread(); 13 // usage.
14 sequence_checker_.DetachFromSequence();
14 } 15 }
15 16
16 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { 17 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {
17 DCHECK(thread_checker_.CalledOnValidThread()); 18 DCHECK(sequence_checker_.CalledOnValidSequence());
18 DataMap::const_iterator found = user_data_.find(key); 19 DataMap::const_iterator found = user_data_.find(key);
19 if (found != user_data_.end()) 20 if (found != user_data_.end())
20 return found->second.get(); 21 return found->second.get();
21 return NULL; 22 return NULL;
22 } 23 }
23 24
24 void SupportsUserData::SetUserData(const void* key, Data* data) { 25 void SupportsUserData::SetUserData(const void* key, Data* data) {
25 DCHECK(thread_checker_.CalledOnValidThread()); 26 DCHECK(sequence_checker_.CalledOnValidSequence());
26 user_data_[key] = WrapUnique(data); 27 user_data_[key] = WrapUnique(data);
27 } 28 }
28 29
29 void SupportsUserData::RemoveUserData(const void* key) { 30 void SupportsUserData::RemoveUserData(const void* key) {
30 DCHECK(thread_checker_.CalledOnValidThread()); 31 DCHECK(sequence_checker_.CalledOnValidSequence());
31 user_data_.erase(key); 32 user_data_.erase(key);
32 } 33 }
33 34
34 void SupportsUserData::DetachUserDataThread() { 35 void SupportsUserData::DetachFromSequence() {
35 thread_checker_.DetachFromThread(); 36 sequence_checker_.DetachFromSequence();
36 } 37 }
37 38
38 SupportsUserData::~SupportsUserData() { 39 SupportsUserData::~SupportsUserData() {
39 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); 40 DCHECK(sequence_checker_.CalledOnValidSequence() || user_data_.empty());
40 DataMap local_user_data; 41 DataMap local_user_data;
41 user_data_.swap(local_user_data); 42 user_data_.swap(local_user_data);
42 // Now this->user_data_ is empty, and any destructors called transitively from 43 // Now this->user_data_ is empty, and any destructors called transitively from
43 // the destruction of |local_user_data| will see it that way instead of 44 // the destruction of |local_user_data| will see it that way instead of
44 // examining a being-destroyed object. 45 // examining a being-destroyed object.
45 } 46 }
46 47
47 } // namespace base 48 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698