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

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

Issue 10545128: Unrevert r141537: Add extensions::StateStore and use that instead of (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix.crash Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/value_conversions.cc ('k') | chrome/browser/extensions/api/alarms/alarm_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <map> 10 #include <map>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/weak_ptr.h"
13 #include "base/timer.h" 14 #include "base/timer.h"
14 #include "chrome/browser/extensions/extension_function.h" 15 #include "chrome/browser/extensions/extension_function.h"
15 #include "chrome/common/extensions/api/alarms.h" 16 #include "chrome/common/extensions/api/alarms.h"
16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
18 19
19 class Profile; 20 class Profile;
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 class ExtensionAlarmsSchedulingTest; 24 class ExtensionAlarmsSchedulingTest;
24 25
25 // Manages the currently pending alarms for every extension in a profile. 26 // Manages the currently pending alarms for every extension in a profile.
26 // There is one manager per virtual Profile. 27 // There is one manager per virtual Profile.
27 class AlarmManager : public content::NotificationObserver { 28 class AlarmManager
29 : public content::NotificationObserver,
30 public base::SupportsWeakPtr<AlarmManager> {
28 public: 31 public:
29 typedef extensions::api::alarms::Alarm Alarm; 32 typedef extensions::api::alarms::Alarm Alarm;
30 typedef std::vector<linked_ptr<Alarm> > AlarmList; 33 typedef std::vector<linked_ptr<Alarm> > AlarmList;
31 34
32 class Delegate { 35 class Delegate {
33 public: 36 public:
34 virtual ~Delegate() {} 37 virtual ~Delegate() {}
35 // Called when an alarm fires. 38 // Called when an alarm fires.
36 virtual void OnAlarm(const std::string& extension_id, 39 virtual void OnAlarm(const std::string& extension_id,
37 const Alarm& alarm) = 0; 40 const Alarm& alarm) = 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 void RemoveAlarmIterator(const AlarmIterator& iter); 96 void RemoveAlarmIterator(const AlarmIterator& iter);
94 97
95 // Callback for when an alarm fires. 98 // Callback for when an alarm fires.
96 void OnAlarm(const std::string& extension_id, const std::string& name); 99 void OnAlarm(const std::string& extension_id, const std::string& name);
97 100
98 // Internal helper to add an alarm and start the timer with the given delay. 101 // Internal helper to add an alarm and start the timer with the given delay.
99 void AddAlarmImpl(const std::string& extension_id, 102 void AddAlarmImpl(const std::string& extension_id,
100 const linked_ptr<Alarm>& alarm, 103 const linked_ptr<Alarm>& alarm,
101 base::TimeDelta time_delay); 104 base::TimeDelta time_delay);
102 105
103 // Syncs our alarm data for the given extension to/from the prefs file. 106 // Syncs our alarm data for the given extension to/from the state storage.
104 void WriteToPrefs(const std::string& extension_id); 107 void WriteToStorage(const std::string& extension_id);
105 void ReadFromPrefs(const std::string& extension_id); 108 void ReadFromStorage(const std::string& extension_id,
109 scoped_ptr<base::Value> value);
106 110
107 // Schedules the next poll of alarms for when the next soonest alarm runs, 111 // Schedules the next poll of alarms for when the next soonest alarm runs,
108 // but do not more often than min_period. 112 // but do not more often than min_period.
109 void ScheduleNextPoll(base::TimeDelta min_period); 113 void ScheduleNextPoll(base::TimeDelta min_period);
110 114
111 // Polls the alarms, running any that have elapsed. After running them and 115 // Polls the alarms, running any that have elapsed. After running them and
112 // rescheduling repeating alarms, schedule the next poll. 116 // rescheduling repeating alarms, schedule the next poll.
113 void PollAlarms(); 117 void PollAlarms();
114 118
115 // NotificationObserver: 119 // NotificationObserver:
(...skipping 12 matching lines...) Expand all
128 AlarmMap alarms_; 132 AlarmMap alarms_;
129 133
130 // A map of the next scheduled times associated with each alarm. 134 // A map of the next scheduled times associated with each alarm.
131 AlarmRuntimeInfoMap scheduled_times_; 135 AlarmRuntimeInfoMap scheduled_times_;
132 136
133 // The previous and next time that alarms were and will be run. 137 // The previous and next time that alarms were and will be run.
134 base::Time last_poll_time_; 138 base::Time last_poll_time_;
135 base::Time next_poll_time_; 139 base::Time next_poll_time_;
136 }; 140 };
137 141
138 // Contains the data we store in the extension prefs for each alarm.
139 struct AlarmPref {
140 linked_ptr<AlarmManager::Alarm> alarm;
141 base::Time scheduled_run_time;
142
143 AlarmPref();
144 ~AlarmPref();
145 };
146
147 } // namespace extensions 142 } // namespace extensions
148 143
149 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ 144 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__
OLDNEW
« no previous file with comments | « base/value_conversions.cc ('k') | chrome/browser/extensions/api/alarms/alarm_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698