| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 // Internal helper to add an alarm and start the timer with the given delay. | 178 // Internal helper to add an alarm and start the timer with the given delay. |
| 179 void AddAlarmImpl(const std::string& extension_id, | 179 void AddAlarmImpl(const std::string& extension_id, |
| 180 const Alarm& alarm); | 180 const Alarm& alarm); |
| 181 | 181 |
| 182 // Syncs our alarm data for the given extension to/from the state storage. | 182 // Syncs our alarm data for the given extension to/from the state storage. |
| 183 void WriteToStorage(const std::string& extension_id); | 183 void WriteToStorage(const std::string& extension_id); |
| 184 void ReadFromStorage(const std::string& extension_id, | 184 void ReadFromStorage(const std::string& extension_id, |
| 185 scoped_ptr<base::Value> value); | 185 scoped_ptr<base::Value> value); |
| 186 | 186 |
| 187 // Set the timer to go off at the specified |time|, and set |next_poll_time| |
| 188 // appropriately. |
| 189 void SetNextPollTime(const base::Time& time); |
| 190 |
| 187 // Schedules the next poll of alarms for when the next soonest alarm runs, | 191 // Schedules the next poll of alarms for when the next soonest alarm runs, |
| 188 // but not more often than the minimum granularity of all alarms. | 192 // but not more often than the minimum granularity of all alarms. |
| 189 void ScheduleNextPoll(); | 193 void ScheduleNextPoll(); |
| 190 | 194 |
| 191 // Polls the alarms, running any that have elapsed. After running them and | 195 // Polls the alarms, running any that have elapsed. After running them and |
| 192 // rescheduling repeating alarms, schedule the next poll. | 196 // rescheduling repeating alarms, schedule the next poll. |
| 193 void PollAlarms(); | 197 void PollAlarms(); |
| 194 | 198 |
| 195 // Executes |action| for given extension, making sure that the extension's | 199 // Executes |action| for given extension, making sure that the extension's |
| 196 // alarm data has been synced from the storage. | 200 // alarm data has been synced from the storage. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 219 // Invariant: None of the AlarmLists are empty. | 223 // Invariant: None of the AlarmLists are empty. |
| 220 AlarmMap alarms_; | 224 AlarmMap alarms_; |
| 221 | 225 |
| 222 // A map of actions waiting for alarm data to be synced from storage, per | 226 // A map of actions waiting for alarm data to be synced from storage, per |
| 223 // extension. | 227 // extension. |
| 224 ReadyMap ready_actions_; | 228 ReadyMap ready_actions_; |
| 225 | 229 |
| 226 // The previous time that alarms were run. | 230 // The previous time that alarms were run. |
| 227 base::Time last_poll_time_; | 231 base::Time last_poll_time_; |
| 228 | 232 |
| 229 // Next poll's time. Used only by unit tests. | 233 // Next poll's time. |
| 230 base::Time test_next_poll_time_; | 234 base::Time next_poll_time_; |
| 231 | 235 |
| 232 DISALLOW_COPY_AND_ASSIGN(AlarmManager); | 236 DISALLOW_COPY_AND_ASSIGN(AlarmManager); |
| 233 }; | 237 }; |
| 234 | 238 |
| 235 } // namespace extensions | 239 } // namespace extensions |
| 236 | 240 |
| 237 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 241 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| OLD | NEW |