Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/extensions/api/alarms/alarm_manager.h

Issue 23205008: Fix a bug where the minimum granular time for Alarms was not calculated properly. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unit tests. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 base::Time now); 37 base::Time now);
38 ~Alarm(); 38 ~Alarm();
39 39
40 linked_ptr<api::alarms::Alarm> js_alarm; 40 linked_ptr<api::alarms::Alarm> js_alarm;
41 // The granularity isn't exposed to the extension's javascript, but we poll at 41 // The granularity isn't exposed to the extension's javascript, but we poll at
42 // least as often as the shortest alarm's granularity. It's initialized as 42 // least as often as the shortest alarm's granularity. It's initialized as
43 // the relative delay requested in creation, even if creation uses an absolute 43 // the relative delay requested in creation, even if creation uses an absolute
44 // time. This will always be at least as large as the min_granularity 44 // time. This will always be at least as large as the min_granularity
45 // constructor argument. 45 // constructor argument.
46 base::TimeDelta granularity; 46 base::TimeDelta granularity;
47 // The minimum granularity is the minimum allowed polling rate. This stops
48 // alarms from polling too often.
49 base::TimeDelta minimum_granularity;
47 }; 50 };
48 51
49 // Manages the currently pending alarms for every extension in a profile. 52 // Manages the currently pending alarms for every extension in a profile.
50 // There is one manager per virtual Profile. 53 // There is one manager per virtual Profile.
51 class AlarmManager 54 class AlarmManager
52 : public ProfileKeyedAPI, 55 : public ProfileKeyedAPI,
53 public content::NotificationObserver, 56 public content::NotificationObserver,
54 public base::SupportsWeakPtr<AlarmManager> { 57 public base::SupportsWeakPtr<AlarmManager> {
55 public: 58 public:
56 typedef std::vector<Alarm> AlarmList; 59 typedef std::vector<Alarm> AlarmList;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Convenience method to get the AlarmManager for a profile. 114 // Convenience method to get the AlarmManager for a profile.
112 static AlarmManager* Get(Profile* profile); 115 static AlarmManager* Get(Profile* profile);
113 116
114 private: 117 private:
115 friend void RunScheduleNextPoll(AlarmManager*); 118 friend void RunScheduleNextPoll(AlarmManager*);
116 friend class ExtensionAlarmsSchedulingTest; 119 friend class ExtensionAlarmsSchedulingTest;
117 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, PollScheduling); 120 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, PollScheduling);
118 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, 121 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest,
119 ReleasedExtensionPollsInfrequently); 122 ReleasedExtensionPollsInfrequently);
120 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, TimerRunning); 123 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, TimerRunning);
124 FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, MinimumGranularity);
121 friend class ProfileKeyedAPIFactory<AlarmManager>; 125 friend class ProfileKeyedAPIFactory<AlarmManager>;
122 126
123 typedef std::string ExtensionId; 127 typedef std::string ExtensionId;
124 typedef std::map<ExtensionId, AlarmList> AlarmMap; 128 typedef std::map<ExtensionId, AlarmList> AlarmMap;
125 129
126 typedef base::Callback<void(const std::string&)> ReadyAction; 130 typedef base::Callback<void(const std::string&)> ReadyAction;
127 typedef std::queue<ReadyAction> ReadyQueue; 131 typedef std::queue<ReadyAction> ReadyQueue;
128 typedef std::map<ExtensionId, ReadyQueue> ReadyMap; 132 typedef std::map<ExtensionId, ReadyQueue> ReadyMap;
129 133
130 // Iterator used to identify a particular alarm within the Map/List pair. 134 // Iterator used to identify a particular alarm within the Map/List pair.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 224
221 // Next poll's time. Used only by unit tests. 225 // Next poll's time. Used only by unit tests.
222 base::Time test_next_poll_time_; 226 base::Time test_next_poll_time_;
223 227
224 DISALLOW_COPY_AND_ASSIGN(AlarmManager); 228 DISALLOW_COPY_AND_ASSIGN(AlarmManager);
225 }; 229 };
226 230
227 } // namespace extensions 231 } // namespace extensions
228 232
229 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ 233 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698