OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // exception filter that was active when Run() was called. This can happen | 227 // exception filter that was active when Run() was called. This can happen |
228 // if some third party code call SetUnhandledExceptionFilter() and never | 228 // if some third party code call SetUnhandledExceptionFilter() and never |
229 // restores the previous filter. | 229 // restores the previous filter. |
230 void set_exception_restoration(bool restore) { | 230 void set_exception_restoration(bool restore) { |
231 exception_restoration_ = restore; | 231 exception_restoration_ = restore; |
232 } | 232 } |
233 | 233 |
234 // Returns true if we are currently running a nested message loop. | 234 // Returns true if we are currently running a nested message loop. |
235 bool IsNested(); | 235 bool IsNested(); |
236 | 236 |
| 237 #if defined(OS_WIN) |
| 238 typedef base::MessagePumpWin::Dispatcher Dispatcher; |
| 239 typedef base::MessagePumpWin::Observer Observer; |
| 240 #elif defined(OS_LINUX) |
| 241 typedef base::MessagePumpForUI::Dispatcher Dispatcher; |
| 242 typedef base::MessagePumpForUI::Observer Observer; |
| 243 #endif |
| 244 |
237 //---------------------------------------------------------------------------- | 245 //---------------------------------------------------------------------------- |
238 protected: | 246 protected: |
239 struct RunState { | 247 struct RunState { |
240 // Used to count how many Run() invocations are on the stack. | 248 // Used to count how many Run() invocations are on the stack. |
241 int run_depth; | 249 int run_depth; |
242 | 250 |
243 // Used to record that Quit() was called, or that we should quit the pump | 251 // Used to record that Quit() was called, or that we should quit the pump |
244 // once it becomes idle. | 252 // once it becomes idle. |
245 bool quit_received; | 253 bool quit_received; |
246 | 254 |
247 #if defined(OS_WIN) | 255 #if defined(OS_WIN) || defined(OS_LINUX) |
248 base::MessagePumpWin::Dispatcher* dispatcher; | 256 Dispatcher* dispatcher; |
249 #endif | 257 #endif |
250 }; | 258 }; |
251 | 259 |
252 class AutoRunState : RunState { | 260 class AutoRunState : RunState { |
253 public: | 261 public: |
254 explicit AutoRunState(MessageLoop* loop); | 262 explicit AutoRunState(MessageLoop* loop); |
255 ~AutoRunState(); | 263 ~AutoRunState(); |
256 private: | 264 private: |
257 MessageLoop* loop_; | 265 MessageLoop* loop_; |
258 RunState* previous_state_; | 266 RunState* previous_state_; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 MessageLoopForUI() : MessageLoop(TYPE_UI) { | 417 MessageLoopForUI() : MessageLoop(TYPE_UI) { |
410 } | 418 } |
411 | 419 |
412 // Returns the MessageLoopForUI of the current thread. | 420 // Returns the MessageLoopForUI of the current thread. |
413 static MessageLoopForUI* current() { | 421 static MessageLoopForUI* current() { |
414 MessageLoop* loop = MessageLoop::current(); | 422 MessageLoop* loop = MessageLoop::current(); |
415 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); | 423 DCHECK_EQ(MessageLoop::TYPE_UI, loop->type()); |
416 return static_cast<MessageLoopForUI*>(loop); | 424 return static_cast<MessageLoopForUI*>(loop); |
417 } | 425 } |
418 | 426 |
419 #if defined(OS_LINUX) | |
420 typedef base::MessagePumpForUI::Observer Observer; | |
421 | |
422 // See message_pump_glib for definitions of these methods. | |
423 void AddObserver(Observer* observer); | |
424 void RemoveObserver(Observer* observer); | |
425 #endif | |
426 | |
427 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
428 typedef base::MessagePumpWin::Dispatcher Dispatcher; | |
429 typedef base::MessagePumpWin::Observer Observer; | |
430 | |
431 // Please see MessagePumpWin for definitions of these methods. | |
432 void AddObserver(Observer* observer); | |
433 void RemoveObserver(Observer* observer); | |
434 void Run(Dispatcher* dispatcher); | |
435 void WillProcessMessage(const MSG& message); | 428 void WillProcessMessage(const MSG& message); |
436 void DidProcessMessage(const MSG& message); | 429 void DidProcessMessage(const MSG& message); |
437 void PumpOutPendingPaintMessages(); | 430 void PumpOutPendingPaintMessages(); |
438 #endif | 431 #endif |
439 | 432 |
440 #if defined(OS_WIN) || defined(OS_LINUX) | 433 #if defined(OS_WIN) || defined(OS_LINUX) |
| 434 // Please see message_pump_win/message_pump_glib for definitions of these |
| 435 // methods. |
| 436 void AddObserver(Observer* observer); |
| 437 void RemoveObserver(Observer* observer); |
| 438 void Run(Dispatcher* dispatcher); |
| 439 |
441 protected: | 440 protected: |
442 // TODO(rvargas): Make this platform independent. | 441 // TODO(rvargas): Make this platform independent. |
443 base::MessagePumpForUI* pump_ui() { | 442 base::MessagePumpForUI* pump_ui() { |
444 return static_cast<base::MessagePumpForUI*>(pump_.get()); | 443 return static_cast<base::MessagePumpForUI*>(pump_.get()); |
445 } | 444 } |
446 #endif // defined(OS_WIN) | 445 #endif // defined(OS_WIN) || defined(OS_LINUX) |
447 }; | 446 }; |
448 | 447 |
449 // Do not add any member variables to MessageLoopForUI! This is important b/c | 448 // Do not add any member variables to MessageLoopForUI! This is important b/c |
450 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra | 449 // MessageLoopForUI is often allocated via MessageLoop(TYPE_UI). Any extra |
451 // data that you need should be stored on the MessageLoop's pump_ instance. | 450 // data that you need should be stored on the MessageLoop's pump_ instance. |
452 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), | 451 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForUI), |
453 MessageLoopForUI_should_not_have_extra_member_variables); | 452 MessageLoopForUI_should_not_have_extra_member_variables); |
454 | 453 |
455 //----------------------------------------------------------------------------- | 454 //----------------------------------------------------------------------------- |
456 // MessageLoopForIO extends MessageLoop with methods that are particular to a | 455 // MessageLoopForIO extends MessageLoop with methods that are particular to a |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 #endif // defined(OS_POSIX) | 504 #endif // defined(OS_POSIX) |
506 }; | 505 }; |
507 | 506 |
508 // Do not add any member variables to MessageLoopForIO! This is important b/c | 507 // Do not add any member variables to MessageLoopForIO! This is important b/c |
509 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 508 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
510 // data that you need should be stored on the MessageLoop's pump_ instance. | 509 // data that you need should be stored on the MessageLoop's pump_ instance. |
511 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 510 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
512 MessageLoopForIO_should_not_have_extra_member_variables); | 511 MessageLoopForIO_should_not_have_extra_member_variables); |
513 | 512 |
514 #endif // BASE_MESSAGE_LOOP_H_ | 513 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |