| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 MessageLoop::NestingObserver::~NestingObserver() {} | 78 MessageLoop::NestingObserver::~NestingObserver() {} |
| 79 | 79 |
| 80 //------------------------------------------------------------------------------ | 80 //------------------------------------------------------------------------------ |
| 81 | 81 |
| 82 MessageLoop::MessageLoop(Type type) | 82 MessageLoop::MessageLoop(Type type) |
| 83 : MessageLoop(type, MessagePumpFactoryCallback()) { | 83 : MessageLoop(type, MessagePumpFactoryCallback()) { |
| 84 BindToCurrentThread(); | 84 BindToCurrentThread(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 MessageLoop::MessageLoop(std::unique_ptr<MessagePump> pump) | 87 MessageLoop::MessageLoop(std::unique_ptr<MessagePump> pump) |
| 88 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { | 88 : MessageLoop(TYPE_CUSTOM, BindOnce(&ReturnPump, Passed(&pump))) { |
| 89 BindToCurrentThread(); | 89 BindToCurrentThread(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 MessageLoop::~MessageLoop() { | 92 MessageLoop::~MessageLoop() { |
| 93 // If |pump_| is non-null, this message loop has been bound and should be the | 93 // If |pump_| is non-null, this message loop has been bound and should be the |
| 94 // current one on this thread. Otherwise, this loop is being destructed before | 94 // current one on this thread. Otherwise, this loop is being destructed before |
| 95 // it was bound to a thread, so a different message loop (or no loop at all) | 95 // it was bound to a thread, so a different message loop (or no loop at all) |
| 96 // may be current. | 96 // may be current. |
| 97 DCHECK((pump_ && current() == this) || (!pump_ && current() != this)); | 97 DCHECK((pump_ && current() == this) || (!pump_ && current() != this)); |
| 98 | 98 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // queue. | 302 // queue. |
| 303 return incoming_task_queue_->IsIdleForTesting(); | 303 return incoming_task_queue_->IsIdleForTesting(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 //------------------------------------------------------------------------------ | 306 //------------------------------------------------------------------------------ |
| 307 | 307 |
| 308 // static | 308 // static |
| 309 std::unique_ptr<MessageLoop> MessageLoop::CreateUnbound( | 309 std::unique_ptr<MessageLoop> MessageLoop::CreateUnbound( |
| 310 Type type, | 310 Type type, |
| 311 MessagePumpFactoryCallback pump_factory) { | 311 MessagePumpFactoryCallback pump_factory) { |
| 312 return WrapUnique(new MessageLoop(type, pump_factory)); | 312 return WrapUnique(new MessageLoop(type, std::move(pump_factory))); |
| 313 } | 313 } |
| 314 | 314 |
| 315 MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) | 315 MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) |
| 316 : type_(type), | 316 : type_(type), |
| 317 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
| 318 pending_high_res_tasks_(0), | 318 pending_high_res_tasks_(0), |
| 319 in_high_res_mode_(false), | 319 in_high_res_mode_(false), |
| 320 #endif | 320 #endif |
| 321 nestable_tasks_allowed_(true), | 321 nestable_tasks_allowed_(true), |
| 322 pump_factory_(pump_factory), | 322 pump_factory_(std::move(pump_factory)), |
| 323 run_loop_(nullptr), | 323 run_loop_(nullptr), |
| 324 current_pending_task_(nullptr), | 324 current_pending_task_(nullptr), |
| 325 incoming_task_queue_(new internal::IncomingTaskQueue(this)), | 325 incoming_task_queue_(new internal::IncomingTaskQueue(this)), |
| 326 unbound_task_runner_( | 326 unbound_task_runner_( |
| 327 new internal::MessageLoopTaskRunner(incoming_task_queue_)), | 327 new internal::MessageLoopTaskRunner(incoming_task_queue_)), |
| 328 task_runner_(unbound_task_runner_), | 328 task_runner_(unbound_task_runner_), |
| 329 thread_id_(kInvalidThreadId) { | 329 thread_id_(kInvalidThreadId) { |
| 330 // If type is TYPE_CUSTOM non-null pump_factory must be given. | 330 // If type is TYPE_CUSTOM non-null pump_factory must be given. |
| 331 DCHECK(type_ != TYPE_CUSTOM || !pump_factory_.is_null()); | 331 DCHECK(type_ != TYPE_CUSTOM || !pump_factory_.is_null()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void MessageLoop::BindToCurrentThread() { | 334 void MessageLoop::BindToCurrentThread() { |
| 335 DCHECK(!pump_); | 335 DCHECK(!pump_); |
| 336 if (!pump_factory_.is_null()) | 336 if (!pump_factory_.is_null()) |
| 337 pump_ = pump_factory_.Run(); | 337 pump_ = std::move(pump_factory_).Run(); |
| 338 else | 338 else |
| 339 pump_ = CreateMessagePumpForType(type_); | 339 pump_ = CreateMessagePumpForType(type_); |
| 340 | 340 |
| 341 DCHECK(!current()) << "should only have one message loop per thread"; | 341 DCHECK(!current()) << "should only have one message loop per thread"; |
| 342 GetTLSMessageLoop()->Set(this); | 342 GetTLSMessageLoop()->Set(this); |
| 343 | 343 |
| 344 incoming_task_queue_->StartScheduling(); | 344 incoming_task_queue_->StartScheduling(); |
| 345 unbound_task_runner_->BindToCurrentThread(); | 345 unbound_task_runner_->BindToCurrentThread(); |
| 346 unbound_task_runner_ = nullptr; | 346 unbound_task_runner_ = nullptr; |
| 347 SetThreadTaskRunnerHandle(); | 347 SetThreadTaskRunnerHandle(); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 } | 586 } |
| 587 #endif | 587 #endif |
| 588 return false; | 588 return false; |
| 589 } | 589 } |
| 590 | 590 |
| 591 #if !defined(OS_NACL) | 591 #if !defined(OS_NACL) |
| 592 //------------------------------------------------------------------------------ | 592 //------------------------------------------------------------------------------ |
| 593 // MessageLoopForUI | 593 // MessageLoopForUI |
| 594 | 594 |
| 595 MessageLoopForUI::MessageLoopForUI(std::unique_ptr<MessagePump> pump) | 595 MessageLoopForUI::MessageLoopForUI(std::unique_ptr<MessagePump> pump) |
| 596 : MessageLoop(TYPE_UI, Bind(&ReturnPump, Passed(&pump))) {} | 596 : MessageLoop(TYPE_UI, BindOnce(&ReturnPump, std::move(pump))) {} |
| 597 | 597 |
| 598 #if defined(OS_ANDROID) | 598 #if defined(OS_ANDROID) |
| 599 void MessageLoopForUI::Start() { | 599 void MessageLoopForUI::Start() { |
| 600 // No Histogram support for UI message loop as it is managed by Java side | 600 // No Histogram support for UI message loop as it is managed by Java side |
| 601 static_cast<MessagePumpForUI*>(pump_.get())->Start(this); | 601 static_cast<MessagePumpForUI*>(pump_.get())->Start(this); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void MessageLoopForUI::StartForTesting( | 604 void MessageLoopForUI::StartForTesting( |
| 605 base::android::JavaMessageHandlerFactory* factory, | 605 base::android::JavaMessageHandlerFactory* factory, |
| 606 WaitableEvent* test_done_event) { | 606 WaitableEvent* test_done_event) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 persistent, | 666 persistent, |
| 667 mode, | 667 mode, |
| 668 controller, | 668 controller, |
| 669 delegate); | 669 delegate); |
| 670 } | 670 } |
| 671 #endif | 671 #endif |
| 672 | 672 |
| 673 #endif // !defined(OS_NACL_SFI) | 673 #endif // !defined(OS_NACL_SFI) |
| 674 | 674 |
| 675 } // namespace base | 675 } // namespace base |
| OLD | NEW |