OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | |
18 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
19 #include "base/message_pump.h" | 18 #include "base/message_pump.h" |
20 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
21 #include "base/pending_task.h" | 20 #include "base/pending_task.h" |
| 21 #include "base/sequenced_task_runner_helpers.h" |
22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
23 #include "base/tracking_info.h" | 23 #include "base/tracking_info.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 // We need this to declare base::MessagePumpWin::Dispatcher, which we should | 27 // We need this to declare base::MessagePumpWin::Dispatcher, which we should |
28 // really just eliminate. | 28 // really just eliminate. |
29 #include "base/message_pump_win.h" | 29 #include "base/message_pump_win.h" |
30 #elif defined(OS_POSIX) | 30 #elif defined(OS_POSIX) |
31 #include "base/message_pump_libevent.h" | 31 #include "base/message_pump_libevent.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // if the object needs to live until the next run of the MessageLoop (for | 192 // if the object needs to live until the next run of the MessageLoop (for |
193 // example, deleting a RenderProcessHost from within an IPC callback is not | 193 // example, deleting a RenderProcessHost from within an IPC callback is not |
194 // good). | 194 // good). |
195 // | 195 // |
196 // NOTE: This method may be called on any thread. The object will be deleted | 196 // NOTE: This method may be called on any thread. The object will be deleted |
197 // on the thread that executes MessageLoop::Run(). If this is not the same | 197 // on the thread that executes MessageLoop::Run(). If this is not the same |
198 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit | 198 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit |
199 // from RefCountedThreadSafe<T>! | 199 // from RefCountedThreadSafe<T>! |
200 template <class T> | 200 template <class T> |
201 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { | 201 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { |
202 base::subtle::DeleteHelperInternal<T, void>::DeleteOnMessageLoop( | 202 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( |
203 this, from_here, object); | 203 this, from_here, object); |
204 } | 204 } |
205 | 205 |
206 // A variant on PostTask that releases the given reference counted object | 206 // A variant on PostTask that releases the given reference counted object |
207 // (by calling its Release method). This is useful if the object needs to | 207 // (by calling its Release method). This is useful if the object needs to |
208 // live until the next run of the MessageLoop, or if the object needs to be | 208 // live until the next run of the MessageLoop, or if the object needs to be |
209 // released on a particular thread. | 209 // released on a particular thread. |
210 // | 210 // |
211 // NOTE: This method may be called on any thread. The object will be | 211 // NOTE: This method may be called on any thread. The object will be |
212 // released (and thus possibly deleted) on the thread that executes | 212 // released (and thus possibly deleted) on the thread that executes |
213 // MessageLoop::Run(). If this is not the same as the thread that calls | 213 // MessageLoop::Run(). If this is not the same as the thread that calls |
214 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from | 214 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from |
215 // RefCountedThreadSafe<T>! | 215 // RefCountedThreadSafe<T>! |
216 template <class T> | 216 template <class T> |
217 void ReleaseSoon(const tracked_objects::Location& from_here, | 217 void ReleaseSoon(const tracked_objects::Location& from_here, |
218 const T* object) { | 218 const T* object) { |
219 base::subtle::ReleaseHelperInternal<T, void>::ReleaseOnMessageLoop( | 219 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( |
220 this, from_here, object); | 220 this, from_here, object); |
221 } | 221 } |
222 | 222 |
223 // Run the message loop. | 223 // Run the message loop. |
224 void Run(); | 224 void Run(); |
225 | 225 |
226 // Process all pending tasks, windows messages, etc., but don't wait/sleep. | 226 // Process all pending tasks, windows messages, etc., but don't wait/sleep. |
227 // Return as soon as all items that can be run are taken care of. | 227 // Return as soon as all items that can be run are taken care of. |
228 void RunAllPending(); | 228 void RunAllPending(); |
229 | 229 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 #endif // defined(OS_POSIX) | 664 #endif // defined(OS_POSIX) |
665 }; | 665 }; |
666 | 666 |
667 // 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 |
668 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 668 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
669 // 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. |
670 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 670 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
671 MessageLoopForIO_should_not_have_extra_member_variables); | 671 MessageLoopForIO_should_not_have_extra_member_variables); |
672 | 672 |
673 #endif // BASE_MESSAGE_LOOP_H_ | 673 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |