| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
| 6 | 6 |
| 7 #include <limits> |
| 7 #include <math.h> | 8 #include <math.h> |
| 8 | 9 |
| 9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/process/memory.h" | 13 #include "base/process/memory.h" |
| 13 #include "base/profiler/scoped_tracker.h" | 14 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/win/wrapped_window_proc.h" | 16 #include "base/win/wrapped_window_proc.h" |
| 16 | 17 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 int MessagePumpWin::GetCurrentDelay() const { | 64 int MessagePumpWin::GetCurrentDelay() const { |
| 64 if (delayed_work_time_.is_null()) | 65 if (delayed_work_time_.is_null()) |
| 65 return -1; | 66 return -1; |
| 66 | 67 |
| 67 // Be careful here. TimeDelta has a precision of microseconds, but we want a | 68 // Be careful here. TimeDelta has a precision of microseconds, but we want a |
| 68 // value in milliseconds. If there are 5.5ms left, should the delay be 5 or | 69 // value in milliseconds. If there are 5.5ms left, should the delay be 5 or |
| 69 // 6? It should be 6 to avoid executing delayed work too early. | 70 // 6? It should be 6 to avoid executing delayed work too early. |
| 70 double timeout = | 71 double timeout = |
| 71 ceil((delayed_work_time_ - TimeTicks::Now()).InMillisecondsF()); | 72 ceil((delayed_work_time_ - TimeTicks::Now()).InMillisecondsF()); |
| 72 | 73 |
| 73 // If this value is negative, then we need to run delayed work soon. | 74 // Range check the |timeout| while converting to an integer. If the |timeout| |
| 74 int delay = static_cast<int>(timeout); | 75 // is negative, then we need to run delayed work soon. If the |timeout| is |
| 75 if (delay < 0) | 76 // "overflowingly" large, that means a delayed task was posted with a |
| 76 delay = 0; | 77 // super-long delay. |
| 77 | 78 return timeout < 0 ? 0 : |
| 78 return delay; | 79 (timeout > std::numeric_limits<int>::max() ? |
| 80 std::numeric_limits<int>::max() : static_cast<int>(timeout)); |
| 79 } | 81 } |
| 80 | 82 |
| 81 //----------------------------------------------------------------------------- | 83 //----------------------------------------------------------------------------- |
| 82 // MessagePumpForUI public: | 84 // MessagePumpForUI public: |
| 83 | 85 |
| 84 MessagePumpForUI::MessagePumpForUI() | 86 MessagePumpForUI::MessagePumpForUI() |
| 85 : atom_(0) { | 87 : atom_(0) { |
| 86 InitMessageWnd(); | 88 InitMessageWnd(); |
| 87 } | 89 } |
| 88 | 90 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 | 677 |
| 676 // static | 678 // static |
| 677 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 679 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
| 678 ULONG_PTR key, | 680 ULONG_PTR key, |
| 679 bool* has_valid_io_context) { | 681 bool* has_valid_io_context) { |
| 680 *has_valid_io_context = ((key & 1) == 0); | 682 *has_valid_io_context = ((key & 1) == 0); |
| 681 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 683 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
| 682 } | 684 } |
| 683 | 685 |
| 684 } // namespace base | 686 } // namespace base |
| OLD | NEW |