brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 6 | #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 7 | |
| 8 | #include <queue> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/base_export.h" |
| 12 | #include "base/basictypes.h" |
| 13 | #include "base/callback_forward.h" |
skyostil@chromium.org | 2ca1bf3 | 2014-08-14 23:26:09 +0900 | [diff] [blame] | 14 | #include "base/debug/task_annotator.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 15 | #include "base/location.h" |
| 16 | #include "base/memory/ref_counted.h" |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 17 | #include "base/memory/scoped_ptr.h" |
| 18 | #include "base/message_loop/incoming_task_queue.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 19 | #include "base/message_loop/message_loop_proxy.h" |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 20 | #include "base/message_loop/message_loop_proxy_impl.h" |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 21 | #include "base/message_loop/message_pump.h" |
jeremy@chromium.org | 4d5a6b2 | 2014-06-06 04:36:20 +0900 | [diff] [blame] | 22 | #include "base/message_loop/timer_slack.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 23 | #include "base/observer_list.h" |
| 24 | #include "base/pending_task.h" |
| 25 | #include "base/sequenced_task_runner_helpers.h" |
| 26 | #include "base/synchronization/lock.h" |
avi@chromium.org | b039e8b | 2013-06-28 09:49:07 +0900 | [diff] [blame] | 27 | #include "base/time/time.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 28 | #include "base/tracking_info.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 29 | |
sky@chromium.org | 66a00b3 | 2014-01-17 09:10:29 +0900 | [diff] [blame] | 30 | // TODO(sky): these includes should not be necessary. Nuke them. |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 31 | #if defined(OS_WIN) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 32 | #include "base/message_loop/message_pump_win.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 33 | #elif defined(OS_IOS) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 34 | #include "base/message_loop/message_pump_io_ios.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 35 | #elif defined(OS_POSIX) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 36 | #include "base/message_loop/message_pump_libevent.h" |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | namespace base { |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 40 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 41 | class HistogramBase; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 42 | class RunLoop; |
| 43 | class ThreadTaskRunnerHandle; |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 44 | class WaitableEvent; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 45 | |
| 46 | // A MessageLoop is used to process events for a particular thread. There is |
| 47 | // at most one MessageLoop instance per thread. |
| 48 | // |
| 49 | // Events include at a minimum Task instances submitted to PostTask and its |
| 50 | // variants. Depending on the type of message pump used by the MessageLoop |
| 51 | // other events such as UI messages may be processed. On Windows APC calls (as |
| 52 | // time permits) and signals sent to a registered set of HANDLEs may also be |
| 53 | // processed. |
| 54 | // |
| 55 | // NOTE: Unless otherwise specified, a MessageLoop's methods may only be called |
| 56 | // on the thread where the MessageLoop's Run method executes. |
| 57 | // |
| 58 | // NOTE: MessageLoop has task reentrancy protection. This means that if a |
| 59 | // task is being processed, a second task cannot start until the first task is |
| 60 | // finished. Reentrancy can happen when processing a task, and an inner |
| 61 | // message pump is created. That inner pump then processes native messages |
| 62 | // which could implicitly start an inner task. Inner message pumps are created |
| 63 | // with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions |
| 64 | // (DoDragDrop), printer functions (StartDoc) and *many* others. |
| 65 | // |
| 66 | // Sample workaround when inner task processing is needed: |
| 67 | // HRESULT hr; |
| 68 | // { |
| 69 | // MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 70 | // hr = DoDragDrop(...); // Implicitly runs a modal message loop. |
| 71 | // } |
| 72 | // // Process |hr| (the result returned by DoDragDrop()). |
| 73 | // |
| 74 | // Please be SURE your task is reentrant (nestable) and all global variables |
| 75 | // are stable and accessible before calling SetNestableTasksAllowed(true). |
| 76 | // |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 77 | class BASE_EXPORT MessageLoop : public MessagePump::Delegate { |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 78 | public: |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 79 | // A MessageLoop has a particular type, which indicates the set of |
| 80 | // asynchronous events it may process in addition to tasks and timers. |
| 81 | // |
| 82 | // TYPE_DEFAULT |
| 83 | // This type of ML only supports tasks and timers. |
| 84 | // |
| 85 | // TYPE_UI |
| 86 | // This type of ML also supports native UI events (e.g., Windows messages). |
| 87 | // See also MessageLoopForUI. |
| 88 | // |
| 89 | // TYPE_IO |
| 90 | // This type of ML also supports asynchronous IO. See also |
| 91 | // MessageLoopForIO. |
| 92 | // |
kristianm@chromium.org | a78bfa9 | 2013-08-08 10:31:52 +0900 | [diff] [blame] | 93 | // TYPE_JAVA |
| 94 | // This type of ML is backed by a Java message handler which is responsible |
| 95 | // for running the tasks added to the ML. This is only for use on Android. |
| 96 | // TYPE_JAVA behaves in essence like TYPE_UI, except during construction |
| 97 | // where it does not use the main thread specific pump factory. |
| 98 | // |
sky@chromium.org | ab45280 | 2013-11-08 15:16:53 +0900 | [diff] [blame] | 99 | // TYPE_CUSTOM |
| 100 | // MessagePump was supplied to constructor. |
| 101 | // |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 102 | enum Type { |
| 103 | TYPE_DEFAULT, |
| 104 | TYPE_UI, |
sky@chromium.org | ab45280 | 2013-11-08 15:16:53 +0900 | [diff] [blame] | 105 | TYPE_CUSTOM, |
kristianm@chromium.org | a78bfa9 | 2013-08-08 10:31:52 +0900 | [diff] [blame] | 106 | TYPE_IO, |
| 107 | #if defined(OS_ANDROID) |
| 108 | TYPE_JAVA, |
| 109 | #endif // defined(OS_ANDROID) |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | // Normally, it is not necessary to instantiate a MessageLoop. Instead, it |
| 113 | // is typical to make use of the current thread's MessageLoop instance. |
| 114 | explicit MessageLoop(Type type = TYPE_DEFAULT); |
sky@chromium.org | ab45280 | 2013-11-08 15:16:53 +0900 | [diff] [blame] | 115 | // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must |
| 116 | // be non-NULL. |
| 117 | explicit MessageLoop(scoped_ptr<base::MessagePump> pump); |
dcheng | 7dc8df5 | 2014-10-21 19:54:51 +0900 | [diff] [blame] | 118 | ~MessageLoop() override; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 119 | |
| 120 | // Returns the MessageLoop object for the current thread, or null if none. |
| 121 | static MessageLoop* current(); |
| 122 | |
| 123 | static void EnableHistogrammer(bool enable_histogrammer); |
| 124 | |
suyash.s@samsung.com | b5f1fc9 | 2014-03-08 02:03:54 +0900 | [diff] [blame] | 125 | typedef scoped_ptr<MessagePump> (MessagePumpFactory)(); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 126 | // Uses the given base::MessagePumpForUIFactory to override the default |
| 127 | // MessagePump implementation for 'TYPE_UI'. Returns true if the factory |
| 128 | // was successfully registered. |
| 129 | static bool InitMessagePumpForUIFactory(MessagePumpFactory* factory); |
| 130 | |
sky@chromium.org | 4f42682 | 2013-11-13 01:35:02 +0900 | [diff] [blame] | 131 | // Creates the default MessagePump based on |type|. Caller owns return |
| 132 | // value. |
suyash.s@samsung.com | b5f1fc9 | 2014-03-08 02:03:54 +0900 | [diff] [blame] | 133 | static scoped_ptr<MessagePump> CreateMessagePumpForType(Type type); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 134 | // A DestructionObserver is notified when the current MessageLoop is being |
| 135 | // destroyed. These observers are notified prior to MessageLoop::current() |
| 136 | // being changed to return NULL. This gives interested parties the chance to |
| 137 | // do final cleanup that depends on the MessageLoop. |
| 138 | // |
| 139 | // NOTE: Any tasks posted to the MessageLoop during this notification will |
| 140 | // not be run. Instead, they will be deleted. |
| 141 | // |
| 142 | class BASE_EXPORT DestructionObserver { |
| 143 | public: |
| 144 | virtual void WillDestroyCurrentMessageLoop() = 0; |
| 145 | |
| 146 | protected: |
| 147 | virtual ~DestructionObserver(); |
| 148 | }; |
| 149 | |
| 150 | // Add a DestructionObserver, which will start receiving notifications |
| 151 | // immediately. |
| 152 | void AddDestructionObserver(DestructionObserver* destruction_observer); |
| 153 | |
| 154 | // Remove a DestructionObserver. It is safe to call this method while a |
| 155 | // DestructionObserver is receiving a notification callback. |
| 156 | void RemoveDestructionObserver(DestructionObserver* destruction_observer); |
| 157 | |
| 158 | // The "PostTask" family of methods call the task's Run method asynchronously |
| 159 | // from within a message loop at some point in the future. |
| 160 | // |
| 161 | // With the PostTask variant, tasks are invoked in FIFO order, inter-mixed |
| 162 | // with normal UI or IO event processing. With the PostDelayedTask variant, |
| 163 | // tasks are called after at least approximately 'delay_ms' have elapsed. |
| 164 | // |
| 165 | // The NonNestable variants work similarly except that they promise never to |
| 166 | // dispatch the task from a nested invocation of MessageLoop::Run. Instead, |
| 167 | // such tasks get deferred until the top-most MessageLoop::Run is executing. |
| 168 | // |
| 169 | // The MessageLoop takes ownership of the Task, and deletes it after it has |
| 170 | // been Run(). |
| 171 | // |
| 172 | // PostTask(from_here, task) is equivalent to |
| 173 | // PostDelayedTask(from_here, task, 0). |
| 174 | // |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 175 | // NOTE: These methods may be called on any thread. The Task will be invoked |
| 176 | // on the thread that executes MessageLoop::Run(). |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 177 | void PostTask(const tracked_objects::Location& from_here, |
| 178 | const Closure& task); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 179 | |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 180 | void PostDelayedTask(const tracked_objects::Location& from_here, |
| 181 | const Closure& task, |
| 182 | TimeDelta delay); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 183 | |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 184 | void PostNonNestableTask(const tracked_objects::Location& from_here, |
| 185 | const Closure& task); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 186 | |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 187 | void PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 188 | const Closure& task, |
| 189 | TimeDelta delay); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 190 | |
| 191 | // A variant on PostTask that deletes the given object. This is useful |
| 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 |
| 194 | // good). |
| 195 | // |
| 196 | // NOTE: This method may be called on any thread. The object will be deleted |
maniscalco | cba1be9 | 2014-10-03 03:35:33 +0900 | [diff] [blame] | 197 | // on the thread that executes MessageLoop::Run(). |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 198 | template <class T> |
| 199 | void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { |
| 200 | base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( |
| 201 | this, from_here, object); |
| 202 | } |
| 203 | |
| 204 | // A variant on PostTask that releases the given reference counted object |
| 205 | // (by calling its Release method). This is useful if the object needs to |
| 206 | // live until the next run of the MessageLoop, or if the object needs to be |
| 207 | // released on a particular thread. |
| 208 | // |
maniscalco@chromium.org | 26ea8ac | 2014-05-28 07:37:50 +0900 | [diff] [blame] | 209 | // A common pattern is to manually increment the object's reference count |
vkuzkokov@chromium.org | 49e37bd | 2014-05-31 03:07:17 +0900 | [diff] [blame] | 210 | // (AddRef), clear the pointer, then issue a ReleaseSoon. The reference count |
maniscalco@chromium.org | 26ea8ac | 2014-05-28 07:37:50 +0900 | [diff] [blame] | 211 | // is incremented manually to ensure clearing the pointer does not trigger a |
| 212 | // delete and to account for the upcoming decrement (ReleaseSoon). For |
| 213 | // example: |
| 214 | // |
| 215 | // scoped_refptr<Foo> foo = ... |
vkuzkokov@chromium.org | 49e37bd | 2014-05-31 03:07:17 +0900 | [diff] [blame] | 216 | // foo->AddRef(); |
| 217 | // Foo* raw_foo = foo.get(); |
maniscalco@chromium.org | 26ea8ac | 2014-05-28 07:37:50 +0900 | [diff] [blame] | 218 | // foo = NULL; |
vkuzkokov@chromium.org | 49e37bd | 2014-05-31 03:07:17 +0900 | [diff] [blame] | 219 | // message_loop->ReleaseSoon(raw_foo); |
maniscalco@chromium.org | 26ea8ac | 2014-05-28 07:37:50 +0900 | [diff] [blame] | 220 | // |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 221 | // NOTE: This method may be called on any thread. The object will be |
| 222 | // released (and thus possibly deleted) on the thread that executes |
| 223 | // MessageLoop::Run(). If this is not the same as the thread that calls |
maniscalco | cba1be9 | 2014-10-03 03:35:33 +0900 | [diff] [blame] | 224 | // ReleaseSoon(FROM_HERE, ), then T MUST inherit from |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 225 | // RefCountedThreadSafe<T>! |
| 226 | template <class T> |
| 227 | void ReleaseSoon(const tracked_objects::Location& from_here, |
| 228 | const T* object) { |
| 229 | base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( |
| 230 | this, from_here, object); |
| 231 | } |
| 232 | |
| 233 | // Deprecated: use RunLoop instead. |
| 234 | // Run the message loop. |
| 235 | void Run(); |
| 236 | |
| 237 | // Deprecated: use RunLoop instead. |
| 238 | // Process all pending tasks, windows messages, etc., but don't wait/sleep. |
| 239 | // Return as soon as all items that can be run are taken care of. |
| 240 | void RunUntilIdle(); |
| 241 | |
| 242 | // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdle(). |
| 243 | void Quit() { QuitWhenIdle(); } |
| 244 | |
| 245 | // Deprecated: use RunLoop instead. |
| 246 | // |
| 247 | // Signals the Run method to return when it becomes idle. It will continue to |
| 248 | // process pending messages and future messages as long as they are enqueued. |
| 249 | // Warning: if the MessageLoop remains busy, it may never quit. Only use this |
| 250 | // Quit method when looping procedures (such as web pages) have been shut |
| 251 | // down. |
| 252 | // |
| 253 | // This method may only be called on the same thread that called Run, and Run |
| 254 | // must still be on the call stack. |
| 255 | // |
| 256 | // Use QuitClosure variants if you need to Quit another thread's MessageLoop, |
| 257 | // but note that doing so is fairly dangerous if the target thread makes |
| 258 | // nested calls to MessageLoop::Run. The problem being that you won't know |
| 259 | // which nested run loop you are quitting, so be careful! |
| 260 | void QuitWhenIdle(); |
| 261 | |
| 262 | // Deprecated: use RunLoop instead. |
| 263 | // |
| 264 | // This method is a variant of Quit, that does not wait for pending messages |
| 265 | // to be processed before returning from Run. |
| 266 | void QuitNow(); |
| 267 | |
| 268 | // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure(). |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 269 | static Closure QuitClosure() { return QuitWhenIdleClosure(); } |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 270 | |
| 271 | // Deprecated: use RunLoop instead. |
| 272 | // Construct a Closure that will call QuitWhenIdle(). Useful to schedule an |
| 273 | // arbitrary MessageLoop to QuitWhenIdle. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 274 | static Closure QuitWhenIdleClosure(); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 275 | |
jeremy@chromium.org | 4d5a6b2 | 2014-06-06 04:36:20 +0900 | [diff] [blame] | 276 | // Set the timer slack for this message loop. |
| 277 | void SetTimerSlack(TimerSlack timer_slack) { |
| 278 | pump_->SetTimerSlack(timer_slack); |
| 279 | } |
| 280 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 281 | // Returns true if this loop is |type|. This allows subclasses (especially |
| 282 | // those in tests) to specialize how they are identified. |
| 283 | virtual bool IsType(Type type) const; |
| 284 | |
| 285 | // Returns the type passed to the constructor. |
| 286 | Type type() const { return type_; } |
| 287 | |
| 288 | // Optional call to connect the thread name with this loop. |
| 289 | void set_thread_name(const std::string& thread_name) { |
| 290 | DCHECK(thread_name_.empty()) << "Should not rename this thread!"; |
| 291 | thread_name_ = thread_name; |
| 292 | } |
| 293 | const std::string& thread_name() const { return thread_name_; } |
| 294 | |
| 295 | // Gets the message loop proxy associated with this message loop. |
rsleevi@chromium.org | c9ff378 | 2014-07-12 10:10:52 +0900 | [diff] [blame] | 296 | // |
| 297 | // NOTE: Deprecated; prefer task_runner() and the TaskRunner interfaces |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 298 | scoped_refptr<MessageLoopProxy> message_loop_proxy() { |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 299 | return message_loop_proxy_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 300 | } |
| 301 | |
rsleevi@chromium.org | c9ff378 | 2014-07-12 10:10:52 +0900 | [diff] [blame] | 302 | // Gets the TaskRunner associated with this message loop. |
| 303 | scoped_refptr<SingleThreadTaskRunner> task_runner() { |
| 304 | return message_loop_proxy_; |
| 305 | } |
| 306 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 307 | // Enables or disables the recursive task processing. This happens in the case |
| 308 | // of recursive message loops. Some unwanted message loop may occurs when |
| 309 | // using common controls or printer functions. By default, recursive task |
| 310 | // processing is disabled. |
| 311 | // |
| 312 | // Please utilize |ScopedNestableTaskAllower| instead of calling these methods |
| 313 | // directly. In general nestable message loops are to be avoided. They are |
| 314 | // dangerous and difficult to get right, so please use with extreme caution. |
| 315 | // |
| 316 | // The specific case where tasks get queued is: |
| 317 | // - The thread is running a message loop. |
| 318 | // - It receives a task #1 and execute it. |
| 319 | // - The task #1 implicitly start a message loop, like a MessageBox in the |
| 320 | // unit test. This can also be StartDoc or GetSaveFileName. |
| 321 | // - The thread receives a task #2 before or while in this second message |
| 322 | // loop. |
| 323 | // - With NestableTasksAllowed set to true, the task #2 will run right away. |
| 324 | // Otherwise, it will get executed right after task #1 completes at "thread |
| 325 | // message loop level". |
| 326 | void SetNestableTasksAllowed(bool allowed); |
| 327 | bool NestableTasksAllowed() const; |
| 328 | |
| 329 | // Enables nestable tasks on |loop| while in scope. |
| 330 | class ScopedNestableTaskAllower { |
| 331 | public: |
| 332 | explicit ScopedNestableTaskAllower(MessageLoop* loop) |
| 333 | : loop_(loop), |
| 334 | old_state_(loop_->NestableTasksAllowed()) { |
| 335 | loop_->SetNestableTasksAllowed(true); |
| 336 | } |
| 337 | ~ScopedNestableTaskAllower() { |
| 338 | loop_->SetNestableTasksAllowed(old_state_); |
| 339 | } |
| 340 | |
| 341 | private: |
| 342 | MessageLoop* loop_; |
| 343 | bool old_state_; |
| 344 | }; |
| 345 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 346 | // Returns true if we are currently running a nested message loop. |
| 347 | bool IsNested(); |
| 348 | |
| 349 | // A TaskObserver is an object that receives task notifications from the |
| 350 | // MessageLoop. |
| 351 | // |
| 352 | // NOTE: A TaskObserver implementation should be extremely fast! |
| 353 | class BASE_EXPORT TaskObserver { |
| 354 | public: |
| 355 | TaskObserver(); |
| 356 | |
| 357 | // This method is called before processing a task. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 358 | virtual void WillProcessTask(const PendingTask& pending_task) = 0; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 359 | |
| 360 | // This method is called after processing a task. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 361 | virtual void DidProcessTask(const PendingTask& pending_task) = 0; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 362 | |
| 363 | protected: |
| 364 | virtual ~TaskObserver(); |
| 365 | }; |
| 366 | |
| 367 | // These functions can only be called on the same thread that |this| is |
| 368 | // running on. |
| 369 | void AddTaskObserver(TaskObserver* task_observer); |
| 370 | void RemoveTaskObserver(TaskObserver* task_observer); |
| 371 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 372 | #if defined(OS_WIN) |
| 373 | void set_os_modal_loop(bool os_modal_loop) { |
| 374 | os_modal_loop_ = os_modal_loop; |
| 375 | } |
| 376 | |
| 377 | bool os_modal_loop() const { |
| 378 | return os_modal_loop_; |
| 379 | } |
| 380 | #endif // OS_WIN |
| 381 | |
| 382 | // Can only be called from the thread that owns the MessageLoop. |
| 383 | bool is_running() const; |
| 384 | |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 385 | // Returns true if the message loop has high resolution timers enabled. |
| 386 | // Provided for testing. |
cpu | 410a98e | 2014-08-29 08:25:37 +0900 | [diff] [blame] | 387 | bool HasHighResolutionTasks(); |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 388 | |
| 389 | // Returns true if the message loop is "idle". Provided for testing. |
| 390 | bool IsIdleForTesting(); |
| 391 | |
jamesr | 8d73106 | 2014-09-30 06:12:44 +0900 | [diff] [blame] | 392 | // Wakes up the message pump. Can be called on any thread. The caller is |
| 393 | // responsible for synchronizing ScheduleWork() calls. |
| 394 | void ScheduleWork(bool was_empty); |
| 395 | |
| 396 | // Returns the TaskAnnotator which is used to add debug information to posted |
| 397 | // tasks. |
| 398 | debug::TaskAnnotator* task_annotator() { return &task_annotator_; } |
| 399 | |
| 400 | // Runs the specified PendingTask. |
| 401 | void RunTask(const PendingTask& pending_task); |
| 402 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 403 | //---------------------------------------------------------------------------- |
| 404 | protected: |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 405 | scoped_ptr<MessagePump> pump_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 406 | |
| 407 | private: |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 408 | friend class RunLoop; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 409 | |
sky@chromium.org | ab45280 | 2013-11-08 15:16:53 +0900 | [diff] [blame] | 410 | // Configures various members for the two constructors. |
| 411 | void Init(); |
| 412 | |
cpu@chromium.org | 33353ba | 2014-01-04 06:25:26 +0900 | [diff] [blame] | 413 | // Invokes the actual run loop using the message pump. |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 414 | void RunHandler(); |
| 415 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 416 | // Called to process any delayed non-nestable tasks. |
| 417 | bool ProcessNextDelayedNonNestableTask(); |
| 418 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 419 | // Calls RunTask or queues the pending_task on the deferred task list if it |
| 420 | // cannot be run right now. Returns true if the task was run. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 421 | bool DeferOrRunPendingTask(const PendingTask& pending_task); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 422 | |
| 423 | // Adds the pending task to delayed_work_queue_. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 424 | void AddToDelayedWorkQueue(const PendingTask& pending_task); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 425 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 426 | // Delete tasks that haven't run yet without running them. Used in the |
| 427 | // destructor to make sure all the task's destructors get called. Returns |
| 428 | // true if some work was done. |
| 429 | bool DeletePendingTasks(); |
| 430 | |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 431 | // Loads tasks from the incoming queue to |work_queue_| if the latter is |
| 432 | // empty. |
| 433 | void ReloadWorkQueue(); |
| 434 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 435 | // Start recording histogram info about events and action IF it was enabled |
| 436 | // and IF the statistics recorder can accept a registration of our histogram. |
| 437 | void StartHistogrammer(); |
| 438 | |
| 439 | // Add occurrence of event to our histogram, so that we can see what is being |
| 440 | // done in a specific MessageLoop instance (i.e., specific thread). |
| 441 | // If message_histogram_ is NULL, this is a no-op. |
| 442 | void HistogramEvent(int event); |
| 443 | |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 444 | // MessagePump::Delegate methods: |
dcheng | 7dc8df5 | 2014-10-21 19:54:51 +0900 | [diff] [blame] | 445 | bool DoWork() override; |
| 446 | bool DoDelayedWork(TimeTicks* next_delayed_work_time) override; |
| 447 | bool DoIdleWork() override; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 448 | |
sky@chromium.org | ab45280 | 2013-11-08 15:16:53 +0900 | [diff] [blame] | 449 | const Type type_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 450 | |
| 451 | // A list of tasks that need to be processed by this instance. Note that |
| 452 | // this queue is only accessed (push/pop) by our current thread. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 453 | TaskQueue work_queue_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 454 | |
cpu | 410a98e | 2014-08-29 08:25:37 +0900 | [diff] [blame] | 455 | // How many high resolution tasks are in the pending task queue. This value |
| 456 | // increases by N every time we call ReloadWorkQueue() and decreases by 1 |
| 457 | // every time we call RunTask() if the task needs a high resolution timer. |
| 458 | int pending_high_res_tasks_; |
| 459 | // Tracks if we have requested high resolution timers. Its only use is to |
| 460 | // turn off the high resolution timer upon loop destruction. |
| 461 | bool in_high_res_mode_; |
| 462 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 463 | // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 464 | DelayedTaskQueue delayed_work_queue_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 465 | |
| 466 | // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 467 | TimeTicks recent_time_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 468 | |
| 469 | // A queue of non-nestable tasks that we had to defer because when it came |
| 470 | // time to execute them we were in a nested message loop. They will execute |
| 471 | // once we're out of nested message loops. |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 472 | TaskQueue deferred_non_nestable_work_queue_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 473 | |
| 474 | ObserverList<DestructionObserver> destruction_observers_; |
| 475 | |
| 476 | // A recursion block that prevents accidentally running additional tasks when |
| 477 | // insider a (accidentally induced?) nested message pump. |
| 478 | bool nestable_tasks_allowed_; |
| 479 | |
alexeypa@google.com | bb819d6 | 2013-07-23 05:06:56 +0900 | [diff] [blame] | 480 | #if defined(OS_WIN) |
alexeypa@google.com | bb819d6 | 2013-07-23 05:06:56 +0900 | [diff] [blame] | 481 | // Should be set to true before calling Windows APIs like TrackPopupMenu, etc |
| 482 | // which enter a modal message loop. |
| 483 | bool os_modal_loop_; |
| 484 | #endif |
| 485 | |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 486 | std::string thread_name_; |
| 487 | // A profiling histogram showing the counts of various messages and events. |
| 488 | HistogramBase* message_histogram_; |
| 489 | |
| 490 | RunLoop* run_loop_; |
alexeypa@google.com | bb819d6 | 2013-07-23 05:06:56 +0900 | [diff] [blame] | 491 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 492 | ObserverList<TaskObserver> task_observers_; |
| 493 | |
skyostil@chromium.org | 2ca1bf3 | 2014-08-14 23:26:09 +0900 | [diff] [blame] | 494 | debug::TaskAnnotator task_annotator_; |
| 495 | |
alexeypa@chromium.org | 4018323 | 2013-07-23 07:24:13 +0900 | [diff] [blame] | 496 | scoped_refptr<internal::IncomingTaskQueue> incoming_task_queue_; |
| 497 | |
| 498 | // The message loop proxy associated with this message loop. |
| 499 | scoped_refptr<internal::MessageLoopProxyImpl> message_loop_proxy_; |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 500 | scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 501 | |
| 502 | template <class T, class R> friend class base::subtle::DeleteHelperInternal; |
| 503 | template <class T, class R> friend class base::subtle::ReleaseHelperInternal; |
| 504 | |
| 505 | void DeleteSoonInternal(const tracked_objects::Location& from_here, |
| 506 | void(*deleter)(const void*), |
| 507 | const void* object); |
| 508 | void ReleaseSoonInternal(const tracked_objects::Location& from_here, |
| 509 | void(*releaser)(const void*), |
| 510 | const void* object); |
| 511 | |
| 512 | DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
| 513 | }; |
| 514 | |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 515 | #if !defined(OS_NACL) |
| 516 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 517 | //----------------------------------------------------------------------------- |
| 518 | // MessageLoopForUI extends MessageLoop with methods that are particular to a |
| 519 | // MessageLoop instantiated with TYPE_UI. |
| 520 | // |
| 521 | // This class is typically used like so: |
| 522 | // MessageLoopForUI::current()->...call some method... |
| 523 | // |
| 524 | class BASE_EXPORT MessageLoopForUI : public MessageLoop { |
| 525 | public: |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 526 | MessageLoopForUI() : MessageLoop(TYPE_UI) { |
| 527 | } |
| 528 | |
| 529 | // Returns the MessageLoopForUI of the current thread. |
| 530 | static MessageLoopForUI* current() { |
| 531 | MessageLoop* loop = MessageLoop::current(); |
| 532 | DCHECK(loop); |
| 533 | DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); |
| 534 | return static_cast<MessageLoopForUI*>(loop); |
| 535 | } |
| 536 | |
sky@chromium.org | 8a7aae7 | 2014-01-20 17:59:52 +0900 | [diff] [blame] | 537 | static bool IsCurrent() { |
| 538 | MessageLoop* loop = MessageLoop::current(); |
| 539 | return loop && loop->type() == MessageLoop::TYPE_UI; |
| 540 | } |
| 541 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 542 | #if defined(OS_IOS) |
| 543 | // On iOS, the main message loop cannot be Run(). Instead call Attach(), |
| 544 | // which connects this MessageLoop to the UI thread's CFRunLoop and allows |
| 545 | // PostTask() to work. |
| 546 | void Attach(); |
| 547 | #endif |
| 548 | |
| 549 | #if defined(OS_ANDROID) |
| 550 | // On Android, the UI message loop is handled by Java side. So Run() should |
| 551 | // never be called. Instead use Start(), which will forward all the native UI |
| 552 | // events to the Java message loop. |
| 553 | void Start(); |
sky@chromium.org | f0ef6b6 | 2014-01-12 08:12:06 +0900 | [diff] [blame] | 554 | #endif |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 555 | |
zhaoze.zhou@partner.samsung.com | 0137aa8 | 2014-07-17 04:12:40 +0900 | [diff] [blame] | 556 | #if defined(USE_OZONE) || (defined(USE_X11) && !defined(USE_GLIB)) |
sadrul@chromium.org | 7aff5f6 | 2014-04-11 02:19:38 +0900 | [diff] [blame] | 557 | // Please see MessagePumpLibevent for definition. |
| 558 | bool WatchFileDescriptor( |
| 559 | int fd, |
| 560 | bool persistent, |
| 561 | MessagePumpLibevent::Mode mode, |
| 562 | MessagePumpLibevent::FileDescriptorWatcher* controller, |
| 563 | MessagePumpLibevent::Watcher* delegate); |
| 564 | #endif |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | // Do not add any member variables to MessageLoopForUI! This is important b/c |
| 568 | // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra |
| 569 | // data that you need should be stored on the MessageLoop's pump_ instance. |
| 570 | COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), |
| 571 | MessageLoopForUI_should_not_have_extra_member_variables); |
| 572 | |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 573 | #endif // !defined(OS_NACL) |
| 574 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 575 | //----------------------------------------------------------------------------- |
| 576 | // MessageLoopForIO extends MessageLoop with methods that are particular to a |
| 577 | // MessageLoop instantiated with TYPE_IO. |
| 578 | // |
| 579 | // This class is typically used like so: |
| 580 | // MessageLoopForIO::current()->...call some method... |
| 581 | // |
| 582 | class BASE_EXPORT MessageLoopForIO : public MessageLoop { |
| 583 | public: |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 584 | MessageLoopForIO() : MessageLoop(TYPE_IO) { |
| 585 | } |
| 586 | |
| 587 | // Returns the MessageLoopForIO of the current thread. |
| 588 | static MessageLoopForIO* current() { |
| 589 | MessageLoop* loop = MessageLoop::current(); |
| 590 | DCHECK_EQ(MessageLoop::TYPE_IO, loop->type()); |
| 591 | return static_cast<MessageLoopForIO*>(loop); |
| 592 | } |
| 593 | |
| 594 | static bool IsCurrent() { |
| 595 | MessageLoop* loop = MessageLoop::current(); |
| 596 | return loop && loop->type() == MessageLoop::TYPE_IO; |
| 597 | } |
| 598 | |
hidehiko | 58e1907 | 2014-11-06 08:51:52 +0900 | [diff] [blame] | 599 | #if !defined(OS_NACL_SFI) |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 600 | |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 601 | #if defined(OS_WIN) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 602 | typedef MessagePumpForIO::IOHandler IOHandler; |
| 603 | typedef MessagePumpForIO::IOContext IOContext; |
| 604 | typedef MessagePumpForIO::IOObserver IOObserver; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 605 | #elif defined(OS_IOS) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 606 | typedef MessagePumpIOSForIO::Watcher Watcher; |
| 607 | typedef MessagePumpIOSForIO::FileDescriptorWatcher |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 608 | FileDescriptorWatcher; |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 609 | typedef MessagePumpIOSForIO::IOObserver IOObserver; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 610 | |
| 611 | enum Mode { |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 612 | WATCH_READ = MessagePumpIOSForIO::WATCH_READ, |
| 613 | WATCH_WRITE = MessagePumpIOSForIO::WATCH_WRITE, |
| 614 | WATCH_READ_WRITE = MessagePumpIOSForIO::WATCH_READ_WRITE |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 615 | }; |
| 616 | #elif defined(OS_POSIX) |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 617 | typedef MessagePumpLibevent::Watcher Watcher; |
| 618 | typedef MessagePumpLibevent::FileDescriptorWatcher |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 619 | FileDescriptorWatcher; |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 620 | typedef MessagePumpLibevent::IOObserver IOObserver; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 621 | |
| 622 | enum Mode { |
brettw@chromium.org | 710ecb9 | 2013-06-19 05:27:52 +0900 | [diff] [blame] | 623 | WATCH_READ = MessagePumpLibevent::WATCH_READ, |
| 624 | WATCH_WRITE = MessagePumpLibevent::WATCH_WRITE, |
| 625 | WATCH_READ_WRITE = MessagePumpLibevent::WATCH_READ_WRITE |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 626 | }; |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 627 | #endif |
| 628 | |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 629 | void AddIOObserver(IOObserver* io_observer); |
| 630 | void RemoveIOObserver(IOObserver* io_observer); |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 631 | |
| 632 | #if defined(OS_WIN) |
| 633 | // Please see MessagePumpWin for definitions of these methods. |
| 634 | void RegisterIOHandler(HANDLE file, IOHandler* handler); |
| 635 | bool RegisterJobObject(HANDLE job, IOHandler* handler); |
| 636 | bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 637 | #elif defined(OS_POSIX) |
| 638 | // Please see MessagePumpIOSForIO/MessagePumpLibevent for definition. |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 639 | bool WatchFileDescriptor(int fd, |
| 640 | bool persistent, |
| 641 | Mode mode, |
| 642 | FileDescriptorWatcher *controller, |
| 643 | Watcher *delegate); |
sadrul@chromium.org | b169e22 | 2014-04-23 09:55:07 +0900 | [diff] [blame] | 644 | #endif // defined(OS_IOS) || defined(OS_POSIX) |
hidehiko | 58e1907 | 2014-11-06 08:51:52 +0900 | [diff] [blame] | 645 | #endif // !defined(OS_NACL_SFI) |
brettw@chromium.org | 6318b39 | 2013-06-14 12:27:49 +0900 | [diff] [blame] | 646 | }; |
| 647 | |
| 648 | // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 649 | // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 650 | // data that you need should be stored on the MessageLoop's pump_ instance. |
| 651 | COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 652 | MessageLoopForIO_should_not_have_extra_member_variables); |
| 653 | |
| 654 | } // namespace base |
| 655 | |
| 656 | #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |