| 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 EXTENSIONS_BROWSER_API_ALARMS_ALARM_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_ALARMS_ALARM_MANAGER_H_ |
| 6 #define EXTENSIONS_BROWSER_API_ALARMS_ALARM_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 friend class ExtensionAlarmsSchedulingTest; | 122 friend class ExtensionAlarmsSchedulingTest; |
| 123 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, PollScheduling); | 123 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, PollScheduling); |
| 124 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, | 124 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, |
| 125 ReleasedExtensionPollsInfrequently); | 125 ReleasedExtensionPollsInfrequently); |
| 126 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, TimerRunning); | 126 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, TimerRunning); |
| 127 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, MinimumGranularity); | 127 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, MinimumGranularity); |
| 128 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, | 128 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, |
| 129 DifferentMinimumGranularities); | 129 DifferentMinimumGranularities); |
| 130 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, | 130 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, |
| 131 RepeatingAlarmsScheduledPredictably); | 131 RepeatingAlarmsScheduledPredictably); |
| 132 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, |
| 133 PollFrequencyFromStoredAlarm); |
| 132 friend class BrowserContextKeyedAPIFactory<AlarmManager>; | 134 friend class BrowserContextKeyedAPIFactory<AlarmManager>; |
| 133 | 135 |
| 134 typedef std::string ExtensionId; | 136 typedef std::string ExtensionId; |
| 135 typedef std::map<ExtensionId, AlarmList> AlarmMap; | 137 typedef std::map<ExtensionId, AlarmList> AlarmMap; |
| 136 | 138 |
| 137 typedef base::Callback<void(const std::string&)> ReadyAction; | 139 typedef base::Callback<void(const std::string&)> ReadyAction; |
| 138 typedef std::queue<ReadyAction> ReadyQueue; | 140 typedef std::queue<ReadyAction> ReadyQueue; |
| 139 typedef std::map<ExtensionId, ReadyQueue> ReadyMap; | 141 typedef std::map<ExtensionId, ReadyQueue> ReadyMap; |
| 140 | 142 |
| 141 // Iterator used to identify a particular alarm within the Map/List pair. | 143 // Iterator used to identify a particular alarm within the Map/List pair. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 179 |
| 178 // Callback for when an alarm fires. | 180 // Callback for when an alarm fires. |
| 179 void OnAlarm(AlarmIterator iter); | 181 void OnAlarm(AlarmIterator iter); |
| 180 | 182 |
| 181 // Internal helper to add an alarm and start the timer with the given delay. | 183 // Internal helper to add an alarm and start the timer with the given delay. |
| 182 void AddAlarmImpl(const std::string& extension_id, const Alarm& alarm); | 184 void AddAlarmImpl(const std::string& extension_id, const Alarm& alarm); |
| 183 | 185 |
| 184 // Syncs our alarm data for the given extension to/from the state storage. | 186 // Syncs our alarm data for the given extension to/from the state storage. |
| 185 void WriteToStorage(const std::string& extension_id); | 187 void WriteToStorage(const std::string& extension_id); |
| 186 void ReadFromStorage(const std::string& extension_id, | 188 void ReadFromStorage(const std::string& extension_id, |
| 189 bool is_unpacked, |
| 187 std::unique_ptr<base::Value> value); | 190 std::unique_ptr<base::Value> value); |
| 188 | 191 |
| 189 // Set the timer to go off at the specified |time|, and set |next_poll_time| | 192 // Set the timer to go off at the specified |time|, and set |next_poll_time| |
| 190 // appropriately. | 193 // appropriately. |
| 191 void SetNextPollTime(const base::Time& time); | 194 void SetNextPollTime(const base::Time& time); |
| 192 | 195 |
| 193 // Schedules the next poll of alarms for when the next soonest alarm runs, | 196 // Schedules the next poll of alarms for when the next soonest alarm runs, |
| 194 // but not more often than the minimum granularity of all alarms. | 197 // but not more often than the minimum granularity of all alarms. |
| 195 void ScheduleNextPoll(); | 198 void ScheduleNextPoll(); |
| 196 | 199 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 240 |
| 238 // Next poll's time. | 241 // Next poll's time. |
| 239 base::Time next_poll_time_; | 242 base::Time next_poll_time_; |
| 240 | 243 |
| 241 DISALLOW_COPY_AND_ASSIGN(AlarmManager); | 244 DISALLOW_COPY_AND_ASSIGN(AlarmManager); |
| 242 }; | 245 }; |
| 243 | 246 |
| 244 } // namespace extensions | 247 } // namespace extensions |
| 245 | 248 |
| 246 #endif // EXTENSIONS_BROWSER_API_ALARMS_ALARM_MANAGER_H_ | 249 #endif // EXTENSIONS_BROWSER_API_ALARMS_ALARM_MANAGER_H_ |
| OLD | NEW |