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..9102f2f3a225ea7e1c022533bd32fd75f6063223 |
--- /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" |
+ |
+namespace { |
+ |
+const char kOnAlarmEvent[] = "experimental.alarms.onAlarm"; |
+ |
+void SetAlarmCallback(Profile* profile, const std::string& extension_id) { |
+ // 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("default")); |
+ base::JSONWriter::Write(&args, &json_args); |
+ profile->GetExtensionEventRouter()->DispatchEventToExtension( |
+ extension_id, kOnAlarmEvent, json_args, NULL, GURL()); |
+} |
+ |
+} |
+ |
+bool AlarmsSetFunction::RunImpl() { |
+ DictionaryValue* details; |
Aaron Boodman
2012/03/27 23:34:01
Please use the JSON Schema compiler for new APIs.
Matt Perry
2012/03/28 00:33:03
Done.
|
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
+ |
+ int delay_s; |
+ bool repeating = false; |
+ EXTENSION_FUNCTION_VALIDATE(details->GetInteger("delayInSeconds", &delay_s)); |
+ if (details->HasKey("repeating")) |
+ EXTENSION_FUNCTION_VALIDATE(details->GetBoolean("repeating", &repeating)); |
+ |
+ // 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()), delay_s*1000); |
+ |
+ 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; |
+} |