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() ? |
darin (slow to review)
2015/01/27 07:52:39
you didn't want to use the max_int / 2 comparison
| |
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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 | 655 |
654 // static | 656 // static |
655 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 657 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
656 ULONG_PTR key, | 658 ULONG_PTR key, |
657 bool* has_valid_io_context) { | 659 bool* has_valid_io_context) { |
658 *has_valid_io_context = ((key & 1) == 0); | 660 *has_valid_io_context = ((key & 1) == 0); |
659 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 661 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
660 } | 662 } |
661 | 663 |
662 } // namespace base | 664 } // namespace base |
OLD | NEW |