| 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 #include "chrome/browser/extensions/api/alarms/alarms_api.h" | 5 #include "chrome/browser/extensions/api/alarms/alarms_api.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/time/clock.h" | 8 #include "base/time/clock.h" |
| 9 #include "base/time/default_clock.h" | 9 #include "base/time/default_clock.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" | 11 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
| 12 #include "chrome/common/extensions/api/alarms.h" | 12 #include "chrome/common/extensions/api/alarms.h" |
| 13 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
| 14 | 14 |
| 15 namespace alarms = extensions::api::alarms; | 15 namespace alarms = extensions::api::alarms; |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kDefaultAlarmName[] = ""; | 21 const char kDefaultAlarmName[] = ""; |
| 22 const char kAlarmNotFound[] = "No alarm named '*' exists."; | |
| 23 const char kBothRelativeAndAbsoluteTime[] = | 22 const char kBothRelativeAndAbsoluteTime[] = |
| 24 "Cannot set both when and delayInMinutes."; | 23 "Cannot set both when and delayInMinutes."; |
| 25 const char kNoScheduledTime[] = | 24 const char kNoScheduledTime[] = |
| 26 "Must set at least one of when, delayInMinutes, or periodInMinutes."; | 25 "Must set at least one of when, delayInMinutes, or periodInMinutes."; |
| 27 const int kReleaseDelayMinimum = 1; | 26 const int kReleaseDelayMinimum = 1; |
| 28 const int kDevDelayMinimum = 0; | 27 const int kDevDelayMinimum = 0; |
| 29 | 28 |
| 30 bool ValidateAlarmCreateInfo(const std::string& alarm_name, | 29 bool ValidateAlarmCreateInfo(const std::string& alarm_name, |
| 31 const alarms::AlarmCreateInfo& create_info, | 30 const alarms::AlarmCreateInfo& create_info, |
| 32 const Extension* extension, | 31 const Extension* extension, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 name, | 139 name, |
| 141 base::Bind(&AlarmsGetFunction::Callback, this, name)); | 140 base::Bind(&AlarmsGetFunction::Callback, this, name)); |
| 142 | 141 |
| 143 return true; | 142 return true; |
| 144 } | 143 } |
| 145 | 144 |
| 146 void AlarmsGetFunction::Callback( | 145 void AlarmsGetFunction::Callback( |
| 147 const std::string& name, extensions::Alarm* alarm) { | 146 const std::string& name, extensions::Alarm* alarm) { |
| 148 if (alarm) { | 147 if (alarm) { |
| 149 results_ = alarms::Get::Results::Create(*alarm->js_alarm); | 148 results_ = alarms::Get::Results::Create(*alarm->js_alarm); |
| 150 SendResponse(true); | |
| 151 } else { | |
| 152 error_ = ErrorUtils::FormatErrorMessage(kAlarmNotFound, name); | |
| 153 SendResponse(false); | |
| 154 } | 149 } |
| 150 SendResponse(true); |
| 155 } | 151 } |
| 156 | 152 |
| 157 bool AlarmsGetAllFunction::RunImpl() { | 153 bool AlarmsGetAllFunction::RunImpl() { |
| 158 AlarmManager::Get(GetProfile())->GetAllAlarms( | 154 AlarmManager::Get(GetProfile())->GetAllAlarms( |
| 159 extension_id(), base::Bind(&AlarmsGetAllFunction::Callback, this)); | 155 extension_id(), base::Bind(&AlarmsGetAllFunction::Callback, this)); |
| 160 return true; | 156 return true; |
| 161 } | 157 } |
| 162 | 158 |
| 163 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { | 159 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { |
| 164 if (alarms) { | 160 if (alarms) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 extension_id(), base::Bind(&AlarmsClearAllFunction::Callback, this)); | 194 extension_id(), base::Bind(&AlarmsClearAllFunction::Callback, this)); |
| 199 return true; | 195 return true; |
| 200 } | 196 } |
| 201 | 197 |
| 202 void AlarmsClearAllFunction::Callback() { | 198 void AlarmsClearAllFunction::Callback() { |
| 203 SetResult(new base::FundamentalValue(true)); | 199 SetResult(new base::FundamentalValue(true)); |
| 204 SendResponse(true); | 200 SendResponse(true); |
| 205 } | 201 } |
| 206 | 202 |
| 207 } // namespace extensions | 203 } // namespace extensions |
| OLD | NEW |