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

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

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: Fix data race (see https://codereview.chromium.org/1232573002/) Created 5 years, 5 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
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 Type type() const { return type_; } 289 Type type() const { return type_; }
290 290
291 // Optional call to connect the thread name with this loop. 291 // Optional call to connect the thread name with this loop.
292 void set_thread_name(const std::string& thread_name) { 292 void set_thread_name(const std::string& thread_name) {
293 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; 293 DCHECK(thread_name_.empty()) << "Should not rename this thread!";
294 thread_name_ = thread_name; 294 thread_name_ = thread_name;
295 } 295 }
296 const std::string& thread_name() const { return thread_name_; } 296 const std::string& thread_name() const { return thread_name_; }
297 297
298 // Gets the TaskRunner associated with this message loop. 298 // Gets the TaskRunner associated with this message loop.
299 // TODO(skyostil): Change this to return a const reference to a refptr 299 const scoped_refptr<SingleThreadTaskRunner>& task_runner() {
300 // once the internal type matches what is being returned (crbug.com/465354). 300 return task_runner_;
301 scoped_refptr<SingleThreadTaskRunner> task_runner() { return task_runner_; } 301 }
302
303 // Sets a new TaskRunner for this message loop. The message loop must already
304 // have been bound to a thread prior to this call, and the task runner must
305 // belong to that thread. Note that changing the task runner will also affect
306 // the ThreadTaskRunnerHandle for the target thread. Must be called on the
307 // thread to which the message loop is bound.
308 void SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner);
302 309
303 // Enables or disables the recursive task processing. This happens in the case 310 // Enables or disables the recursive task processing. This happens in the case
304 // of recursive message loops. Some unwanted message loop may occurs when 311 // of recursive message loops. Some unwanted message loop may occurs when
305 // using common controls or printer functions. By default, recursive task 312 // using common controls or printer functions. By default, recursive task
306 // processing is disabled. 313 // processing is disabled.
307 // 314 //
308 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods 315 // Please utilize |ScopedNestableTaskAllower| instead of calling these methods
309 // directly. In general nestable message loops are to be avoided. They are 316 // directly. In general nestable message loops are to be avoided. They are
310 // dangerous and difficult to get right, so please use with extreme caution. 317 // dangerous and difficult to get right, so please use with extreme caution.
311 // 318 //
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 Type type, 426 Type type,
420 MessagePumpFactoryCallback pump_factory); 427 MessagePumpFactoryCallback pump_factory);
421 428
422 // Common private constructor. Other constructors delegate the initialization 429 // Common private constructor. Other constructors delegate the initialization
423 // to this constructor. 430 // to this constructor.
424 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory); 431 MessageLoop(Type type, MessagePumpFactoryCallback pump_factory);
425 432
426 // Configure various members and bind this message loop to the current thread. 433 // Configure various members and bind this message loop to the current thread.
427 void BindToCurrentThread(); 434 void BindToCurrentThread();
428 435
436 // Sets the ThreadTaskRunnerHandle for the current thread to point to the
437 // task runner for this message loop.
438 void SetThreadTaskRunnerHandle();
439
429 // Invokes the actual run loop using the message pump. 440 // Invokes the actual run loop using the message pump.
430 void RunHandler(); 441 void RunHandler();
431 442
432 // Called to process any delayed non-nestable tasks. 443 // Called to process any delayed non-nestable tasks.
433 bool ProcessNextDelayedNonNestableTask(); 444 bool ProcessNextDelayedNonNestableTask();
434 445
435 // Calls RunTask or queues the pending_task on the deferred task list if it 446 // Calls RunTask or queues the pending_task on the deferred task list if it
436 // cannot be run right now. Returns true if the task was run. 447 // cannot be run right now. Returns true if the task was run.
437 bool DeferOrRunPendingTask(const PendingTask& pending_task); 448 bool DeferOrRunPendingTask(const PendingTask& pending_task);
438 449
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 HistogramBase* message_histogram_; 525 HistogramBase* message_histogram_;
515 526
516 RunLoop* run_loop_; 527 RunLoop* run_loop_;
517 528
518 ObserverList<TaskObserver> task_observers_; 529 ObserverList<TaskObserver> task_observers_;
519 530
520 debug::TaskAnnotator task_annotator_; 531 debug::TaskAnnotator task_annotator_;
521 532
522 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; 533 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_;
523 534
535 // A task runner which we haven't bound to a thread yet.
536 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_;
537
524 // The task runner associated with this message loop. 538 // The task runner associated with this message loop.
525 scoped_refptr<internal::MessageLoopTaskRunner> task_runner_; 539 scoped_refptr<SingleThreadTaskRunner> task_runner_;
526 scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; 540 scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
527 541
528 template <class T, class R> friend class base::subtle::DeleteHelperInternal; 542 template <class T, class R> friend class base::subtle::DeleteHelperInternal;
529 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; 543 template <class T, class R> friend class base::subtle::ReleaseHelperInternal;
530 544
531 void DeleteSoonInternal(const tracked_objects::Location& from_here, 545 void DeleteSoonInternal(const tracked_objects::Location& from_here,
532 void(*deleter)(const void*), 546 void(*deleter)(const void*),
533 const void* object); 547 const void* object);
534 void ReleaseSoonInternal(const tracked_objects::Location& from_here, 548 void ReleaseSoonInternal(const tracked_objects::Location& from_here,
535 void(*releaser)(const void*), 549 void(*releaser)(const void*),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 687
674 // Do not add any member variables to MessageLoopForIO! This is important b/c 688 // Do not add any member variables to MessageLoopForIO! This is important b/c
675 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 689 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
676 // data that you need should be stored on the MessageLoop's pump_ instance. 690 // data that you need should be stored on the MessageLoop's pump_ instance.
677 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 691 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
678 MessageLoopForIO_should_not_have_extra_member_variables); 692 MessageLoopForIO_should_not_have_extra_member_variables);
679 693
680 } // namespace base 694 } // namespace base
681 695
682 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 696 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698