Chromium Code Reviews| Index: chrome/browser/extensions/api/alarms/alarms_api.cc |
| diff --git a/chrome/browser/extensions/api/alarms/alarms_api.cc b/chrome/browser/extensions/api/alarms/alarms_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2bf2251368bf3abe13fd88299e635c25551cff31 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/alarms/alarms_api.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/alarms/alarms_api.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/json/json_writer.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/extension_event_router.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/common/extensions/api/experimental.alarms.h" |
| + |
| +namespace Alarms = extensions::api::experimental_alarms; |
| + |
| +namespace { |
| + |
| +const char kOnAlarmEvent[] = "experimental.alarms.onAlarm"; |
| +const char kDefaultAlarmName[] = "default"; |
| + |
| +void SetAlarmCallback(Profile* profile, const std::string& extension_id) { |
|
Aaron Boodman
2012/03/28 03:36:18
Maybe just AlarmCallback? How is this setting anyt
Matt Perry
2012/03/28 20:21:36
It was (SetAlarm)Callback, not Set(AlarmCallback)
|
| + // The profile could have gone away before this task was run. |
| + if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| + return; |
| + |
| + ListValue args; |
| + std::string json_args; |
| + args.Append(base::Value::CreateStringValue(kDefaultAlarmName)); |
| + base::JSONWriter::Write(&args, &json_args); |
| + profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| + extension_id, kOnAlarmEvent, json_args, NULL, GURL()); |
| +} |
| + |
| +} |
| + |
| +bool AlarmsCreateFunction::RunImpl() { |
| + scoped_ptr<Alarms::Create::Params> params( |
| + Alarms::Create::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + // TODO(mpcomplete): Better handling of granularity. Introduce an alarm |
| + // manager that dispatches alarms in batches, and can also cancel previous |
| + // alarms. Handle the "name" parameter. |
| + // http://crbug.com/81758 |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + base::Bind(&SetAlarmCallback, profile(), extension_id()), |
| + params->alarm_info.delay_in_seconds*1000); |
|
Aaron Boodman
2012/03/28 03:36:18
"*".wrap(" ");
Matt Perry
2012/03/28 20:21:36
Done.
|
| + |
| + return true; |
| +} |
| + |
| +bool AlarmsGetFunction::RunImpl() { |
| + error_ = "Not implemented."; |
| + return false; |
| +} |
| + |
| +bool AlarmsGetAllFunction::RunImpl() { |
| + error_ = "Not implemented."; |
| + return false; |
| +} |
| + |
| +bool AlarmsClearFunction::RunImpl() { |
| + error_ = "Not implemented."; |
| + return false; |
| +} |
| + |
| +bool AlarmsClearAllFunction::RunImpl() { |
| + error_ = "Not implemented."; |
| + return false; |
| +} |