Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/alarms/alarms_api.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/json/json_writer.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/extensions/extension_event_router.h" | |
| 12 #include "chrome/browser/extensions/extension_service.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/profiles/profile_manager.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kOnAlarmEvent[] = "experimental.alarms.onAlarm"; | |
| 19 | |
| 20 void SetAlarmCallback(Profile* profile, const std::string& extension_id) { | |
| 21 // The profile could have gone away before this task was run. | |
| 22 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
| 23 return; | |
| 24 | |
| 25 ListValue args; | |
| 26 std::string json_args; | |
| 27 args.Append(base::Value::CreateStringValue("default")); | |
| 28 base::JSONWriter::Write(&args, &json_args); | |
| 29 profile->GetExtensionEventRouter()->DispatchEventToExtension( | |
| 30 extension_id, kOnAlarmEvent, json_args, NULL, GURL()); | |
| 31 } | |
| 32 | |
| 33 } | |
| 34 | |
| 35 bool AlarmsSetFunction::RunImpl() { | |
| 36 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.
| |
| 37 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
| 38 | |
| 39 int delay_s; | |
| 40 bool repeating = false; | |
| 41 EXTENSION_FUNCTION_VALIDATE(details->GetInteger("delayInSeconds", &delay_s)); | |
| 42 if (details->HasKey("repeating")) | |
| 43 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean("repeating", &repeating)); | |
| 44 | |
| 45 // TODO(mpcomplete): Better handling of granularity. Introduce an alarm | |
| 46 // manager that dispatches alarms in batches, and can also cancel previous | |
| 47 // alarms. Handle the "name" parameter. | |
| 48 // http://crbug.com/81758 | |
| 49 MessageLoop::current()->PostDelayedTask(FROM_HERE, base::Bind( | |
| 50 &SetAlarmCallback, profile(), extension_id()), delay_s*1000); | |
| 51 | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 bool AlarmsGetFunction::RunImpl() { | |
| 56 error_ = "Not implemented."; | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 bool AlarmsGetAllFunction::RunImpl() { | |
| 61 error_ = "Not implemented."; | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 bool AlarmsClearFunction::RunImpl() { | |
| 66 error_ = "Not implemented."; | |
| 67 return false; | |
| 68 } | |
| 69 | |
| 70 bool AlarmsClearAllFunction::RunImpl() { | |
| 71 error_ = "Not implemented."; | |
| 72 return false; | |
| 73 } | |
| OLD | NEW |