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

Side by Side Diff: base/supports_user_data.cc

Issue 2860613003: Remove the deprecated raw-pointer call from SupportsUserData (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/supports_user_data.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
8
9 namespace base { 7 namespace base {
10 8
11 SupportsUserData::SupportsUserData() { 9 SupportsUserData::SupportsUserData() {
12 // Harmless to construct on a different execution sequence to subsequent 10 // Harmless to construct on a different execution sequence to subsequent
13 // usage. 11 // usage.
14 sequence_checker_.DetachFromSequence(); 12 sequence_checker_.DetachFromSequence();
15 } 13 }
16 14
17 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { 15 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {
18 DCHECK(sequence_checker_.CalledOnValidSequence()); 16 DCHECK(sequence_checker_.CalledOnValidSequence());
19 DataMap::const_iterator found = user_data_.find(key); 17 DataMap::const_iterator found = user_data_.find(key);
20 if (found != user_data_.end()) 18 if (found != user_data_.end())
21 return found->second.get(); 19 return found->second.get();
22 return NULL; 20 return nullptr;
23 }
24
25 void SupportsUserData::SetUserData(const void* key, Data* data) {
26 SetUserData(key, WrapUnique(data));
27 } 21 }
28 22
29 void SupportsUserData::SetUserData(const void* key, 23 void SupportsUserData::SetUserData(const void* key,
30 std::unique_ptr<Data> data) { 24 std::unique_ptr<Data> data) {
31 DCHECK(sequence_checker_.CalledOnValidSequence()); 25 DCHECK(sequence_checker_.CalledOnValidSequence());
32 user_data_[key] = std::move(data); 26 user_data_[key] = std::move(data);
33 } 27 }
34 28
35 void SupportsUserData::RemoveUserData(const void* key) { 29 void SupportsUserData::RemoveUserData(const void* key) {
36 DCHECK(sequence_checker_.CalledOnValidSequence()); 30 DCHECK(sequence_checker_.CalledOnValidSequence());
37 user_data_.erase(key); 31 user_data_.erase(key);
38 } 32 }
39 33
40 void SupportsUserData::DetachFromSequence() { 34 void SupportsUserData::DetachFromSequence() {
41 sequence_checker_.DetachFromSequence(); 35 sequence_checker_.DetachFromSequence();
42 } 36 }
43 37
44 SupportsUserData::~SupportsUserData() { 38 SupportsUserData::~SupportsUserData() {
45 DCHECK(sequence_checker_.CalledOnValidSequence() || user_data_.empty()); 39 DCHECK(sequence_checker_.CalledOnValidSequence() || user_data_.empty());
46 DataMap local_user_data; 40 DataMap local_user_data;
47 user_data_.swap(local_user_data); 41 user_data_.swap(local_user_data);
48 // Now this->user_data_ is empty, and any destructors called transitively from 42 // Now this->user_data_ is empty, and any destructors called transitively from
49 // the destruction of |local_user_data| will see it that way instead of 43 // the destruction of |local_user_data| will see it that way instead of
50 // examining a being-destroyed object. 44 // examining a being-destroyed object.
51 } 45 }
52 46
53 } // namespace base 47 } // namespace base
OLDNEW
« no previous file with comments | « base/supports_user_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698