| 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 "extensions/browser/api/alarms/alarms_api.h" | 5 #include "extensions/browser/api/alarms/alarms_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool AlarmsGetAllFunction::RunAsync() { | 157 bool AlarmsGetAllFunction::RunAsync() { |
| 158 AlarmManager::Get(browser_context()) | 158 AlarmManager::Get(browser_context()) |
| 159 ->GetAllAlarms(extension_id(), | 159 ->GetAllAlarms(extension_id(), |
| 160 base::Bind(&AlarmsGetAllFunction::Callback, this)); | 160 base::Bind(&AlarmsGetAllFunction::Callback, this)); |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { | 164 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { |
| 165 scoped_ptr<base::ListValue> alarms_value(new base::ListValue()); |
| 165 if (alarms) { | 166 if (alarms) { |
| 166 std::vector<linked_ptr<alarms::Alarm>> create_arg; | 167 for (const Alarm& alarm : *alarms) |
| 167 create_arg.reserve(alarms->size()); | 168 alarms_value->Append(alarm.js_alarm->ToValue()); |
| 168 for (size_t i = 0, size = alarms->size(); i < size; ++i) { | |
| 169 create_arg.push_back((*alarms)[i].js_alarm); | |
| 170 } | |
| 171 results_ = alarms::GetAll::Results::Create(create_arg); | |
| 172 } else { | |
| 173 SetResult(new base::ListValue()); | |
| 174 } | 169 } |
| 170 SetResult(std::move(alarms_value)); |
| 175 SendResponse(true); | 171 SendResponse(true); |
| 176 } | 172 } |
| 177 | 173 |
| 178 bool AlarmsClearFunction::RunAsync() { | 174 bool AlarmsClearFunction::RunAsync() { |
| 179 scoped_ptr<alarms::Clear::Params> params( | 175 scoped_ptr<alarms::Clear::Params> params( |
| 180 alarms::Clear::Params::Create(*args_)); | 176 alarms::Clear::Params::Create(*args_)); |
| 181 EXTENSION_FUNCTION_VALIDATE(params.get()); | 177 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 182 | 178 |
| 183 std::string name = params->name.get() ? *params->name : kDefaultAlarmName; | 179 std::string name = params->name.get() ? *params->name : kDefaultAlarmName; |
| 184 AlarmManager::Get(browser_context()) | 180 AlarmManager::Get(browser_context()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 base::Bind(&AlarmsClearAllFunction::Callback, this)); | 195 base::Bind(&AlarmsClearAllFunction::Callback, this)); |
| 200 return true; | 196 return true; |
| 201 } | 197 } |
| 202 | 198 |
| 203 void AlarmsClearAllFunction::Callback() { | 199 void AlarmsClearAllFunction::Callback() { |
| 204 SetResult(new base::FundamentalValue(true)); | 200 SetResult(new base::FundamentalValue(true)); |
| 205 SendResponse(true); | 201 SendResponse(true); |
| 206 } | 202 } |
| 207 | 203 |
| 208 } // namespace extensions | 204 } // namespace extensions |
| OLD | NEW |