OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 RunInternal(); | 181 RunInternal(); |
182 } | 182 } |
183 | 183 |
184 //------------------------------------------------------------------------------ | 184 //------------------------------------------------------------------------------ |
185 | 185 |
186 void MessageLoop::RunInternal() { | 186 void MessageLoop::RunInternal() { |
187 DCHECK(this == current()); | 187 DCHECK(this == current()); |
188 | 188 |
189 StartHistogrammer(); | 189 StartHistogrammer(); |
190 | 190 |
191 #if defined(OS_WIN) | 191 #if defined(OS_WIN) || defined(OS_LINUX) |
192 if (state_->dispatcher) { | 192 if (state_->dispatcher && type() == TYPE_UI) { |
193 pump_win()->RunWithDispatcher(this, state_->dispatcher); | 193 static_cast<base::MessagePumpForUI*>(pump_.get())-> |
| 194 RunWithDispatcher(this, state_->dispatcher); |
194 return; | 195 return; |
195 } | 196 } |
196 #endif | 197 #endif |
197 | 198 |
198 pump_->Run(this); | 199 pump_->Run(this); |
199 } | 200 } |
200 | 201 |
201 //------------------------------------------------------------------------------ | 202 //------------------------------------------------------------------------------ |
202 // Wrapper functions for use in above message loop framework. | 203 // Wrapper functions for use in above message loop framework. |
203 | 204 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 previous_state_ = loop_->state_; | 474 previous_state_ = loop_->state_; |
474 if (previous_state_) { | 475 if (previous_state_) { |
475 run_depth = previous_state_->run_depth + 1; | 476 run_depth = previous_state_->run_depth + 1; |
476 } else { | 477 } else { |
477 run_depth = 1; | 478 run_depth = 1; |
478 } | 479 } |
479 loop_->state_ = this; | 480 loop_->state_ = this; |
480 | 481 |
481 // Initialize the other fields: | 482 // Initialize the other fields: |
482 quit_received = false; | 483 quit_received = false; |
483 #if defined(OS_WIN) | 484 #if defined(OS_WIN) || defined(OS_LINUX) |
484 dispatcher = NULL; | 485 dispatcher = NULL; |
485 #endif | 486 #endif |
486 } | 487 } |
487 | 488 |
488 MessageLoop::AutoRunState::~AutoRunState() { | 489 MessageLoop::AutoRunState::~AutoRunState() { |
489 loop_->state_ = previous_state_; | 490 loop_->state_ = previous_state_; |
490 } | 491 } |
491 | 492 |
492 //------------------------------------------------------------------------------ | 493 //------------------------------------------------------------------------------ |
493 // MessageLoop::PendingTask | 494 // MessageLoop::PendingTask |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // A few events we handle (kindred to messages), and used to profile actions. | 564 // A few events we handle (kindred to messages), and used to profile actions. |
564 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) | 565 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) |
565 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) | 566 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) |
566 | 567 |
567 {-1, NULL} // The list must be null terminated, per API to histogram. | 568 {-1, NULL} // The list must be null terminated, per API to histogram. |
568 }; | 569 }; |
569 | 570 |
570 //------------------------------------------------------------------------------ | 571 //------------------------------------------------------------------------------ |
571 // MessageLoopForUI | 572 // MessageLoopForUI |
572 | 573 |
| 574 #if defined(OS_WIN) |
| 575 void MessageLoopForUI::WillProcessMessage(const MSG& message) { |
| 576 pump_win()->WillProcessMessage(message); |
| 577 } |
| 578 void MessageLoopForUI::DidProcessMessage(const MSG& message) { |
| 579 pump_win()->DidProcessMessage(message); |
| 580 } |
| 581 void MessageLoopForUI::PumpOutPendingPaintMessages() { |
| 582 pump_ui()->PumpOutPendingPaintMessages(); |
| 583 } |
| 584 |
| 585 #endif // defined(OS_WIN) |
| 586 |
573 #if defined(OS_LINUX) || defined(OS_WIN) | 587 #if defined(OS_LINUX) || defined(OS_WIN) |
574 | |
575 void MessageLoopForUI::AddObserver(Observer* observer) { | 588 void MessageLoopForUI::AddObserver(Observer* observer) { |
576 pump_ui()->AddObserver(observer); | 589 pump_ui()->AddObserver(observer); |
577 } | 590 } |
578 | 591 |
579 void MessageLoopForUI::RemoveObserver(Observer* observer) { | 592 void MessageLoopForUI::RemoveObserver(Observer* observer) { |
580 pump_ui()->RemoveObserver(observer); | 593 pump_ui()->RemoveObserver(observer); |
581 } | 594 } |
582 | 595 |
583 #endif | |
584 | |
585 #if defined(OS_WIN) | |
586 | |
587 void MessageLoopForUI::Run(Dispatcher* dispatcher) { | 596 void MessageLoopForUI::Run(Dispatcher* dispatcher) { |
588 AutoRunState save_state(this); | 597 AutoRunState save_state(this); |
589 state_->dispatcher = dispatcher; | 598 state_->dispatcher = dispatcher; |
590 RunHandler(); | 599 RunHandler(); |
591 } | 600 } |
592 | 601 #endif // defined(OS_LINUX) || defined(OS_WIN) |
593 void MessageLoopForUI::WillProcessMessage(const MSG& message) { | |
594 pump_win()->WillProcessMessage(message); | |
595 } | |
596 void MessageLoopForUI::DidProcessMessage(const MSG& message) { | |
597 pump_win()->DidProcessMessage(message); | |
598 } | |
599 void MessageLoopForUI::PumpOutPendingPaintMessages() { | |
600 pump_ui()->PumpOutPendingPaintMessages(); | |
601 } | |
602 | |
603 #endif // defined(OS_WIN) | |
604 | 602 |
605 //------------------------------------------------------------------------------ | 603 //------------------------------------------------------------------------------ |
606 // MessageLoopForIO | 604 // MessageLoopForIO |
607 | 605 |
608 #if defined(OS_WIN) | 606 #if defined(OS_WIN) |
609 | 607 |
610 void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) { | 608 void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) { |
611 pump_io()->RegisterIOHandler(file, handler); | 609 pump_io()->RegisterIOHandler(file, handler); |
612 } | 610 } |
613 | 611 |
(...skipping 10 matching lines...) Expand all Loading... |
624 Watcher *delegate) { | 622 Watcher *delegate) { |
625 return pump_libevent()->WatchFileDescriptor( | 623 return pump_libevent()->WatchFileDescriptor( |
626 fd, | 624 fd, |
627 persistent, | 625 persistent, |
628 static_cast<base::MessagePumpLibevent::Mode>(mode), | 626 static_cast<base::MessagePumpLibevent::Mode>(mode), |
629 controller, | 627 controller, |
630 delegate); | 628 delegate); |
631 } | 629 } |
632 | 630 |
633 #endif | 631 #endif |
OLD | NEW |