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

Side by Side Diff: mojo/common/environment_data.cc

Issue 218583009: Adds a way to associate key/value pairs with the environment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make mojo_service_manager depend on mojo_common_lib Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/common/environment_data.h ('k') | mojo/common/handle_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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 "mojo/common/environment_data.h"
6
7 #include "base/stl_util.h"
8
9 namespace mojo {
10 namespace common {
11
12 // static
13 EnvironmentData* EnvironmentData::instance_ = NULL;
14
15 EnvironmentData::EnvironmentData() {
16 DCHECK(!instance_);
17 instance_ = this;
18 }
19
20 EnvironmentData::~EnvironmentData() {
21 instance_ = NULL;
22 DataMap data_map;
23 data_map.swap(data_map_);
24 STLDeleteContainerPairSecondPointers(data_map.begin(), data_map.end());
25 }
26
27 // static
28 EnvironmentData* EnvironmentData::GetInstance() {
29 return instance_;
30 }
31
32 void EnvironmentData::SetData(const void* key, scoped_ptr<Data> data) {
33 Data* old = NULL;
34 {
35 base::AutoLock auto_lock(data_lock_);
36 old = data_map_[key];
37 if (data)
38 data_map_[key] = data.release();
39 else
40 data_map_.erase(key);
41 }
42 delete old;
43 }
44
45 EnvironmentData::Data* EnvironmentData::GetData(const void* key) {
46 base::AutoLock auto_lock(data_lock_);
47 return data_map_.count(key) > 0 ? data_map_[key] : NULL;
48 }
49
50 } // namespace common
51 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/environment_data.h ('k') | mojo/common/handle_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698