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> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop_helpers.h" |
17 #include "base/message_loop_proxy.h" | 18 #include "base/message_loop_proxy.h" |
18 #include "base/message_pump.h" | 19 #include "base/message_pump.h" |
19 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
20 #include "base/pending_task.h" | 21 #include "base/pending_task.h" |
21 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
22 #include "base/task.h" | 23 #include "base/task.h" |
23 #include "base/tracking_info.h" | 24 #include "base/tracking_info.h" |
24 #include "base/time.h" | 25 #include "base/time.h" |
25 | 26 |
26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
(...skipping 174 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 | 202 // 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 | 203 // example, deleting a RenderProcessHost from within an IPC callback is not |
203 // good). | 204 // good). |
204 // | 205 // |
205 // NOTE: This method may be called on any thread. The object will be deleted | 206 // 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 | 207 // 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 | 208 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit |
208 // from RefCountedThreadSafe<T>! | 209 // from RefCountedThreadSafe<T>! |
209 template <class T> | 210 template <class T> |
210 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { | 211 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { |
211 PostNonNestableTask(from_here, new DeleteTask<T>(object)); | 212 base::subtle::DeleteHelperInternal<T, void>::DeleteOnMessageLoop( |
| 213 this, from_here, object); |
212 } | 214 } |
213 | 215 |
214 // A variant on PostTask that releases the given reference counted object | 216 // 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 | 217 // (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 | 218 // live until the next run of the MessageLoop, or if the object needs to be |
217 // released on a particular thread. | 219 // released on a particular thread. |
218 // | 220 // |
219 // NOTE: This method may be called on any thread. The object will be | 221 // NOTE: This method may be called on any thread. The object will be |
220 // released (and thus possibly deleted) on the thread that executes | 222 // released (and thus possibly deleted) on the thread that executes |
221 // MessageLoop::Run(). If this is not the same as the thread that calls | 223 // 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 | 527 |
526 // The next sequence number to use for delayed tasks. | 528 // The next sequence number to use for delayed tasks. |
527 int next_sequence_num_; | 529 int next_sequence_num_; |
528 | 530 |
529 ObserverList<TaskObserver> task_observers_; | 531 ObserverList<TaskObserver> task_observers_; |
530 | 532 |
531 // The message loop proxy associated with this message loop, if one exists. | 533 // The message loop proxy associated with this message loop, if one exists. |
532 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 534 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
533 | 535 |
534 private: | 536 private: |
| 537 template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
| 538 |
| 539 void DeleteSoonInternal(const tracked_objects::Location& from_here, |
| 540 void(*deleter)(const void*), |
| 541 const void* object); |
| 542 |
535 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 543 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
536 }; | 544 }; |
537 | 545 |
538 //----------------------------------------------------------------------------- | 546 //----------------------------------------------------------------------------- |
539 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 547 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
540 // MessageLoop instantiated with TYPE_UI. | 548 // MessageLoop instantiated with TYPE_UI. |
541 // | 549 // |
542 // This class is typically used like so: | 550 // This class is typically used like so: |
543 // MessageLoopForUI::current()->...call some method... | 551 // MessageLoopForUI::current()->...call some method... |
544 // | 552 // |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 #endif // defined(OS_POSIX) | 664 #endif // defined(OS_POSIX) |
657 }; | 665 }; |
658 | 666 |
659 // Do not add any member variables to MessageLoopForIO! This is important b/c | 667 // Do not add any member variables to MessageLoopForIO! This is important b/c |
660 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 668 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
661 // data that you need should be stored on the MessageLoop's pump_ instance. | 669 // data that you need should be stored on the MessageLoop's pump_ instance. |
662 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 670 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
663 MessageLoopForIO_should_not_have_extra_member_variables); | 671 MessageLoopForIO_should_not_have_extra_member_variables); |
664 | 672 |
665 #endif // BASE_MESSAGE_LOOP_H_ | 673 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |