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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 pump_->SetTimerSlack(timer_slack); | 294 pump_->SetTimerSlack(timer_slack); |
295 } | 295 } |
296 | 296 |
297 // Returns true if this loop is |type|. This allows subclasses (especially | 297 // Returns true if this loop is |type|. This allows subclasses (especially |
298 // those in tests) to specialize how they are identified. | 298 // those in tests) to specialize how they are identified. |
299 virtual bool IsType(Type type) const; | 299 virtual bool IsType(Type type) const; |
300 | 300 |
301 // Returns the type passed to the constructor. | 301 // Returns the type passed to the constructor. |
302 Type type() const { return type_; } | 302 Type type() const { return type_; } |
303 | 303 |
304 // Returns the name of the thread this message loop is bound to. | 304 // Returns the name of the thread this message loop is bound to. This function |
305 // This function is only valid when this message loop is running and | 305 // is only valid when this message loop is running, BindToCurrentThread has |
306 // BindToCurrentThread has already been called. | 306 // already been called and has an "happens-before" relationship with this call |
| 307 // (this relationship is obtained implicitly by the MessageLoop's task posting |
| 308 // system unless calling this very early). |
307 std::string GetThreadName() const; | 309 std::string GetThreadName() const; |
308 | 310 |
309 // Gets the TaskRunner associated with this message loop. | 311 // Gets the TaskRunner associated with this message loop. |
310 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { | 312 const scoped_refptr<SingleThreadTaskRunner>& task_runner() { |
311 return task_runner_; | 313 return task_runner_; |
312 } | 314 } |
313 | 315 |
314 // Sets a new TaskRunner for this message loop. The message loop must already | 316 // Sets a new TaskRunner for this message loop. The message loop must already |
315 // have been bound to a thread prior to this call, and the task runner must | 317 // have been bound to a thread prior to this call, and the task runner must |
316 // belong to that thread. Note that changing the task runner will also affect | 318 // belong to that thread. Note that changing the task runner will also affect |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 547 |
546 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; | 548 scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
547 | 549 |
548 // A task runner which we haven't bound to a thread yet. | 550 // A task runner which we haven't bound to a thread yet. |
549 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 551 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
550 | 552 |
551 // The task runner associated with this message loop. | 553 // The task runner associated with this message loop. |
552 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 554 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
553 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 555 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
554 | 556 |
555 // Id of the thread this message loop is bound to. | 557 // Id of the thread this message loop is bound to. Initialized once when the |
| 558 // MessageLoop is bound to its thread and constant forever after. |
556 PlatformThreadId thread_id_; | 559 PlatformThreadId thread_id_; |
557 | 560 |
558 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) | 561 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
559 template <class T, class R> friend class base::subtle::DeleteHelperInternal; | 562 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
560 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; | 563 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
561 | 564 |
562 void DeleteSoonInternal(const tracked_objects::Location& from_here, | 565 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
563 void(*deleter)(const void*), | 566 void(*deleter)(const void*), |
564 const void* object); | 567 const void* object); |
565 void ReleaseSoonInternal(const tracked_objects::Location& from_here, | 568 void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 711 |
709 // Do not add any member variables to MessageLoopForIO! This is important b/c | 712 // Do not add any member variables to MessageLoopForIO! This is important b/c |
710 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 713 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
711 // data that you need should be stored on the MessageLoop's pump_ instance. | 714 // data that you need should be stored on the MessageLoop's pump_ instance. |
712 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 715 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
713 "MessageLoopForIO should not have extra member variables"); | 716 "MessageLoopForIO should not have extra member variables"); |
714 | 717 |
715 } // namespace base | 718 } // namespace base |
716 | 719 |
717 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 720 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |