Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4936)

Unified Diff: chrome/browser/extensions/api/alarms/alarms_api.cc

Issue 9791011: Add experimental.alarms API to allow lazy background pages to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: docs Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698