Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: base/message_loop/message_loop.cc

Issue 998063002: base: Make it possible to replace the MessageLoop's task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No more MessageLoopProxy. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_);
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 thread_task_runner_handle_.reset();
419 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner));
kinuko 2015/06/25 05:58:08 nit: no need to call reset() twice, line 418 is no
alexclarke 2015/06/25 09:36:51 Done.
420 }
421 scoped_refptr<BindableSingleThreadTaskRunner> previous_runner = task_runner_;
kinuko 2015/06/25 05:58:08 nit: task_runner_.Pass() might be slightly better
422 task_runner_ = task_runner;
423 return previous_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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 persistent, 740 persistent,
724 mode, 741 mode,
725 controller, 742 controller,
726 delegate); 743 delegate);
727 } 744 }
728 #endif 745 #endif
729 746
730 #endif // !defined(OS_NACL_SFI) 747 #endif // !defined(OS_NACL_SFI)
731 748
732 } // namespace base 749 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698