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

Unified Diff: trunk/src/mojo/common/handle_watcher.cc

Issue 299263002: Revert 272472 "Mojo: nuke EnvironmentData" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | « trunk/src/mojo/common/environment_data.cc ('k') | trunk/src/mojo/common/handle_watcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/mojo/common/handle_watcher.cc
===================================================================
--- trunk/src/mojo/common/handle_watcher.cc (revision 272588)
+++ trunk/src/mojo/common/handle_watcher.cc (working copy)
@@ -9,13 +9,13 @@
#include "base/atomic_sequence_num.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
-#include "base/memory/singleton.h"
#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"
@@ -29,6 +29,8 @@
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;
@@ -174,7 +176,6 @@
void StopWatching(WatcherID watcher_id);
private:
- friend struct DefaultSingletonTraits<WatcherThreadManager>;
WatcherThreadManager();
base::Thread thread_;
@@ -186,12 +187,29 @@
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() {
- return Singleton<WatcherThreadManager>::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(
« no previous file with comments | « trunk/src/mojo/common/environment_data.cc ('k') | trunk/src/mojo/common/handle_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698