OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/timers/rtc_alarm.h" | 5 #include "components/timers/rtc_alarm.h" |
6 | 6 |
7 #include <sys/timerfd.h> | 7 #include <sys/timerfd.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 81 |
82 // Increment the event id. Used to invalidate any events that have been | 82 // Increment the event id. Used to invalidate any events that have been |
83 // queued but not yet run since the last time Reset() was called. | 83 // queued but not yet run since the last time Reset() was called. |
84 origin_event_id_++; | 84 origin_event_id_++; |
85 | 85 |
86 // Calling timerfd_settime with a zero delay actually clears the timer so if | 86 // Calling timerfd_settime with a zero delay actually clears the timer so if |
87 // the user has requested a zero delay timer, we need to handle it | 87 // the user has requested a zero delay timer, we need to handle it |
88 // differently. We queue the task here but we still go ahead and call | 88 // differently. We queue the task here but we still go ahead and call |
89 // timerfd_settime with the zero delay anyway to cancel any previous delay | 89 // timerfd_settime with the zero delay anyway to cancel any previous delay |
90 // that might have been programmed. | 90 // that might have been programmed. |
91 if (delay == base::TimeDelta()) { | 91 if (delay <= base::TimeDelta::FromMicroseconds(0)) { |
Daniel Erat
2014/12/04 23:23:16
any reason you can't use the shorter base::TimeDel
Chirantan Ekbote
2014/12/04 23:31:40
I did it mainly to make it painfully explicit and
| |
92 // The timerfd_settime documentation is vague on what happens when it is | |
93 // passed a negative delay. We can sidestep the issue by ensuring that the | |
94 // delay is 0. | |
95 delay = base::TimeDelta::FromMicroseconds(0); | |
92 origin_message_loop_->PostTask(FROM_HERE, | 96 origin_message_loop_->PostTask(FROM_HERE, |
93 base::Bind(&RtcAlarm::OnTimerFired, | 97 base::Bind(&RtcAlarm::OnTimerFired, |
94 scoped_refptr<RtcAlarm>(this), | 98 scoped_refptr<RtcAlarm>(this), |
95 origin_event_id_)); | 99 origin_event_id_)); |
96 } | 100 } |
97 | 101 |
98 // Make sure that we are running on a MessageLoopForIO. | 102 // Make sure that we are running on a MessageLoopForIO. |
99 if (!base::MessageLoopForIO::IsCurrent()) { | 103 if (!base::MessageLoopForIO::IsCurrent()) { |
100 g_io_thread.Get()->task_runner()->PostTask( | 104 g_io_thread.Get()->task_runner()->PostTask( |
101 FROM_HERE, | 105 FROM_HERE, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // this task was queued to run and now. If it was reset, then don't do | 177 // this task was queued to run and now. If it was reset, then don't do |
174 // anything. | 178 // anything. |
175 if (event_id != origin_event_id_) | 179 if (event_id != origin_event_id_) |
176 return; | 180 return; |
177 | 181 |
178 if (parent_) | 182 if (parent_) |
179 parent_->OnTimerFired(); | 183 parent_->OnTimerFired(); |
180 } | 184 } |
181 | 185 |
182 } // namespace timers | 186 } // namespace timers |
OLD | NEW |