| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 WriteToConsole(content::CONSOLE_MESSAGE_LEVEL_WARNING, *it); | 108 WriteToConsole(content::CONSOLE_MESSAGE_LEVEL_WARNING, *it); |
| 109 | 109 |
| 110 const int kSecondsPerMinute = 60; | 110 const int kSecondsPerMinute = 60; |
| 111 base::TimeDelta granularity = | 111 base::TimeDelta granularity = |
| 112 base::TimeDelta::FromSecondsD( | 112 base::TimeDelta::FromSecondsD( |
| 113 (Manifest::IsUnpackedLocation(extension()->location()) | 113 (Manifest::IsUnpackedLocation(extension()->location()) |
| 114 ? alarms_api_constants::kDevDelayMinimum | 114 ? alarms_api_constants::kDevDelayMinimum |
| 115 : alarms_api_constants::kReleaseDelayMinimum)) * | 115 : alarms_api_constants::kReleaseDelayMinimum)) * |
| 116 kSecondsPerMinute; | 116 kSecondsPerMinute; |
| 117 | 117 |
| 118 Alarm alarm(alarm_name, params->alarm_info, granularity, clock_->Now()); | 118 std::unique_ptr<Alarm> alarm( |
| 119 new Alarm(alarm_name, params->alarm_info, granularity, clock_->Now())); |
| 119 AlarmManager::Get(browser_context()) | 120 AlarmManager::Get(browser_context()) |
| 120 ->AddAlarm(extension_id(), alarm, | 121 ->AddAlarm(extension_id(), std::move(alarm), |
| 121 base::Bind(&AlarmsCreateFunction::Callback, this)); | 122 base::Bind(&AlarmsCreateFunction::Callback, this)); |
| 122 | 123 |
| 123 return true; | 124 return true; |
| 124 } | 125 } |
| 125 | 126 |
| 126 void AlarmsCreateFunction::Callback() { | 127 void AlarmsCreateFunction::Callback() { |
| 127 SendResponse(true); | 128 SendResponse(true); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool AlarmsGetFunction::RunAsync() { | 131 bool AlarmsGetFunction::RunAsync() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 bool AlarmsGetAllFunction::RunAsync() { | 152 bool AlarmsGetAllFunction::RunAsync() { |
| 152 AlarmManager::Get(browser_context()) | 153 AlarmManager::Get(browser_context()) |
| 153 ->GetAllAlarms(extension_id(), | 154 ->GetAllAlarms(extension_id(), |
| 154 base::Bind(&AlarmsGetAllFunction::Callback, this)); | 155 base::Bind(&AlarmsGetAllFunction::Callback, this)); |
| 155 return true; | 156 return true; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { | 159 void AlarmsGetAllFunction::Callback(const AlarmList* alarms) { |
| 159 std::unique_ptr<base::ListValue> alarms_value(new base::ListValue()); | 160 std::unique_ptr<base::ListValue> alarms_value(new base::ListValue()); |
| 160 if (alarms) { | 161 if (alarms) { |
| 161 for (const Alarm& alarm : *alarms) | 162 for (const std::unique_ptr<Alarm>& alarm : *alarms) |
| 162 alarms_value->Append(alarm.js_alarm->ToValue()); | 163 alarms_value->Append(alarm->js_alarm->ToValue()); |
| 163 } | 164 } |
| 164 SetResult(std::move(alarms_value)); | 165 SetResult(std::move(alarms_value)); |
| 165 SendResponse(true); | 166 SendResponse(true); |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool AlarmsClearFunction::RunAsync() { | 169 bool AlarmsClearFunction::RunAsync() { |
| 169 std::unique_ptr<alarms::Clear::Params> params( | 170 std::unique_ptr<alarms::Clear::Params> params( |
| 170 alarms::Clear::Params::Create(*args_)); | 171 alarms::Clear::Params::Create(*args_)); |
| 171 EXTENSION_FUNCTION_VALIDATE(params.get()); | 172 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 172 | 173 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 189 base::Bind(&AlarmsClearAllFunction::Callback, this)); | 190 base::Bind(&AlarmsClearAllFunction::Callback, this)); |
| 190 return true; | 191 return true; |
| 191 } | 192 } |
| 192 | 193 |
| 193 void AlarmsClearAllFunction::Callback() { | 194 void AlarmsClearAllFunction::Callback() { |
| 194 SetResult(base::MakeUnique<base::FundamentalValue>(true)); | 195 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
| 195 SendResponse(true); | 196 SendResponse(true); |
| 196 } | 197 } |
| 197 | 198 |
| 198 } // namespace extensions | 199 } // namespace extensions |
| OLD | NEW |