| 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 // This function is only valid when this message loop is running and |
| 296 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; | 296 // BindToCurrentThread has already been called. |
| 297 thread_name_ = thread_name; | 297 std::string GetThreadName() const; |
| 298 } | |
| 299 const std::string& thread_name() const { return thread_name_; } | |
| 300 | 298 |
| 301 // Gets the TaskRunner associated with this message loop. | 299 // Gets the TaskRunner associated with this message loop. |
| 302 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { | 300 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { |
| 303 return task_runner_; | 301 return task_runner_; |
| 304 } | 302 } |
| 305 | 303 |
| 306 // Sets a new TaskRunner for this message loop. The message loop must already | 304 // 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 | 305 // 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 | 306 // 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 | 307 // 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_; | 508 ObserverList<NestingObserver> nesting_observers_; |
| 511 | 509 |
| 512 // A recursion block that prevents accidentally running additional tasks when | 510 // A recursion block that prevents accidentally running additional tasks when |
| 513 // insider a (accidentally induced?) nested message pump. | 511 // insider a (accidentally induced?) nested message pump. |
| 514 bool nestable_tasks_allowed_; | 512 bool nestable_tasks_allowed_; |
| 515 | 513 |
| 516 // pump_factory_.Run() is called to create a message pump for this loop | 514 // pump_factory_.Run() is called to create a message pump for this loop |
| 517 // if type_ is TYPE_CUSTOM and pump_ is null. | 515 // if type_ is TYPE_CUSTOM and pump_ is null. |
| 518 MessagePumpFactoryCallback pump_factory_; | 516 MessagePumpFactoryCallback pump_factory_; |
| 519 | 517 |
| 520 std::string thread_name_; | |
| 521 // A profiling histogram showing the counts of various messages and events. | 518 // A profiling histogram showing the counts of various messages and events. |
| 522 HistogramBase* message_histogram_; | 519 HistogramBase* message_histogram_; |
| 523 | 520 |
| 524 RunLoop* run_loop_; | 521 RunLoop* run_loop_; |
| 525 | 522 |
| 526 ObserverList<TaskObserver> task_observers_; | 523 ObserverList<TaskObserver> task_observers_; |
| 527 | 524 |
| 528 debug::TaskAnnotator task_annotator_; | 525 debug::TaskAnnotator task_annotator_; |
| 529 | 526 |
| 530 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 527 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
| 531 | 528 |
| 532 // A task runner which we haven't bound to a thread yet. | 529 // A task runner which we haven't bound to a thread yet. |
| 533 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 530 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
| 534 | 531 |
| 535 // The task runner associated with this message loop. | 532 // The task runner associated with this message loop. |
| 536 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 533 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| 537 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 534 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
| 538 | 535 |
| 536 // Id of the thread this message loop is bound to. |
| 537 PlatformThreadId thread_id_; |
| 538 |
| 539 template <class T, class R> friend class base::subtle::DeleteHelperInternal; | 539 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
| 540 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; | 540 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
| 541 | 541 |
| 542 void DeleteSoonInternal(const tracked_objects::Location& from_here, | 542 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
| 543 void(*deleter)(const void*), | 543 void(*deleter)(const void*), |
| 544 const void* object); | 544 const void* object); |
| 545 void ReleaseSoonInternal(const tracked_objects::Location& from_here, | 545 void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
| 546 void(*releaser)(const void*), | 546 void(*releaser)(const void*), |
| 547 const void* object); | 547 const void* object); |
| 548 | 548 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 | 681 |
| 682 // Do not add any member variables to MessageLoopForIO! This is important b/c | 682 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 683 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 683 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 684 // data that you need should be stored on the MessageLoop's pump_ instance. | 684 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 685 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 685 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 686 "MessageLoopForIO should not have extra member variables"); | 686 "MessageLoopForIO should not have extra member variables"); |
| 687 | 687 |
| 688 } // namespace base | 688 } // namespace base |
| 689 | 689 |
| 690 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 690 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |