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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 void Run(); | 231 void Run(); |
232 | 232 |
233 // Process all pending tasks, windows messages, etc., but don't wait/sleep. | 233 // Process all pending tasks, windows messages, etc., but don't wait/sleep. |
234 // Return as soon as all items that can be run are taken care of. | 234 // Return as soon as all items that can be run are taken care of. |
235 void RunAllPending(); | 235 void RunAllPending(); |
236 | 236 |
237 // Signals the Run method to return after it is done processing all pending | 237 // Signals the Run method to return after it is done processing all pending |
238 // messages. This method may only be called on the same thread that called | 238 // messages. This method may only be called on the same thread that called |
239 // Run, and Run must still be on the call stack. | 239 // Run, and Run must still be on the call stack. |
240 // | 240 // |
241 // Use QuitTask or QuitClosure if you need to Quit another thread's | 241 // Use QuitClosure if you need to Quit another thread's MessageLoop, but note |
242 // MessageLoop, but note that doing so is fairly dangerous if the target | 242 // that doing so is fairly dangerous if the target thread makes nested calls |
243 // thread makes nested calls to MessageLoop::Run. The problem being that you | 243 // to MessageLoop::Run. The problem being that you won't know which nested |
244 // won't know which nested run loop you are quitting, so be careful! | 244 // run loop you are quitting, so be careful! |
245 void Quit(); | 245 void Quit(); |
246 | 246 |
247 // This method is a variant of Quit, that does not wait for pending messages | 247 // This method is a variant of Quit, that does not wait for pending messages |
248 // to be processed before returning from Run. | 248 // to be processed before returning from Run. |
249 void QuitNow(); | 249 void QuitNow(); |
250 | 250 |
251 // Invokes Quit on the current MessageLoop when run. Useful to schedule an | |
252 // arbitrary MessageLoop to Quit. | |
253 // TODO(jhawkins): Remove once task.h is removed. | |
254 class QuitTask : public Task { | |
255 public: | |
256 virtual void Run() OVERRIDE { | |
257 MessageLoop::current()->Quit(); | |
258 } | |
259 }; | |
260 | |
261 // Invokes Quit on the current MessageLoop when run. Useful to schedule an | 251 // Invokes Quit on the current MessageLoop when run. Useful to schedule an |
262 // arbitrary MessageLoop to Quit. | 252 // arbitrary MessageLoop to Quit. |
263 static base::Closure QuitClosure(); | 253 static base::Closure QuitClosure(); |
264 | 254 |
265 // Returns the type passed to the constructor. | 255 // Returns the type passed to the constructor. |
266 Type type() const { return type_; } | 256 Type type() const { return type_; } |
267 | 257 |
268 // Optional call to connect the thread name with this loop. | 258 // Optional call to connect the thread name with this loop. |
269 void set_thread_name(const std::string& thread_name) { | 259 void set_thread_name(const std::string& thread_name) { |
270 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; | 260 DCHECK(thread_name_.empty()) << "Should not rename this thread!"; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 #endif // defined(OS_POSIX) | 656 #endif // defined(OS_POSIX) |
667 }; | 657 }; |
668 | 658 |
669 // Do not add any member variables to MessageLoopForIO! This is important b/c | 659 // Do not add any member variables to MessageLoopForIO! This is important b/c |
670 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 660 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
671 // data that you need should be stored on the MessageLoop's pump_ instance. | 661 // data that you need should be stored on the MessageLoop's pump_ instance. |
672 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 662 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
673 MessageLoopForIO_should_not_have_extra_member_variables); | 663 MessageLoopForIO_should_not_have_extra_member_variables); |
674 | 664 |
675 #endif // BASE_MESSAGE_LOOP_H_ | 665 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |