OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef BASE_MESSAGE_LOOP_H_ |
6 #define BASE_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // released on a particular thread. | 239 // released on a particular thread. |
240 // | 240 // |
241 // NOTE: This method may be called on any thread. The object will be | 241 // NOTE: This method may be called on any thread. The object will be |
242 // released (and thus possibly deleted) on the thread that executes | 242 // released (and thus possibly deleted) on the thread that executes |
243 // MessageLoop::Run(). If this is not the same as the thread that calls | 243 // MessageLoop::Run(). If this is not the same as the thread that calls |
244 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from | 244 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from |
245 // RefCountedThreadSafe<T>! | 245 // RefCountedThreadSafe<T>! |
246 template <class T> | 246 template <class T> |
247 void ReleaseSoon(const tracked_objects::Location& from_here, | 247 void ReleaseSoon(const tracked_objects::Location& from_here, |
248 const T* object) { | 248 const T* object) { |
249 PostNonNestableTask(from_here, new ReleaseTask<T>(object)); | 249 base::subtle::ReleaseHelperInternal<T, void>::ReleaseOnMessageLoop( |
| 250 this, from_here, object); |
250 } | 251 } |
251 | 252 |
252 // Run the message loop. | 253 // Run the message loop. |
253 void Run(); | 254 void Run(); |
254 | 255 |
255 // 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. |
256 // 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. |
257 void RunAllPending(); | 258 void RunAllPending(); |
258 | 259 |
259 // Signals the Run method to return after it is done processing all pending | 260 // Signals the Run method to return after it is done processing all pending |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 // The next sequence number to use for delayed tasks. | 549 // The next sequence number to use for delayed tasks. |
549 int next_sequence_num_; | 550 int next_sequence_num_; |
550 | 551 |
551 ObserverList<TaskObserver> task_observers_; | 552 ObserverList<TaskObserver> task_observers_; |
552 | 553 |
553 // The message loop proxy associated with this message loop, if one exists. | 554 // The message loop proxy associated with this message loop, if one exists. |
554 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 555 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
555 | 556 |
556 private: | 557 private: |
557 template <class T, class R> friend class base::subtle::DeleteHelperInternal; | 558 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
| 559 template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
558 | 560 |
559 void DeleteSoonInternal(const tracked_objects::Location& from_here, | 561 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
560 void(*deleter)(const void*), | 562 void(*deleter)(const void*), |
561 const void* object); | 563 const void* object); |
| 564 void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
| 565 void(*releaser)(const void*), |
| 566 const void* object); |
| 567 |
562 | 568 |
563 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 569 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
564 }; | 570 }; |
565 | 571 |
566 //----------------------------------------------------------------------------- | 572 //----------------------------------------------------------------------------- |
567 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 573 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
568 // MessageLoop instantiated with TYPE_UI. | 574 // MessageLoop instantiated with TYPE_UI. |
569 // | 575 // |
570 // This class is typically used like so: | 576 // This class is typically used like so: |
571 // MessageLoopForUI::current()->...call some method... | 577 // MessageLoopForUI::current()->...call some method... |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 #endif // defined(OS_POSIX) | 690 #endif // defined(OS_POSIX) |
685 }; | 691 }; |
686 | 692 |
687 // Do not add any member variables to MessageLoopForIO! This is important b/c | 693 // Do not add any member variables to MessageLoopForIO! This is important b/c |
688 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 694 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
689 // data that you need should be stored on the MessageLoop's pump_ instance. | 695 // data that you need should be stored on the MessageLoop's pump_ instance. |
690 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 696 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
691 MessageLoopForIO_should_not_have_extra_member_variables); | 697 MessageLoopForIO_should_not_have_extra_member_variables); |
692 | 698 |
693 #endif // BASE_MESSAGE_LOOP_H_ | 699 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |