OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // File-level comment to appease parser. Eventually this will not be necessary. | 5 // File-level comment to appease parser. Eventually this will not be necessary. |
6 // TODO(mpcomplete): We need documentation before we can release this. | 6 // TODO(mpcomplete): We need documentation before we can release this. |
7 | 7 |
8 namespace alarms { | 8 namespace alarms { |
9 dictionary Alarm { | 9 dictionary Alarm { |
10 // Name of this alarm. | 10 // Name of this alarm. |
11 DOMString name; | 11 DOMString name; |
12 | 12 |
13 // Original length of time in minutes after which the onAlarm event should | 13 // Time at which this alarm was scheduled to fire, in milliseconds past the |
14 // fire. | 14 // epoch (e.g. Date.now() + n). For performance reasons, the alarm may have |
15 // TODO: need minimum=0 | 15 // been delayed an arbitrary amount beyond this. |
16 double delayInMinutes; | 16 double scheduledTime; |
17 | 17 |
18 // True if the alarm repeatedly fires at regular intervals, false if it | 18 // If not null, the alarm is a repeating alarm and will fire again in |
19 // only fires once. | 19 // 'periodInMinutes' minutes. |
20 boolean repeating; | 20 double? periodInMinutes; |
21 }; | 21 }; |
22 | 22 |
23 // TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is | 23 // TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is |
24 // fixed. | 24 // fixed. |
25 dictionary AlarmCreateInfo { | 25 dictionary AlarmCreateInfo { |
| 26 // Time at which the alarm should fire, in milliseconds past the epoch |
| 27 // (e.g. Date.now() + n). |
| 28 double? when; |
| 29 |
26 // Length of time in minutes after which the onAlarm event should fire. | 30 // Length of time in minutes after which the onAlarm event should fire. |
27 // Note that granularity is not guaranteed: this value is more of a hint to | 31 // |
28 // the browser. For performance reasons, alarms may be delayed an arbitrary | |
29 // amount of time before firing. | |
30 // TODO: need minimum=0 | 32 // TODO: need minimum=0 |
31 double delayInMinutes; | 33 double? delayInMinutes; |
32 | 34 |
33 // True if the alarm should repeatedly fire at regular intervals. Defaults | 35 // If set, the onAlarm event should fire every |periodInMinutes| minutes |
34 // to false. | 36 // after the initial event specified by |when| or |delayInMinutes|. If not |
35 boolean? repeating; | 37 // set, the alarm will only fire once. |
| 38 // |
| 39 // TODO: need minimum=0 |
| 40 double? periodInMinutes; |
36 }; | 41 }; |
37 | 42 |
38 callback AlarmCallback = void (Alarm alarm); | 43 callback AlarmCallback = void (Alarm alarm); |
39 callback AlarmListCallback = void (Alarm[] alarms); | 44 callback AlarmListCallback = void (Alarm[] alarms); |
40 | 45 |
41 interface Functions { | 46 interface Functions { |
42 // Creates an alarm. After the delay is elapsed, the onAlarm event is | 47 // Creates an alarm. Near the time(s) specified by 'alarmInfo', the onAlarm |
43 // fired. If there is another alarm with the same name (or no name if none | 48 // event is fired. If there is another alarm with the same name (or no name |
44 // is specified), it will be cancelled and replaced by this alarm. | 49 // if none is specified), it will be cancelled and replaced by this alarm. |
| 50 // |
| 51 // Note that granularity is not guaranteed: times are more of a hint to the |
| 52 // browser. For performance reasons, alarms may be delayed an arbitrary |
| 53 // amount of time before firing. |
| 54 // |
45 // |name|: Optional name to identify this alarm. Defaults to the empty | 55 // |name|: Optional name to identify this alarm. Defaults to the empty |
46 // string. | 56 // string. |
| 57 // |
| 58 // |alarmInfo|: Describes when the alarm should fire. The initial time must |
| 59 // be specified by either |when| or |delayInMinutes| (but not both). If |
| 60 // |periodInMinutes| is set, the alarm will repeat every |periodInMinutes| |
| 61 // minutes after the initial event. If neither |when| or |delayInMinutes| |
| 62 // is set for a repeating alarm, |periodInMinutes| is used as the default |
| 63 // for |delayInMinutes|. |
47 static void create(optional DOMString name, AlarmCreateInfo alarmInfo); | 64 static void create(optional DOMString name, AlarmCreateInfo alarmInfo); |
48 | 65 |
49 // Retrieves details about the specified alarm. | 66 // Retrieves details about the specified alarm. |
50 // |name|: The name of the alarm to get. Defaults to the empty string. | 67 // |name|: The name of the alarm to get. Defaults to the empty string. |
51 static void get(optional DOMString name, AlarmCallback callback); | 68 static void get(optional DOMString name, AlarmCallback callback); |
52 | 69 |
53 // Gets an array of all the alarms. | 70 // Gets an array of all the alarms. |
54 static void getAll(AlarmListCallback callback); | 71 static void getAll(AlarmListCallback callback); |
55 | 72 |
56 // Clears the alarm with the given name. | 73 // Clears the alarm with the given name. |
57 // |name|: The name of the alarm to clear. Defaults to the empty string. | 74 // |name|: The name of the alarm to clear. Defaults to the empty string. |
58 static void clear(optional DOMString name); | 75 static void clear(optional DOMString name); |
59 | 76 |
60 // Clears all alarms. | 77 // Clears all alarms. |
61 static void clearAll(); | 78 static void clearAll(); |
62 }; | 79 }; |
63 | 80 |
64 interface Events { | 81 interface Events { |
65 // Fired when an alarm has elapsed. Useful for transient background pages. | 82 // Fired when an alarm has elapsed. Useful for transient background pages. |
66 // |alarm|: The alarm that has elapsed. | 83 // |alarm|: The alarm that has elapsed. |
67 static void onAlarm(Alarm alarm); | 84 static void onAlarm(Alarm alarm); |
68 }; | 85 }; |
69 }; | 86 }; |
OLD | NEW |