Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / api / alarms.idl
blob3b218e0f0dd71d2970fb15ea4294b26a46771ede
1 // Copyright (c) 2012 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.
5 // Use the <code>chrome.alarms</code> API to schedule code to run
6 // periodically or at a specified time in the future.
7 namespace alarms {
8 dictionary Alarm {
9 // Name of this alarm.
10 DOMString name;
12 // Time at which this alarm was scheduled to fire, in milliseconds past the
13 // epoch (e.g. <code>Date.now() + n</code>). For performance reasons, the
14 // alarm may have been delayed an arbitrary amount beyond this.
15 double scheduledTime;
17 // If not null, the alarm is a repeating alarm and will fire again in
18 // <var>periodInMinutes</var> minutes.
19 double? periodInMinutes;
22 // TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is
23 // fixed.
24 dictionary AlarmCreateInfo {
25 // Time at which the alarm should fire, in milliseconds past the epoch
26 // (e.g. <code>Date.now() + n</code>).
27 double? when;
29 // Length of time in minutes after which the <code>onAlarm</code> event
30 // should fire.
32 // <!-- TODO: need minimum=0 -->
33 double? delayInMinutes;
35 // If set, the onAlarm event should fire every <var>periodInMinutes</var>
36 // minutes after the initial event specified by <var>when</var> or
37 // <var>delayInMinutes</var>. If not set, the alarm will only fire once.
39 // <!-- TODO: need minimum=0 -->
40 double? periodInMinutes;
43 callback AlarmCallback = void (Alarm alarm);
44 callback AlarmListCallback = void (Alarm[] alarms);
46 interface Functions {
47 // Creates an alarm. Near the time(s) specified by <var>alarmInfo</var>,
48 // the <code>onAlarm</code> event is fired. If there is another alarm with
49 // the same name (or no name if none is specified), it will be cancelled and
50 // replaced by this alarm.
52 // In order to reduce the load on the user's machine, Chrome limits alarms
53 // to at most once every 1 minute but may delay them an arbitrary amount
54 // more. That is, setting <code>delayInMinutes</code> or
55 // <code>periodInMinutes</code> to less than <code>1</code> will not be
56 // honored and will cause a warning. <code>when</code> can be set to less
57 // than 1 minute after "now" without warning but won't actually cause the
58 // alarm to fire for at least 1 minute.
60 // To help you debug your app or extension, when you've loaded it unpacked,
61 // there's no limit to how often the alarm can fire.
63 // |name|: Optional name to identify this alarm. Defaults to the empty
64 // string.
66 // |alarmInfo|: Describes when the alarm should fire. The initial time must
67 // be specified by either <var>when</var> or <var>delayInMinutes</var> (but
68 // not both). If <var>periodInMinutes</var> is set, the alarm will repeat
69 // every <var>periodInMinutes</var> minutes after the initial event. If
70 // neither <var>when</var> or <var>delayInMinutes</var> is set for a
71 // repeating alarm, <var>periodInMinutes</var> is used as the default for
72 // <var>delayInMinutes</var>.
73 static void create(optional DOMString name, AlarmCreateInfo alarmInfo);
75 // Retrieves details about the specified alarm.
76 // |name|: The name of the alarm to get. Defaults to the empty string.
77 static void get(optional DOMString name, AlarmCallback callback);
79 // Gets an array of all the alarms.
80 static void getAll(AlarmListCallback callback);
82 // Clears the alarm with the given name.
83 // |name|: The name of the alarm to clear. Defaults to the empty string.
84 static void clear(optional DOMString name);
86 // Clears all alarms.
87 static void clearAll();
90 interface Events {
91 // Fired when an alarm has elapsed. Useful for event pages.
92 // |alarm|: The alarm that has elapsed.
93 static void onAlarm(Alarm alarm);