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

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

Issue 10217018: Alarm resolution changed to minutes and minimum delay added. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed type checks for optional string. Created 8 years, 7 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 #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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 delegate_(new DefaultAlarmDelegate(profile)) { 48 delegate_(new DefaultAlarmDelegate(profile)) {
49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
50 content::Source<Profile>(profile_)); 50 content::Source<Profile>(profile_));
51 } 51 }
52 52
53 AlarmManager::~AlarmManager() { 53 AlarmManager::~AlarmManager() {
54 } 54 }
55 55
56 void AlarmManager::AddAlarm(const std::string& extension_id, 56 void AlarmManager::AddAlarm(const std::string& extension_id,
57 const linked_ptr<Alarm>& alarm) { 57 const linked_ptr<Alarm>& alarm) {
58 AddAlarmImpl(extension_id, alarm, 58 base::TimeDelta alarm_time = base::TimeDelta::FromMicroseconds(
Yoyo Zhou 2012/05/05 00:48:59 You can use base::TimeDelta::FromMinutes instead.
59 base::TimeDelta::FromSeconds(alarm->delay_in_seconds)); 59 alarm->delay_in_minutes * base::Time::kMicrosecondsPerMinute);
60 AddAlarmImpl(extension_id, alarm, alarm_time);
60 WriteToPrefs(extension_id); 61 WriteToPrefs(extension_id);
61 } 62 }
62 63
63 const AlarmManager::Alarm* AlarmManager::GetAlarm( 64 const AlarmManager::Alarm* AlarmManager::GetAlarm(
64 const std::string& extension_id, const std::string& name) { 65 const std::string& extension_id, const std::string& name) {
65 AlarmIterator it = GetAlarmIterator(extension_id, name); 66 AlarmIterator it = GetAlarmIterator(extension_id, name);
66 if (it.first == alarms_.end()) 67 if (it.first == alarms_.end())
67 return NULL; 68 return NULL;
68 return it.second->get(); 69 return it.second->get();
69 } 70 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 CHECK(it.first != alarms_.end()); 135 CHECK(it.first != alarms_.end());
135 const Alarm* alarm = it.second->get(); 136 const Alarm* alarm = it.second->get();
136 delegate_->OnAlarm(extension_id, *alarm); 137 delegate_->OnAlarm(extension_id, *alarm);
137 138
138 if (!alarm->repeating) { 139 if (!alarm->repeating) {
139 RemoveAlarmIterator(it); 140 RemoveAlarmIterator(it);
140 } else { 141 } else {
141 // Restart the timer, since it may have been set with a shorter delay 142 // Restart the timer, since it may have been set with a shorter delay
142 // initially. 143 // initially.
143 base::Timer* timer = timers_[alarm].get(); 144 base::Timer* timer = timers_[alarm].get();
144 timer->Start(FROM_HERE, 145 base::TimeDelta alarm_time = base::TimeDelta::FromMicroseconds(
145 base::TimeDelta::FromSeconds(alarm->delay_in_seconds), 146 alarm->delay_in_minutes * base::Time::kMicrosecondsPerMinute);
146 base::Bind(&AlarmManager::OnAlarm, base::Unretained(this), 147 timer->Start(FROM_HERE, alarm_time,
147 extension_id, alarm->name)); 148 base::Bind(&AlarmManager::OnAlarm, base::Unretained(this),
149 extension_id, alarm->name));
148 } 150 }
149 151
150 WriteToPrefs(extension_id); 152 WriteToPrefs(extension_id);
151 } 153 }
152 154
153 void AlarmManager::AddAlarmImpl(const std::string& extension_id, 155 void AlarmManager::AddAlarmImpl(const std::string& extension_id,
154 const linked_ptr<Alarm>& alarm, 156 const linked_ptr<Alarm>& alarm,
155 base::TimeDelta timer_delay) { 157 base::TimeDelta timer_delay) {
156 // Override any old alarm with the same name. 158 // Override any old alarm with the same name.
157 AlarmIterator old_alarm = GetAlarmIterator(extension_id, alarm->name); 159 AlarmIterator old_alarm = GetAlarmIterator(extension_id, alarm->name);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 230 }
229 } 231 }
230 232
231 AlarmPref::AlarmPref() { 233 AlarmPref::AlarmPref() {
232 } 234 }
233 235
234 AlarmPref::~AlarmPref() { 236 AlarmPref::~AlarmPref() {
235 } 237 }
236 238
237 } // namespace extensions 239 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698