| 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 #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 <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 pump_->SetTimerSlack(timer_slack); | 284 pump_->SetTimerSlack(timer_slack); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // Returns true if this loop is |type|. This allows subclasses (especially | 287 // Returns true if this loop is |type|. This allows subclasses (especially |
| 288 // those in tests) to specialize how they are identified. | 288 // those in tests) to specialize how they are identified. |
| 289 virtual bool IsType(Type type) const; | 289 virtual bool IsType(Type type) const; |
| 290 | 290 |
| 291 // Returns the type passed to the constructor. | 291 // Returns the type passed to the constructor. |
| 292 Type type() const { return type_; } | 292 Type type() const { return type_; } |
| 293 | 293 |
| 294 // Optional call to connect the thread name with this loop. | 294 // Returns the name of the thread this message loop is bound to. |
| 295 void set_thread_name(const std::string& thread_name) { | 295 std::string GetThreadName() const; |
| 296 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; | |
| 297 thread_name_ = thread_name; | |
| 298 } | |
| 299 const std::string& thread_name() const { return thread_name_; } | |
| 300 | 296 |
| 301 // Gets the TaskRunner associated with this message loop. | 297 // Gets the TaskRunner associated with this message loop. |
| 302 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { | 298 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { |
| 303 return task_runner_; | 299 return task_runner_; |
| 304 } | 300 } |
| 305 | 301 |
| 306 // Sets a new TaskRunner for this message loop. The message loop must already | 302 // Sets a new TaskRunner for this message loop. The message loop must already |
| 307 // have been bound to a thread prior to this call, and the task runner must | 303 // have been bound to a thread prior to this call, and the task runner must |
| 308 // belong to that thread. Note that changing the task runner will also affect | 304 // belong to that thread. Note that changing the task runner will also affect |
| 309 // the ThreadTaskRunnerHandle for the target thread. Must be called on the | 305 // the ThreadTaskRunnerHandle for the target thread. Must be called on the |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 ObserverList<NestingObserver> nesting_observers_; | 506 ObserverList<NestingObserver> nesting_observers_; |
| 511 | 507 |
| 512 // A recursion block that prevents accidentally running additional tasks when | 508 // A recursion block that prevents accidentally running additional tasks when |
| 513 // insider a (accidentally induced?) nested message pump. | 509 // insider a (accidentally induced?) nested message pump. |
| 514 bool nestable_tasks_allowed_; | 510 bool nestable_tasks_allowed_; |
| 515 | 511 |
| 516 // pump_factory_.Run() is called to create a message pump for this loop | 512 // pump_factory_.Run() is called to create a message pump for this loop |
| 517 // if type_ is TYPE_CUSTOM and pump_ is null. | 513 // if type_ is TYPE_CUSTOM and pump_ is null. |
| 518 MessagePumpFactoryCallback pump_factory_; | 514 MessagePumpFactoryCallback pump_factory_; |
| 519 | 515 |
| 520 std::string thread_name_; | |
| 521 // A profiling histogram showing the counts of various messages and events. | 516 // A profiling histogram showing the counts of various messages and events. |
| 522 HistogramBase* message_histogram_; | 517 HistogramBase* message_histogram_; |
| 523 | 518 |
| 524 RunLoop* run_loop_; | 519 RunLoop* run_loop_; |
| 525 | 520 |
| 526 ObserverList<TaskObserver> task_observers_; | 521 ObserverList<TaskObserver> task_observers_; |
| 527 | 522 |
| 528 debug::TaskAnnotator task_annotator_; | 523 debug::TaskAnnotator task_annotator_; |
| 529 | 524 |
| 530 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 525 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
| 531 | 526 |
| 532 // A task runner which we haven't bound to a thread yet. | 527 // A task runner which we haven't bound to a thread yet. |
| 533 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 528 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
| 534 | 529 |
| 535 // The task runner associated with this message loop. | 530 // The task runner associated with this message loop. |
| 536 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 531 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| 537 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 532 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
| 538 | 533 |
| 534 // Id of the thread this message loop is bound to. |
| 535 PlatformThreadId thread_id_; |
| 536 |
| 539 template <class T, class R> friend class base::subtle::DeleteHelperInternal; | 537 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
| 540 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; | 538 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
| 541 | 539 |
| 542 void DeleteSoonInternal(const tracked_objects::Location& from_here, | 540 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
| 543 void(*deleter)(const void*), | 541 void(*deleter)(const void*), |
| 544 const void* object); | 542 const void* object); |
| 545 void ReleaseSoonInternal(const tracked_objects::Location& from_here, | 543 void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
| 546 void(*releaser)(const void*), | 544 void(*releaser)(const void*), |
| 547 const void* object); | 545 const void* object); |
| 548 | 546 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 | 679 |
| 682 // Do not add any member variables to MessageLoopForIO! This is important b/c | 680 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 683 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 681 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 684 // data that you need should be stored on the MessageLoop's pump_ instance. | 682 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 685 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 683 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 686 "MessageLoopForIO should not have extra member variables"); | 684 "MessageLoopForIO should not have extra member variables"); |
| 687 | 685 |
| 688 } // namespace base | 686 } // namespace base |
| 689 | 687 |
| 690 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 688 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |