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 26 matching lines...) Expand all Loading... | |
37 #include "base/message_pump_x.h" | 37 #include "base/message_pump_x.h" |
38 #else | 38 #else |
39 #include "base/message_pump_gtk.h" | 39 #include "base/message_pump_gtk.h" |
40 #endif | 40 #endif |
41 | 41 |
42 #endif | 42 #endif |
43 #endif | 43 #endif |
44 | 44 |
45 namespace base { | 45 namespace base { |
46 class Histogram; | 46 class Histogram; |
47 | |
48 template <class T> | |
awong
2011/12/28 23:24:19
This needs a comment explaining why we need this.
dcheng
2011/12/28 23:34:20
Done. As discussed, made DoDelete private as well
| |
49 class DeleteHelper { | |
50 public: | |
51 static void DoDelete(const void* object) { | |
52 delete reinterpret_cast<const T*>(object); | |
53 } | |
54 }; | |
47 } | 55 } |
48 | 56 |
49 // A MessageLoop is used to process events for a particular thread. There is | 57 // A MessageLoop is used to process events for a particular thread. There is |
50 // at most one MessageLoop instance per thread. | 58 // at most one MessageLoop instance per thread. |
51 // | 59 // |
52 // Events include at a minimum Task instances submitted to PostTask or those | 60 // Events include at a minimum Task instances submitted to PostTask or those |
53 // managed by TimerManager. Depending on the type of message pump used by the | 61 // managed by TimerManager. Depending on the type of message pump used by the |
54 // MessageLoop other events such as UI messages may be processed. On Windows | 62 // MessageLoop other events such as UI messages may be processed. On Windows |
55 // APC calls (as time permits) and signals sent to a registered set of HANDLEs | 63 // APC calls (as time permits) and signals sent to a registered set of HANDLEs |
56 // may also be processed. | 64 // may also be processed. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // if the object needs to live until the next run of the MessageLoop (for | 209 // if the object needs to live until the next run of the MessageLoop (for |
202 // example, deleting a RenderProcessHost from within an IPC callback is not | 210 // example, deleting a RenderProcessHost from within an IPC callback is not |
203 // good). | 211 // good). |
204 // | 212 // |
205 // NOTE: This method may be called on any thread. The object will be deleted | 213 // NOTE: This method may be called on any thread. The object will be deleted |
206 // on the thread that executes MessageLoop::Run(). If this is not the same | 214 // on the thread that executes MessageLoop::Run(). If this is not the same |
207 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit | 215 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit |
208 // from RefCountedThreadSafe<T>! | 216 // from RefCountedThreadSafe<T>! |
209 template <class T> | 217 template <class T> |
210 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { | 218 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { |
211 PostNonNestableTask(from_here, new DeleteTask<T>(object)); | 219 DeleteSoonInternal(from_here, &base::DeleteHelper<T>::DoDelete, object); |
212 } | 220 } |
213 | 221 |
214 // A variant on PostTask that releases the given reference counted object | 222 // A variant on PostTask that releases the given reference counted object |
215 // (by calling its Release method). This is useful if the object needs to | 223 // (by calling its Release method). This is useful if the object needs to |
216 // live until the next run of the MessageLoop, or if the object needs to be | 224 // live until the next run of the MessageLoop, or if the object needs to be |
217 // released on a particular thread. | 225 // released on a particular thread. |
218 // | 226 // |
219 // NOTE: This method may be called on any thread. The object will be | 227 // NOTE: This method may be called on any thread. The object will be |
220 // released (and thus possibly deleted) on the thread that executes | 228 // released (and thus possibly deleted) on the thread that executes |
221 // MessageLoop::Run(). If this is not the same as the thread that calls | 229 // MessageLoop::Run(). If this is not the same as the thread that calls |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 | 533 |
526 // The next sequence number to use for delayed tasks. | 534 // The next sequence number to use for delayed tasks. |
527 int next_sequence_num_; | 535 int next_sequence_num_; |
528 | 536 |
529 ObserverList<TaskObserver> task_observers_; | 537 ObserverList<TaskObserver> task_observers_; |
530 | 538 |
531 // The message loop proxy associated with this message loop, if one exists. | 539 // The message loop proxy associated with this message loop, if one exists. |
532 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 540 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
533 | 541 |
534 private: | 542 private: |
543 void DeleteSoonInternal(const tracked_objects::Location& from_here, | |
544 void(*deleter)(const void*), | |
545 const void* object); | |
546 | |
535 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 547 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
536 }; | 548 }; |
537 | 549 |
538 //----------------------------------------------------------------------------- | 550 //----------------------------------------------------------------------------- |
539 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 551 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
540 // MessageLoop instantiated with TYPE_UI. | 552 // MessageLoop instantiated with TYPE_UI. |
541 // | 553 // |
542 // This class is typically used like so: | 554 // This class is typically used like so: |
543 // MessageLoopForUI::current()->...call some method... | 555 // MessageLoopForUI::current()->...call some method... |
544 // | 556 // |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 #endif // defined(OS_POSIX) | 668 #endif // defined(OS_POSIX) |
657 }; | 669 }; |
658 | 670 |
659 // Do not add any member variables to MessageLoopForIO! This is important b/c | 671 // Do not add any member variables to MessageLoopForIO! This is important b/c |
660 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 672 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
661 // data that you need should be stored on the MessageLoop's pump_ instance. | 673 // data that you need should be stored on the MessageLoop's pump_ instance. |
662 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 674 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
663 MessageLoopForIO_should_not_have_extra_member_variables); | 675 MessageLoopForIO_should_not_have_extra_member_variables); |
664 | 676 |
665 #endif // BASE_MESSAGE_LOOP_H_ | 677 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |