Chromium Code Reviews| 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 "chrome/browser/extensions/api/alarms/alarm_manager.h" | 5 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 for (AlarmMap::const_iterator m_it = alarms_.begin(), m_end = alarms_.end(); | 321 for (AlarmMap::const_iterator m_it = alarms_.begin(), m_end = alarms_.end(); |
| 322 m_it != m_end; ++m_it) { | 322 m_it != m_end; ++m_it) { |
| 323 for (AlarmList::const_iterator l_it = m_it->second.begin(); | 323 for (AlarmList::const_iterator l_it = m_it->second.begin(); |
| 324 l_it != m_it->second.end(); ++l_it) { | 324 l_it != m_it->second.end(); ++l_it) { |
| 325 base::Time cur_alarm_time = | 325 base::Time cur_alarm_time = |
| 326 base::Time::FromJsTime(l_it->js_alarm->scheduled_time); | 326 base::Time::FromJsTime(l_it->js_alarm->scheduled_time); |
| 327 if (cur_alarm_time < soonest_alarm_time) | 327 if (cur_alarm_time < soonest_alarm_time) |
| 328 soonest_alarm_time = cur_alarm_time; | 328 soonest_alarm_time = cur_alarm_time; |
| 329 if (l_it->granularity < min_granularity) | 329 if (l_it->granularity < min_granularity) |
| 330 min_granularity = l_it->granularity; | 330 min_granularity = l_it->granularity; |
| 331 base::TimeDelta cur_alarm_delta = cur_alarm_time - clock_->Now(); | 331 base::TimeDelta cur_alarm_delta = cur_alarm_time - last_poll_time_; |
|
Devlin
2014/01/17 17:25:04
Slight tweak from Matt's solution here - I think t
| |
| 332 if (cur_alarm_delta < l_it->minimum_granularity) | |
| 333 cur_alarm_delta = l_it->minimum_granularity; | |
| 332 if (cur_alarm_delta < min_granularity) | 334 if (cur_alarm_delta < min_granularity) |
| 333 min_granularity = cur_alarm_delta; | 335 min_granularity = cur_alarm_delta; |
| 334 if (min_granularity < l_it->minimum_granularity) | |
| 335 min_granularity = l_it->minimum_granularity; | |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 base::Time next_poll(last_poll_time_ + min_granularity); | 339 base::Time next_poll(last_poll_time_ + min_granularity); |
| 340 // If the next alarm is more than min_granularity in the future, wait for it. | 340 // If the next alarm is more than min_granularity in the future, wait for it. |
| 341 // Otherwise, only poll as often as min_granularity. | 341 // Otherwise, only poll as often as min_granularity. |
| 342 // As a special case, if we've never checked for an alarm before | 342 // As a special case, if we've never checked for an alarm before |
| 343 // (e.g. during startup), let alarms fire asap. | 343 // (e.g. during startup), let alarms fire asap. |
| 344 if (last_poll_time_.is_null() || next_poll < soonest_alarm_time) | 344 if (last_poll_time_.is_null() || next_poll < soonest_alarm_time) |
| 345 next_poll = soonest_alarm_time; | 345 next_poll = soonest_alarm_time; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 if (create_info.period_in_minutes.get()) { | 461 if (create_info.period_in_minutes.get()) { |
| 462 js_alarm->period_in_minutes.reset( | 462 js_alarm->period_in_minutes.reset( |
| 463 new double(*create_info.period_in_minutes)); | 463 new double(*create_info.period_in_minutes)); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 Alarm::~Alarm() { | 467 Alarm::~Alarm() { |
| 468 } | 468 } |
| 469 | 469 |
| 470 } // namespace extensions | 470 } // namespace extensions |
| OLD | NEW |