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

Unified Diff: mojo/common/handle_watcher.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.cc ('k') | mojo/common/handle_watcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/handle_watcher.cc
diff --git a/mojo/common/handle_watcher.cc b/mojo/common/handle_watcher.cc
index 150305c00f264a9bcf958c693b4de99989b72ce6..a95669c5803056037723de81df2a84e391fd7881 100644
--- a/mojo/common/handle_watcher.cc
+++ b/mojo/common/handle_watcher.cc
@@ -12,8 +12,10 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
+#include "mojo/common/environment_data.h"
#include "mojo/common/message_pump_mojo.h"
#include "mojo/common/message_pump_mojo_handler.h"
#include "mojo/common/time_helper.h"
@@ -27,6 +29,8 @@ namespace {
const char kWatcherThreadName[] = "handle-watcher-thread";
+const char kWatcherThreadManagerKey[] = "watcher-thread-manager";
+
// TODO(sky): this should be unnecessary once MessageLoop has been refactored.
MessagePumpMojo* message_pump_mojo = NULL;
@@ -153,6 +157,8 @@ void WatcherBackend::OnHandleError(const Handle& handle, MojoResult result) {
// to be ready. All requests are handled by WatcherBackend.
class WatcherThreadManager {
public:
+ ~WatcherThreadManager();
+
// Returns the shared instance.
static WatcherThreadManager* GetInstance();
@@ -170,10 +176,7 @@ class WatcherThreadManager {
void StopWatching(WatcherID watcher_id);
private:
- friend struct base::DefaultLazyInstanceTraits<WatcherThreadManager>;
-
WatcherThreadManager();
- ~WatcherThreadManager();
base::Thread thread_;
@@ -184,10 +187,29 @@ class WatcherThreadManager {
DISALLOW_COPY_AND_ASSIGN(WatcherThreadManager);
};
+struct WatcherThreadManagerData : EnvironmentData::Data {
+ scoped_ptr<WatcherThreadManager> thread_manager;
+};
+
+WatcherThreadManager::~WatcherThreadManager() {
+ thread_.Stop();
+}
+
+static base::LazyInstance<base::Lock> thread_lookup_lock =
+ LAZY_INSTANCE_INITIALIZER;
+
WatcherThreadManager* WatcherThreadManager::GetInstance() {
- static base::LazyInstance<WatcherThreadManager> instance =
- LAZY_INSTANCE_INITIALIZER;
- return &instance.Get();
+ base::AutoLock auto_lock(thread_lookup_lock.Get());
+ WatcherThreadManagerData* data = static_cast<WatcherThreadManagerData*>(
+ EnvironmentData::GetInstance()->GetData(kWatcherThreadManagerKey));
+ if (!data) {
+ data = new WatcherThreadManagerData;
+ data->thread_manager.reset(new WatcherThreadManager);
+ EnvironmentData::GetInstance()->SetData(
+ kWatcherThreadManagerKey,
+ scoped_ptr<EnvironmentData::Data>(data));
+ }
+ return data->thread_manager.get();
}
WatcherID WatcherThreadManager::StartWatching(
@@ -229,10 +251,6 @@ WatcherThreadManager::WatcherThreadManager()
thread_.StartWithOptions(thread_options);
}
-WatcherThreadManager::~WatcherThreadManager() {
- thread_.Stop();
-}
-
} // namespace
// HandleWatcher::StartState ---------------------------------------------------
« no previous file with comments | « mojo/common/environment_data.cc ('k') | mojo/common/handle_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698