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

Side by Side Diff: base/supports_user_data.cc

Issue 1641563002: Remove linked_ptr usage in //base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase, really Created 4 years, 10 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') | base/threading/sequenced_worker_pool.cc » ('j') | 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 namespace base { 7 namespace base {
8 8
9 SupportsUserData::SupportsUserData() { 9 SupportsUserData::SupportsUserData() {
10 // Harmless to construct on a different thread to subsequent usage. 10 // Harmless to construct on a different thread to subsequent usage.
11 thread_checker_.DetachFromThread(); 11 thread_checker_.DetachFromThread();
12 } 12 }
13 13
14 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const { 14 SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {
15 DCHECK(thread_checker_.CalledOnValidThread()); 15 DCHECK(thread_checker_.CalledOnValidThread());
16 DataMap::const_iterator found = user_data_.find(key); 16 DataMap::const_iterator found = user_data_.find(key);
17 if (found != user_data_.end()) 17 if (found != user_data_.end())
18 return found->second.get(); 18 return found->second.get();
19 return NULL; 19 return NULL;
20 } 20 }
21 21
22 void SupportsUserData::SetUserData(const void* key, Data* data) { 22 void SupportsUserData::SetUserData(const void* key, Data* data) {
23 DCHECK(thread_checker_.CalledOnValidThread()); 23 DCHECK(thread_checker_.CalledOnValidThread());
24 user_data_[key] = linked_ptr<Data>(data); 24 user_data_[key] = make_scoped_ptr(data);
25 } 25 }
26 26
27 void SupportsUserData::RemoveUserData(const void* key) { 27 void SupportsUserData::RemoveUserData(const void* key) {
28 DCHECK(thread_checker_.CalledOnValidThread()); 28 DCHECK(thread_checker_.CalledOnValidThread());
29 user_data_.erase(key); 29 user_data_.erase(key);
30 } 30 }
31 31
32 void SupportsUserData::DetachUserDataThread() { 32 void SupportsUserData::DetachUserDataThread() {
33 thread_checker_.DetachFromThread(); 33 thread_checker_.DetachFromThread();
34 } 34 }
35 35
36 SupportsUserData::~SupportsUserData() { 36 SupportsUserData::~SupportsUserData() {
37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty()); 37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty());
38 DataMap local_user_data; 38 DataMap local_user_data;
39 user_data_.swap(local_user_data); 39 user_data_.swap(local_user_data);
40 // Now this->user_data_ is empty, and any destructors called transitively from 40 // Now this->user_data_ is empty, and any destructors called transitively from
41 // the destruction of |local_user_data| will see it that way instead of 41 // the destruction of |local_user_data| will see it that way instead of
42 // examining a being-destroyed object. 42 // examining a being-destroyed object.
43 } 43 }
44 44
45 } // namespace base 45 } // namespace base
OLDNEW
« no previous file with comments | « base/supports_user_data.h ('k') | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698