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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/common/environment_data.h ('k') | mojo/common/handle_watcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/environment_data.cc
diff --git a/mojo/common/environment_data.cc b/mojo/common/environment_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0fcef667dc4c37af288f09e3e74c1786e9c4b52a
--- /dev/null
+++ b/mojo/common/environment_data.cc
@@ -0,0 +1,51 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/common/environment_data.h"
+
+#include "base/stl_util.h"
+
+namespace mojo {
+namespace common {
+
+// static
+EnvironmentData* EnvironmentData::instance_ = NULL;
+
+EnvironmentData::EnvironmentData() {
+ DCHECK(!instance_);
+ instance_ = this;
+}
+
+EnvironmentData::~EnvironmentData() {
+ instance_ = NULL;
+ DataMap data_map;
+ data_map.swap(data_map_);
+ STLDeleteContainerPairSecondPointers(data_map.begin(), data_map.end());
+}
+
+// static
+EnvironmentData* EnvironmentData::GetInstance() {
+ return instance_;
+}
+
+void EnvironmentData::SetData(const void* key, scoped_ptr<Data> data) {
+ Data* old = NULL;
+ {
+ base::AutoLock auto_lock(data_lock_);
+ old = data_map_[key];
+ if (data)
+ data_map_[key] = data.release();
+ else
+ data_map_.erase(key);
+ }
+ delete old;
+}
+
+EnvironmentData::Data* EnvironmentData::GetData(const void* key) {
+ base::AutoLock auto_lock(data_lock_);
+ return data_map_.count(key) > 0 ? data_map_[key] : NULL;
+}
+
+} // namespace common
+} // namespace mojo
« 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