blob: 2a0263ed0d1881e6552f04b44a34fadf3e441cb2 [file] [log] [blame]
[email protected]ea8e1812012-02-15 22:07:341// 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
3// found in the LICENSE file.
4
5#include "base/supports_user_data.h"
6
7namespace base {
8
[email protected]7d2e5f7622012-09-10 19:18:539SupportsUserData::SupportsUserData() {
10 // Harmless to construct on a different thread to subsequent usage.
11 thread_checker_.DetachFromThread();
12}
[email protected]ea8e1812012-02-15 22:07:3413
14SupportsUserData::Data* SupportsUserData::GetUserData(const void* key) const {
[email protected]7d2e5f7622012-09-10 19:18:5315 DCHECK(thread_checker_.CalledOnValidThread());
[email protected]ea8e1812012-02-15 22:07:3416 DataMap::const_iterator found = user_data_.find(key);
17 if (found != user_data_.end())
18 return found->second.get();
19 return NULL;
20}
21
22void SupportsUserData::SetUserData(const void* key, Data* data) {
[email protected]7d2e5f7622012-09-10 19:18:5323 DCHECK(thread_checker_.CalledOnValidThread());
[email protected]ea8e1812012-02-15 22:07:3424 user_data_[key] = linked_ptr<Data>(data);
25}
26
[email protected]27ee16f2012-08-12 02:25:1327void SupportsUserData::RemoveUserData(const void* key) {
[email protected]7d2e5f7622012-09-10 19:18:5328 DCHECK(thread_checker_.CalledOnValidThread());
[email protected]27ee16f2012-08-12 02:25:1329 user_data_.erase(key);
30}
31
[email protected]7d2e5f7622012-09-10 19:18:5332void SupportsUserData::DetachUserDataThread() {
33 thread_checker_.DetachFromThread();
34}
35
36SupportsUserData::~SupportsUserData() {
37 DCHECK(thread_checker_.CalledOnValidThread() || user_data_.empty());
38}
[email protected]cb932482012-06-26 06:23:0039
[email protected]ea8e1812012-02-15 22:07:3440} // namespace base