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