| Index: mojo/common/message_pump_mojo.cc
|
| diff --git a/mojo/common/message_pump_mojo.cc b/mojo/common/message_pump_mojo.cc
|
| index a2275925876143315fa45f61d0b98c7fbe0fbbfc..91b78d1ae4fde79c967bbca657a118119f8efbc5 100644
|
| --- a/mojo/common/message_pump_mojo.cc
|
| +++ b/mojo/common/message_pump_mojo.cc
|
| @@ -8,7 +8,9 @@
|
| #include <vector>
|
|
|
| #include "base/debug/alias.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| +#include "base/threading/thread_local.h"
|
| #include "base/time/time.h"
|
| #include "mojo/common/message_pump_mojo_handler.h"
|
| #include "mojo/common/time_helper.h"
|
| @@ -17,6 +19,9 @@ namespace mojo {
|
| namespace common {
|
| namespace {
|
|
|
| +base::LazyInstance<base::ThreadLocalPointer<MessagePumpMojo> >::Leaky
|
| + g_tls_current_pump = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| MojoDeadline TimeTicksToMojoDeadline(base::TimeTicks time_ticks,
|
| base::TimeTicks now) {
|
| // The is_null() check matches that of HandleWatcher as well as how
|
| @@ -52,9 +57,14 @@ struct MessagePumpMojo::RunState {
|
| };
|
|
|
| MessagePumpMojo::MessagePumpMojo() : run_state_(NULL), next_handler_id_(0) {
|
| + DCHECK(!current())
|
| + << "There is already a MessagePumpMojo instance on this thread.";
|
| + g_tls_current_pump.Pointer()->Set(this);
|
| }
|
|
|
| MessagePumpMojo::~MessagePumpMojo() {
|
| + DCHECK_EQ(this, current());
|
| + g_tls_current_pump.Pointer()->Set(NULL);
|
| }
|
|
|
| // static
|
| @@ -62,6 +72,11 @@ scoped_ptr<base::MessagePump> MessagePumpMojo::Create() {
|
| return scoped_ptr<MessagePump>(new MessagePumpMojo());
|
| }
|
|
|
| +// static
|
| +MessagePumpMojo* MessagePumpMojo::current() {
|
| + return g_tls_current_pump.Pointer()->Get();
|
| +}
|
| +
|
| void MessagePumpMojo::AddHandler(MessagePumpMojoHandler* handler,
|
| const Handle& handle,
|
| MojoHandleSignals wait_signals,
|
|
|