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 |
24 // fixed. | 24 // is 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). Note that granularity is not guaranteed: this | |
28 // value is more of a hint to the browser. For performance reasons, alarms | |
29 // may be delayed an arbitrary amount of time before firing. | |
30 // | |
31 // Cannot be specified with |delayInMinutes|, and one of |when|, | |
Aaron Boodman
2012/06/12 23:02:38
Maybe it would be simpler to just describe the all
Jeffrey Yasskin
2012/06/12 23:37:28
Done.
| |
32 // |delayInMinutes|, or |periodInMinutes| must be set. | |
33 double? when; | |
34 | |
26 // Length of time in minutes after which the onAlarm event should fire. | 35 // 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 | 36 // Note that granularity is not guaranteed: this value is more of a hint to |
28 // the browser. For performance reasons, alarms may be delayed an arbitrary | 37 // the browser. For performance reasons, alarms may be delayed an arbitrary |
29 // amount of time before firing. | 38 // amount of time before firing. |
39 // | |
40 // Cannot be specified with |when|, and one of |when|, |delayInMinutes|, or | |
41 // |periodInMinutes| must be set. | |
42 // | |
30 // TODO: need minimum=0 | 43 // TODO: need minimum=0 |
31 double delayInMinutes; | 44 double? delayInMinutes; |
32 | 45 |
33 // True if the alarm should repeatedly fire at regular intervals. Defaults | 46 // If set, the onAlarm event should fire every |periodInMinutes| minutes |
34 // to false. | 47 // after the initial event specified by |when| or |delayInMinutes|. If |
35 boolean? repeating; | 48 // neither |when| nor |delayInMinutes| is set, |delayInMinutes| defaults to |
49 // |periodInMinutes|. If not set, the alarm will only fire once. | |
50 // | |
51 // Note that granularity is not guaranteed: this value is more of a hint to | |
52 // the browser. For performance reasons, alarms may be delayed an arbitrary | |
53 // amount of time before firing. | |
54 // | |
55 // TODO: need minimum=0 | |
56 double? periodInMinutes; | |
36 }; | 57 }; |
37 | 58 |
38 callback AlarmCallback = void (Alarm alarm); | 59 callback AlarmCallback = void (Alarm alarm); |
39 callback AlarmListCallback = void (Alarm[] alarms); | 60 callback AlarmListCallback = void (Alarm[] alarms); |
40 | 61 |
41 interface Functions { | 62 interface Functions { |
42 // Creates an alarm. After the delay is elapsed, the onAlarm event is | 63 // Creates an alarm. Near the time specified by 'alarmInfo', the onAlarm |
43 // fired. If there is another alarm with the same name (or no name if none | 64 // 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. | 65 // if none is specified), it will be cancelled and replaced by this alarm. |
45 // |name|: Optional name to identify this alarm. Defaults to the empty | 66 // |name|: Optional name to identify this alarm. Defaults to the empty |
46 // string. | 67 // string. |
47 static void create(optional DOMString name, AlarmCreateInfo alarmInfo); | 68 static void create(optional DOMString name, AlarmCreateInfo alarmInfo); |
48 | 69 |
70 | |
Aaron Boodman
2012/06/12 23:02:38
extra line
Jeffrey Yasskin
2012/06/12 23:37:28
Oops, fixed.
| |
49 // Retrieves details about the specified alarm. | 71 // Retrieves details about the specified alarm. |
50 // |name|: The name of the alarm to get. Defaults to the empty string. | 72 // |name|: The name of the alarm to get. Defaults to the empty string. |
51 static void get(optional DOMString name, AlarmCallback callback); | 73 static void get(optional DOMString name, AlarmCallback callback); |
52 | 74 |
53 // Gets an array of all the alarms. | 75 // Gets an array of all the alarms. |
54 static void getAll(AlarmListCallback callback); | 76 static void getAll(AlarmListCallback callback); |
55 | 77 |
56 // Clears the alarm with the given name. | 78 // Clears the alarm with the given name. |
57 // |name|: The name of the alarm to clear. Defaults to the empty string. | 79 // |name|: The name of the alarm to clear. Defaults to the empty string. |
58 static void clear(optional DOMString name); | 80 static void clear(optional DOMString name); |
59 | 81 |
60 // Clears all alarms. | 82 // Clears all alarms. |
61 static void clearAll(); | 83 static void clearAll(); |
62 }; | 84 }; |
63 | 85 |
64 interface Events { | 86 interface Events { |
65 // Fired when an alarm has elapsed. Useful for transient background pages. | 87 // Fired when an alarm has elapsed. Useful for transient background pages. |
66 // |alarm|: The alarm that has elapsed. | 88 // |alarm|: The alarm that has elapsed. |
67 static void onAlarm(Alarm alarm); | 89 static void onAlarm(Alarm alarm); |
68 }; | 90 }; |
69 }; | 91 }; |
OLD | NEW |