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 #include "chrome/common/extensions/api/experimental.alarms.h" |
| 16 |
| 17 namespace Alarms = extensions::api::experimental_alarms; |
| 18 |
| 19 namespace { |
| 20 |
| 21 const char kOnAlarmEvent[] = "experimental.alarms.onAlarm"; |
| 22 const char kDefaultAlarmName[] = ""; |
| 23 |
| 24 void AlarmCallback(Profile* profile, const std::string& extension_id) { |
| 25 // The profile could have gone away before this task was run. |
| 26 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 27 return; |
| 28 |
| 29 ListValue args; |
| 30 std::string json_args; |
| 31 args.Append(base::Value::CreateStringValue(kDefaultAlarmName)); |
| 32 base::JSONWriter::Write(&args, &json_args); |
| 33 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 34 extension_id, kOnAlarmEvent, json_args, NULL, GURL()); |
| 35 } |
| 36 |
| 37 } |
| 38 |
| 39 bool AlarmsCreateFunction::RunImpl() { |
| 40 scoped_ptr<Alarms::Create::Params> params( |
| 41 Alarms::Create::Params::Create(*args_)); |
| 42 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 43 |
| 44 // TODO(mpcomplete): Better handling of granularity. Introduce an alarm |
| 45 // manager that dispatches alarms in batches, and can also cancel previous |
| 46 // alarms. Handle the "name" parameter. |
| 47 // http://crbug.com/81758 |
| 48 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 49 base::Bind(&AlarmCallback, profile(), extension_id()), |
| 50 params->alarm_info.delay_in_seconds * 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 |