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