| Index: base/message_loop/message_loop.cc
|
| diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
|
| index daa7782e5216879b577a33c0b35f602bf369db5d..ba61031b960aa28c37551465108bdb7d19279d40 100644
|
| --- a/base/message_loop/message_loop.cc
|
| +++ b/base/message_loop/message_loop.cc
|
| @@ -100,10 +100,26 @@ MessagePumpForIO* ToPumpIO(MessagePump* pump) {
|
| }
|
| #endif // !defined(OS_NACL_SFI)
|
|
|
| +MessageLoop::Type GetMessageLoopType(MessageLoop::LazyInitOptions* options) {
|
| + if (options->message_pump_factory.is_null())
|
| + return options->message_loop_type;
|
| + return MessageLoop::TYPE_CUSTOM;
|
| +}
|
| +
|
| } // namespace
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| +MessageLoop::LazyInitOptions::LazyInitOptions()
|
| + : message_loop_type(MessageLoop::TYPE_DEFAULT),
|
| + timer_slack(TIMER_SLACK_NONE) {
|
| +}
|
| +
|
| +MessageLoop::LazyInitOptions::~LazyInitOptions() {
|
| +}
|
| +
|
| +//------------------------------------------------------------------------------
|
| +
|
| MessageLoop::TaskObserver::TaskObserver() {
|
| }
|
|
|
| @@ -150,6 +166,16 @@ MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
|
| }
|
|
|
| MessageLoop::~MessageLoop() {
|
| + if (lazy_init_options_) {
|
| + // This message loop is destructed before we call LazyInit.
|
| + DCHECK(current() == NULL);
|
| + DCHECK(incoming_task_queue_->empty());
|
| + DCHECK(!pump_);
|
| + DCHECK(!destruction_observers_.might_have_observers());
|
| + incoming_task_queue_->WillDestroyCurrentMessageLoop();
|
| + return;
|
| + }
|
| +
|
| DCHECK_EQ(this, current());
|
|
|
| // iOS just attaches to the loop, it doesn't Run it.
|
| @@ -195,6 +221,12 @@ MessageLoop::~MessageLoop() {
|
| }
|
|
|
| // static
|
| +MessageLoop* MessageLoop::CreateForLazyInit(
|
| + scoped_ptr<LazyInitOptions> options) {
|
| + return new MessageLoop(options.Pass());
|
| +}
|
| +
|
| +// static
|
| MessageLoop* MessageLoop::current() {
|
| // TODO(darin): sadly, we cannot enable this yet since people call us even
|
| // when they have no intention of using us.
|
| @@ -260,6 +292,27 @@ scoped_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {
|
| return MESSAGE_PUMP_DEFAULT;
|
| }
|
|
|
| +void MessageLoop::LazyInit() {
|
| + DCHECK(lazy_init_options_)
|
| + << "should be called only when created for lazy init";
|
| + DCHECK(!current()) << "should only have one message loop per thread";
|
| + lazy_tls_ptr.Pointer()->Set(this);
|
| +
|
| + if (!lazy_init_options_->message_pump_factory.is_null()) {
|
| + pump_ = lazy_init_options_->message_pump_factory.Run().Pass();
|
| + } else {
|
| + pump_ =
|
| + CreateMessagePumpForType(lazy_init_options_->message_loop_type).Pass();
|
| + }
|
| + SetTimerSlack(lazy_init_options_->timer_slack);
|
| + lazy_init_options_.reset();
|
| +
|
| + incoming_task_queue_->DidInitializeMessageLoop();
|
| + message_loop_proxy_->LazyInit();
|
| + thread_task_runner_handle_.reset(
|
| + new ThreadTaskRunnerHandle(message_loop_proxy_));
|
| +}
|
| +
|
| void MessageLoop::AddDestructionObserver(
|
| DestructionObserver* destruction_observer) {
|
| DCHECK_EQ(this, current());
|
| @@ -303,11 +356,13 @@ void MessageLoop::PostNonNestableDelayedTask(
|
| }
|
|
|
| void MessageLoop::Run() {
|
| + DCHECK(!lazy_init_options_);
|
| RunLoop run_loop;
|
| run_loop.Run();
|
| }
|
|
|
| void MessageLoop::RunUntilIdle() {
|
| + DCHECK(!lazy_init_options_);
|
| RunLoop run_loop;
|
| run_loop.RunUntilIdle();
|
| }
|
| @@ -387,13 +442,34 @@ bool MessageLoop::IsIdleForTesting() {
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| +MessageLoop::MessageLoop(scoped_ptr<LazyInitOptions> options)
|
| + : type_(GetMessageLoopType(options.get())),
|
| +#if defined(OS_WIN)
|
| + pending_high_res_tasks_(0),
|
| + in_high_res_mode_(false),
|
| +#endif
|
| + nestable_tasks_allowed_(true),
|
| +#if defined(OS_WIN)
|
| + os_modal_loop_(false),
|
| +#endif // OS_WIN
|
| + lazy_init_options_(options.Pass()),
|
| + message_histogram_(NULL),
|
| + run_loop_(NULL) {
|
| + incoming_task_queue_ =
|
| + internal::IncomingTaskQueue::CreateForLazyInitMessageLoop(this);
|
| + message_loop_proxy_ =
|
| + internal::MessageLoopProxyImpl::CreateForLazyInit(incoming_task_queue_);
|
| +}
|
| +
|
| void MessageLoop::Init() {
|
| + DCHECK(!lazy_init_options_) << "should not be called when created for "
|
| + "lazy initialization";
|
| DCHECK(!current()) << "should only have one message loop per thread";
|
| lazy_tls_ptr.Pointer()->Set(this);
|
|
|
| incoming_task_queue_ = new internal::IncomingTaskQueue(this);
|
| message_loop_proxy_ =
|
| - new internal::MessageLoopProxyImpl(incoming_task_queue_);
|
| + internal::MessageLoopProxyImpl::Create(incoming_task_queue_);
|
| thread_task_runner_handle_.reset(
|
| new ThreadTaskRunnerHandle(message_loop_proxy_));
|
| }
|
|
|