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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 public: | 164 public: |
165 virtual void OnBeginNestedMessageLoop() = 0; | 165 virtual void OnBeginNestedMessageLoop() = 0; |
166 | 166 |
167 protected: | 167 protected: |
168 virtual ~NestingObserver(); | 168 virtual ~NestingObserver(); |
169 }; | 169 }; |
170 | 170 |
171 void AddNestingObserver(NestingObserver* observer); | 171 void AddNestingObserver(NestingObserver* observer); |
172 void RemoveNestingObserver(NestingObserver* observer); | 172 void RemoveNestingObserver(NestingObserver* observer); |
173 | 173 |
| 174 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
174 // NOTE: Deprecated; prefer task_runner() and the TaskRunner interfaces. | 175 // NOTE: Deprecated; prefer task_runner() and the TaskRunner interfaces. |
175 // TODO(skyostil): Remove these functions (crbug.com/465354). | 176 // TODO(skyostil): Remove these functions (crbug.com/465354). |
176 // | 177 // |
177 // The "PostTask" family of methods call the task's Run method asynchronously | 178 // The "PostTask" family of methods call the task's Run method asynchronously |
178 // from within a message loop at some point in the future. | 179 // from within a message loop at some point in the future. |
179 // | 180 // |
180 // With the PostTask variant, tasks are invoked in FIFO order, inter-mixed | 181 // With the PostTask variant, tasks are invoked in FIFO order, inter-mixed |
181 // with normal UI or IO event processing. With the PostDelayedTask variant, | 182 // with normal UI or IO event processing. With the PostDelayedTask variant, |
182 // tasks are called after at least approximately 'delay_ms' have elapsed. | 183 // tasks are called after at least approximately 'delay_ms' have elapsed. |
183 // | 184 // |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // released (and thus possibly deleted) on the thread that executes | 235 // released (and thus possibly deleted) on the thread that executes |
235 // MessageLoop::Run(). If this is not the same as the thread that calls | 236 // MessageLoop::Run(). If this is not the same as the thread that calls |
236 // ReleaseSoon(FROM_HERE, ), then T MUST inherit from | 237 // ReleaseSoon(FROM_HERE, ), then T MUST inherit from |
237 // RefCountedThreadSafe<T>! | 238 // RefCountedThreadSafe<T>! |
238 template <class T> | 239 template <class T> |
239 void ReleaseSoon(const tracked_objects::Location& from_here, | 240 void ReleaseSoon(const tracked_objects::Location& from_here, |
240 const T* object) { | 241 const T* object) { |
241 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( | 242 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( |
242 this, from_here, object); | 243 this, from_here, object); |
243 } | 244 } |
| 245 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) |
| 246 |
| 247 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 248 protected: |
| 249 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
244 | 250 |
245 // Deprecated: use RunLoop instead. | 251 // Deprecated: use RunLoop instead. |
246 // Run the message loop. | 252 // Run the message loop. |
247 void Run(); | 253 void Run(); |
248 | 254 |
249 // Deprecated: use RunLoop instead. | 255 // Deprecated: use RunLoop instead. |
250 // Process all pending tasks, windows messages, etc., but don't wait/sleep. | 256 // Process all pending tasks, windows messages, etc., but don't wait/sleep. |
251 // Return as soon as all items that can be run are taken care of. | 257 // Return as soon as all items that can be run are taken care of. |
252 void RunUntilIdle(); | 258 void RunUntilIdle(); |
253 | 259 |
| 260 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 261 public: |
| 262 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 263 |
254 // Deprecated: use RunLoop instead. | 264 // Deprecated: use RunLoop instead. |
255 // | 265 // |
256 // Signals the Run method to return when it becomes idle. It will continue to | 266 // Signals the Run method to return when it becomes idle. It will continue to |
257 // process pending messages and future messages as long as they are enqueued. | 267 // process pending messages and future messages as long as they are enqueued. |
258 // Warning: if the MessageLoop remains busy, it may never quit. Only use this | 268 // Warning: if the MessageLoop remains busy, it may never quit. Only use this |
259 // Quit method when looping procedures (such as web pages) have been shut | 269 // Quit method when looping procedures (such as web pages) have been shut |
260 // down. | 270 // down. |
261 // | 271 // |
262 // This method may only be called on the same thread that called Run, and Run | 272 // This method may only be called on the same thread that called Run, and Run |
263 // must still be on the call stack. | 273 // must still be on the call stack. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // A task runner which we haven't bound to a thread yet. | 548 // A task runner which we haven't bound to a thread yet. |
539 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; | 549 scoped_refptr<internal::MessageLoopTaskRunner> unbound_task_runner_; |
540 | 550 |
541 // The task runner associated with this message loop. | 551 // The task runner associated with this message loop. |
542 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 552 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
543 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; | 553 std::unique_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
544 | 554 |
545 // Id of the thread this message loop is bound to. | 555 // Id of the thread this message loop is bound to. |
546 PlatformThreadId thread_id_; | 556 PlatformThreadId thread_id_; |
547 | 557 |
| 558 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
548 template <class T, class R> friend class base::subtle::DeleteHelperInternal; | 559 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
549 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; | 560 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
550 | 561 |
551 void DeleteSoonInternal(const tracked_objects::Location& from_here, | 562 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
552 void(*deleter)(const void*), | 563 void(*deleter)(const void*), |
553 const void* object); | 564 const void* object); |
554 void ReleaseSoonInternal(const tracked_objects::Location& from_here, | 565 void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
555 void(*releaser)(const void*), | 566 void(*releaser)(const void*), |
556 const void* object); | 567 const void* object); |
| 568 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) |
557 | 569 |
558 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 570 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
559 }; | 571 }; |
560 | 572 |
561 #if !defined(OS_NACL) | 573 #if !defined(OS_NACL) |
562 | 574 |
563 //----------------------------------------------------------------------------- | 575 //----------------------------------------------------------------------------- |
564 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 576 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
565 // MessageLoop instantiated with TYPE_UI. | 577 // MessageLoop instantiated with TYPE_UI. |
566 // | 578 // |
567 // This class is typically used like so: | 579 // This class is typically used like so: |
568 // MessageLoopForUI::current()->...call some method... | 580 // MessageLoopForUI::current()->...call some method... |
569 // | 581 // |
570 class BASE_EXPORT MessageLoopForUI : public MessageLoop { | 582 class BASE_EXPORT MessageLoopForUI : public MessageLoop { |
571 public: | 583 public: |
| 584 using MessageLoop::Run; |
| 585 using MessageLoop::RunUntilIdle; |
| 586 |
572 MessageLoopForUI() : MessageLoop(TYPE_UI) { | 587 MessageLoopForUI() : MessageLoop(TYPE_UI) { |
573 } | 588 } |
574 | 589 |
575 explicit MessageLoopForUI(std::unique_ptr<MessagePump> pump); | 590 explicit MessageLoopForUI(std::unique_ptr<MessagePump> pump); |
576 | 591 |
577 // Returns the MessageLoopForUI of the current thread. | 592 // Returns the MessageLoopForUI of the current thread. |
578 static MessageLoopForUI* current() { | 593 static MessageLoopForUI* current() { |
579 MessageLoop* loop = MessageLoop::current(); | 594 MessageLoop* loop = MessageLoop::current(); |
580 DCHECK(loop); | 595 DCHECK(loop); |
581 DCHECK(loop->IsType(MessageLoop::TYPE_UI)); | 596 DCHECK(loop->IsType(MessageLoop::TYPE_UI)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 637 |
623 //----------------------------------------------------------------------------- | 638 //----------------------------------------------------------------------------- |
624 // MessageLoopForIO extends MessageLoop with methods that are particular to a | 639 // MessageLoopForIO extends MessageLoop with methods that are particular to a |
625 // MessageLoop instantiated with TYPE_IO. | 640 // MessageLoop instantiated with TYPE_IO. |
626 // | 641 // |
627 // This class is typically used like so: | 642 // This class is typically used like so: |
628 // MessageLoopForIO::current()->...call some method... | 643 // MessageLoopForIO::current()->...call some method... |
629 // | 644 // |
630 class BASE_EXPORT MessageLoopForIO : public MessageLoop { | 645 class BASE_EXPORT MessageLoopForIO : public MessageLoop { |
631 public: | 646 public: |
| 647 using MessageLoop::Run; |
| 648 using MessageLoop::RunUntilIdle; |
| 649 |
632 MessageLoopForIO() : MessageLoop(TYPE_IO) { | 650 MessageLoopForIO() : MessageLoop(TYPE_IO) { |
633 } | 651 } |
634 | 652 |
635 // Returns the MessageLoopForIO of the current thread. | 653 // Returns the MessageLoopForIO of the current thread. |
636 static MessageLoopForIO* current() { | 654 static MessageLoopForIO* current() { |
637 MessageLoop* loop = MessageLoop::current(); | 655 MessageLoop* loop = MessageLoop::current(); |
638 DCHECK(loop); | 656 DCHECK(loop); |
639 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); | 657 DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); |
640 return static_cast<MessageLoopForIO*>(loop); | 658 return static_cast<MessageLoopForIO*>(loop); |
641 } | 659 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 708 |
691 // Do not add any member variables to MessageLoopForIO! This is important b/c | 709 // Do not add any member variables to MessageLoopForIO! This is important b/c |
692 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 710 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
693 // data that you need should be stored on the MessageLoop's pump_ instance. | 711 // data that you need should be stored on the MessageLoop's pump_ instance. |
694 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 712 static_assert(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
695 "MessageLoopForIO should not have extra member variables"); | 713 "MessageLoopForIO should not have extra member variables"); |
696 | 714 |
697 } // namespace base | 715 } // namespace base |
698 | 716 |
699 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 717 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |