Chromium Code Reviews| 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..268dc12940c027f18e6f977565581407eb8f2a53 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,13 @@ 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() { |
| + g_tls_current_pump.Pointer()->Set(NULL); |
|
sky
2014/08/27 21:37:27
DCHECK that this is the current pointer.
yzshen1
2014/08/27 22:31:48
Done.
|
| } |
| // static |
| @@ -62,6 +71,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, |