| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 MessageLoop::current()->QuitWhenIdle(); | 418 MessageLoop::current()->QuitWhenIdle(); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 | 421 |
| 422 #if defined(OS_WIN) | 422 #if defined(OS_WIN) |
| 423 | 423 |
| 424 class DispatcherImpl : public MessagePumpDispatcher { | 424 class DispatcherImpl : public MessagePumpDispatcher { |
| 425 public: | 425 public: |
| 426 DispatcherImpl() : dispatch_count_(0) {} | 426 DispatcherImpl() : dispatch_count_(0) {} |
| 427 | 427 |
| 428 virtual uint32_t Dispatch(const NativeEvent& msg) OVERRIDE { | 428 virtual uint32_t Dispatch(const NativeEvent& msg) override { |
| 429 ::TranslateMessage(&msg); | 429 ::TranslateMessage(&msg); |
| 430 ::DispatchMessage(&msg); | 430 ::DispatchMessage(&msg); |
| 431 // Do not count WM_TIMER since it is not what we post and it will cause | 431 // Do not count WM_TIMER since it is not what we post and it will cause |
| 432 // flakiness. | 432 // flakiness. |
| 433 if (msg.message != WM_TIMER) | 433 if (msg.message != WM_TIMER) |
| 434 ++dispatch_count_; | 434 ++dispatch_count_; |
| 435 // We treat WM_LBUTTONUP as the last message. | 435 // We treat WM_LBUTTONUP as the last message. |
| 436 return msg.message == WM_LBUTTONUP ? POST_DISPATCH_QUIT_LOOP | 436 return msg.message == WM_LBUTTONUP ? POST_DISPATCH_QUIT_LOOP |
| 437 : POST_DISPATCH_NONE; | 437 : POST_DISPATCH_NONE; |
| 438 } | 438 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 659 |
| 660 class DummyTaskObserver : public MessageLoop::TaskObserver { | 660 class DummyTaskObserver : public MessageLoop::TaskObserver { |
| 661 public: | 661 public: |
| 662 explicit DummyTaskObserver(int num_tasks) | 662 explicit DummyTaskObserver(int num_tasks) |
| 663 : num_tasks_started_(0), | 663 : num_tasks_started_(0), |
| 664 num_tasks_processed_(0), | 664 num_tasks_processed_(0), |
| 665 num_tasks_(num_tasks) {} | 665 num_tasks_(num_tasks) {} |
| 666 | 666 |
| 667 virtual ~DummyTaskObserver() {} | 667 virtual ~DummyTaskObserver() {} |
| 668 | 668 |
| 669 virtual void WillProcessTask(const PendingTask& pending_task) OVERRIDE { | 669 virtual void WillProcessTask(const PendingTask& pending_task) override { |
| 670 num_tasks_started_++; | 670 num_tasks_started_++; |
| 671 EXPECT_TRUE(pending_task.time_posted != TimeTicks()); | 671 EXPECT_TRUE(pending_task.time_posted != TimeTicks()); |
| 672 EXPECT_LE(num_tasks_started_, num_tasks_); | 672 EXPECT_LE(num_tasks_started_, num_tasks_); |
| 673 EXPECT_EQ(num_tasks_started_, num_tasks_processed_ + 1); | 673 EXPECT_EQ(num_tasks_started_, num_tasks_processed_ + 1); |
| 674 } | 674 } |
| 675 | 675 |
| 676 virtual void DidProcessTask(const PendingTask& pending_task) OVERRIDE { | 676 virtual void DidProcessTask(const PendingTask& pending_task) override { |
| 677 num_tasks_processed_++; | 677 num_tasks_processed_++; |
| 678 EXPECT_TRUE(pending_task.time_posted != TimeTicks()); | 678 EXPECT_TRUE(pending_task.time_posted != TimeTicks()); |
| 679 EXPECT_LE(num_tasks_started_, num_tasks_); | 679 EXPECT_LE(num_tasks_started_, num_tasks_); |
| 680 EXPECT_EQ(num_tasks_started_, num_tasks_processed_); | 680 EXPECT_EQ(num_tasks_started_, num_tasks_processed_); |
| 681 } | 681 } |
| 682 | 682 |
| 683 int num_tasks_started() const { return num_tasks_started_; } | 683 int num_tasks_started() const { return num_tasks_started_; } |
| 684 int num_tasks_processed() const { return num_tasks_processed_; } | 684 int num_tasks_processed() const { return num_tasks_processed_; } |
| 685 | 685 |
| 686 private: | 686 private: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 } | 749 } |
| 750 | 750 |
| 751 #endif // defined(OS_WIN) | 751 #endif // defined(OS_WIN) |
| 752 | 752 |
| 753 #if defined(OS_POSIX) && !defined(OS_NACL) | 753 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 754 | 754 |
| 755 namespace { | 755 namespace { |
| 756 | 756 |
| 757 class QuitDelegate : public MessageLoopForIO::Watcher { | 757 class QuitDelegate : public MessageLoopForIO::Watcher { |
| 758 public: | 758 public: |
| 759 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { | 759 virtual void OnFileCanWriteWithoutBlocking(int fd) override { |
| 760 MessageLoop::current()->QuitWhenIdle(); | 760 MessageLoop::current()->QuitWhenIdle(); |
| 761 } | 761 } |
| 762 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { | 762 virtual void OnFileCanReadWithoutBlocking(int fd) override { |
| 763 MessageLoop::current()->QuitWhenIdle(); | 763 MessageLoop::current()->QuitWhenIdle(); |
| 764 } | 764 } |
| 765 }; | 765 }; |
| 766 | 766 |
| 767 TEST(MessageLoopTest, FileDescriptorWatcherOutlivesMessageLoop) { | 767 TEST(MessageLoopTest, FileDescriptorWatcherOutlivesMessageLoop) { |
| 768 // Simulate a MessageLoop that dies before an FileDescriptorWatcher. | 768 // Simulate a MessageLoop that dies before an FileDescriptorWatcher. |
| 769 // This could happen when people use the Singleton pattern or atexit. | 769 // This could happen when people use the Singleton pattern or atexit. |
| 770 | 770 |
| 771 // Create a file descriptor. Doesn't need to be readable or writable, | 771 // Create a file descriptor. Doesn't need to be readable or writable, |
| 772 // as we don't need to actually get any notifications. | 772 // as we don't need to actually get any notifications. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 bool* destruction_observer_called_; | 850 bool* destruction_observer_called_; |
| 851 }; | 851 }; |
| 852 | 852 |
| 853 class MLDestructionObserver : public MessageLoop::DestructionObserver { | 853 class MLDestructionObserver : public MessageLoop::DestructionObserver { |
| 854 public: | 854 public: |
| 855 MLDestructionObserver(bool* task_destroyed, bool* destruction_observer_called) | 855 MLDestructionObserver(bool* task_destroyed, bool* destruction_observer_called) |
| 856 : task_destroyed_(task_destroyed), | 856 : task_destroyed_(task_destroyed), |
| 857 destruction_observer_called_(destruction_observer_called), | 857 destruction_observer_called_(destruction_observer_called), |
| 858 task_destroyed_before_message_loop_(false) { | 858 task_destroyed_before_message_loop_(false) { |
| 859 } | 859 } |
| 860 virtual void WillDestroyCurrentMessageLoop() OVERRIDE { | 860 virtual void WillDestroyCurrentMessageLoop() override { |
| 861 task_destroyed_before_message_loop_ = *task_destroyed_; | 861 task_destroyed_before_message_loop_ = *task_destroyed_; |
| 862 *destruction_observer_called_ = true; | 862 *destruction_observer_called_ = true; |
| 863 } | 863 } |
| 864 bool task_destroyed_before_message_loop() const { | 864 bool task_destroyed_before_message_loop() const { |
| 865 return task_destroyed_before_message_loop_; | 865 return task_destroyed_before_message_loop_; |
| 866 } | 866 } |
| 867 private: | 867 private: |
| 868 bool* task_destroyed_; | 868 bool* task_destroyed_; |
| 869 bool* destruction_observer_called_; | 869 bool* destruction_observer_called_; |
| 870 bool task_destroyed_before_message_loop_; | 870 bool task_destroyed_before_message_loop_; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 | 1007 |
| 1008 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); | 1008 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); |
| 1009 | 1009 |
| 1010 loop.Run(); | 1010 loop.Run(); |
| 1011 | 1011 |
| 1012 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); | 1012 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); |
| 1013 } | 1013 } |
| 1014 #endif // defined(OS_WIN) | 1014 #endif // defined(OS_WIN) |
| 1015 | 1015 |
| 1016 } // namespace base | 1016 } // namespace base |
| OLD | NEW |