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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 } | 360 } |
361 | 361 |
362 bool MessageLoop::IsIdleForTesting() { | 362 bool MessageLoop::IsIdleForTesting() { |
363 // We only check the imcoming queue|, since we don't want to lock the work | 363 // We only check the imcoming queue|, since we don't want to lock the work |
364 // queue. | 364 // queue. |
365 return incoming_task_queue_->IsIdleForTesting(); | 365 return incoming_task_queue_->IsIdleForTesting(); |
366 } | 366 } |
367 | 367 |
368 //------------------------------------------------------------------------------ | 368 //------------------------------------------------------------------------------ |
369 | 369 |
370 // static | |
370 scoped_ptr<MessageLoop> MessageLoop::CreateUnbound( | 371 scoped_ptr<MessageLoop> MessageLoop::CreateUnbound( |
371 Type type, MessagePumpFactoryCallback pump_factory) { | 372 Type type, MessagePumpFactoryCallback pump_factory) { |
372 return make_scoped_ptr(new MessageLoop(type, pump_factory)); | 373 return make_scoped_ptr(new MessageLoop(type, pump_factory)); |
373 } | 374 } |
374 | 375 |
375 MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) | 376 MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) |
376 : type_(type), | 377 : type_(type), |
377 #if defined(OS_WIN) | 378 #if defined(OS_WIN) |
378 pending_high_res_tasks_(0), | 379 pending_high_res_tasks_(0), |
379 in_high_res_mode_(false), | 380 in_high_res_mode_(false), |
(...skipping 16 matching lines...) Expand all Loading... | |
396 if (!pump_factory_.is_null()) | 397 if (!pump_factory_.is_null()) |
397 pump_ = pump_factory_.Run(); | 398 pump_ = pump_factory_.Run(); |
398 else | 399 else |
399 pump_ = CreateMessagePumpForType(type_); | 400 pump_ = CreateMessagePumpForType(type_); |
400 | 401 |
401 DCHECK(!current()) << "should only have one message loop per thread"; | 402 DCHECK(!current()) << "should only have one message loop per thread"; |
402 lazy_tls_ptr.Pointer()->Set(this); | 403 lazy_tls_ptr.Pointer()->Set(this); |
403 | 404 |
404 incoming_task_queue_->StartScheduling(); | 405 incoming_task_queue_->StartScheduling(); |
405 task_runner_->BindToCurrentThread(); | 406 task_runner_->BindToCurrentThread(); |
406 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_)); | 407 SwapTaskRunner(task_runner_); |
danakj
2015/06/29 19:07:23
Why do we want to support both:
1. SwapTaskRunner
danakj
2015/06/29 19:07:23
can we DCHECK that the return from this is null?
alex clarke (OOO till 29th)
2015/06/30 10:51:43
I don't know, and Sami is currently OOO so I can't
alex clarke (OOO till 29th)
2015/06/30 10:51:43
Done.
| |
408 } | |
409 | |
410 scoped_refptr<BindableSingleThreadTaskRunner> MessageLoop::SwapTaskRunner( | |
411 scoped_refptr<BindableSingleThreadTaskRunner> task_runner) { | |
412 // If this message loop was already bound to a thread, ensure the task runner | |
413 // belongs to the same thread and update the thread task runner handle. | |
414 // Otherwise the task runner will be bound later in BindToCurrentThread(). | |
415 if (pump_) { | |
416 DCHECK_EQ(this, current()); | |
417 DCHECK(task_runner->BelongsToCurrentThread()); | |
418 // This reset() is needed or ThreadTaskRunnerHandle::Get() will crash. | |
danakj
2015/06/29 19:07:23
We're not calling Get() here.. can you expand the
alex clarke (OOO till 29th)
2015/06/30 10:51:43
It's there because in the original review kinuko a
| |
419 thread_task_runner_handle_.reset(); | |
420 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner)); | |
421 } | |
422 task_runner_.swap(task_runner); | |
423 return task_runner; | |
407 } | 424 } |
408 | 425 |
409 void MessageLoop::RunHandler() { | 426 void MessageLoop::RunHandler() { |
410 DCHECK_EQ(this, current()); | 427 DCHECK_EQ(this, current()); |
411 | 428 |
412 StartHistogrammer(); | 429 StartHistogrammer(); |
413 | 430 |
414 #if defined(OS_WIN) | 431 #if defined(OS_WIN) |
415 if (run_loop_->dispatcher_ && type() == TYPE_UI) { | 432 if (run_loop_->dispatcher_ && type() == TYPE_UI) { |
416 static_cast<MessagePumpForUI*>(pump_.get())-> | 433 static_cast<MessagePumpForUI*>(pump_.get())-> |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 persistent, | 744 persistent, |
728 mode, | 745 mode, |
729 controller, | 746 controller, |
730 delegate); | 747 delegate); |
731 } | 748 } |
732 #endif | 749 #endif |
733 | 750 |
734 #endif // !defined(OS_NACL_SFI) | 751 #endif // !defined(OS_NACL_SFI) |
735 | 752 |
736 } // namespace base | 753 } // namespace base |
OLD | NEW |