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 // been delayed an arbitrary amount beyond this. |
| 16 double scheduledTime; |
| 17 |
| 18 // If not null, the alarm is a repeating alarm and will fire again in |
| 19 // 'periodInMinutes' minutes. |
| 20 double? periodInMinutes; |
| 21 }; |
| 22 |
| 23 // TODO(mpcomplete): rename to OneShotCreateInfo when http://crbug.com/123073 |
| 24 // is fixed. |
| 25 dictionary AlarmOneShotCreateInfo { |
| 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 // Exactly one of time or delayInMinutes must be set. |
| 32 double? time; |
| 33 |
| 34 // Length of time in minutes after which the onAlarm event should fire. |
| 35 // Note that granularity is not guaranteed: this value is more of a hint to |
| 36 // the browser. For performance reasons, alarms may be delayed an arbitrary |
| 37 // amount of time before firing. |
| 38 // |
| 39 // Exactly one of time or delayInMinutes must be set. |
| 40 // |
15 // TODO: need minimum=0 | 41 // TODO: need minimum=0 |
16 double delayInMinutes; | 42 double? delayInMinutes; |
17 | |
18 // True if the alarm repeatedly fires at regular intervals, false if it | |
19 // only fires once. | |
20 boolean repeating; | |
21 }; | 43 }; |
22 | 44 |
23 // TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is | 45 // TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is |
24 // fixed. | 46 // fixed. |
25 dictionary AlarmCreateInfo { | 47 dictionary AlarmRepeatingCreateInfo { |
26 // Length of time in minutes after which the onAlarm event should fire. | 48 // Length of time in minutes between times the onAlarm event should fire, |
27 // Note that granularity is not guaranteed: this value is more of a hint to | 49 // and the delay before the first time it fires. Note that granularity is |
28 // the browser. For performance reasons, alarms may be delayed an arbitrary | 50 // not guaranteed: this value is more of a hint to the browser. For |
29 // amount of time before firing. | 51 // performance reasons, alarms may be delayed an arbitrary amount of time |
| 52 // before firing. |
| 53 // |
30 // TODO: need minimum=0 | 54 // TODO: need minimum=0 |
31 double delayInMinutes; | 55 double periodInMinutes; |
32 | |
33 // True if the alarm should repeatedly fire at regular intervals. Defaults | |
34 // to false. | |
35 boolean? repeating; | |
36 }; | 56 }; |
37 | 57 |
38 callback AlarmCallback = void (Alarm alarm); | 58 callback AlarmCallback = void (Alarm alarm); |
39 callback AlarmListCallback = void (Alarm[] alarms); | 59 callback AlarmListCallback = void (Alarm[] alarms); |
40 | 60 |
41 interface Functions { | 61 interface Functions { |
42 // Creates an alarm. After the delay is elapsed, the onAlarm event is | 62 // Creates an alarm that will fire once. Near the time specified by |
43 // fired. If there is another alarm with the same name (or no name if none | 63 // 'alarmInfo', the onAlarm event is fired. If there is another alarm |
44 // is specified), it will be cancelled and replaced by this alarm. | 64 // (either one-shot or repeating) with the same name (or no name if none is |
45 // |name|: Optional name to identify this alarm. Defaults to the empty | 65 // specified), it will be cancelled and replaced by this alarm. |name|: |
46 // string. | 66 // Optional name to identify this alarm. Defaults to the empty string. |
47 static void create(optional DOMString name, AlarmCreateInfo alarmInfo); | 67 static void createOneShot(optional DOMString name, |
| 68 AlarmOneShotCreateInfo alarmInfo); |
| 69 |
| 70 // Creates an alarm that will fire repeatedly. The onAlarm event is fired |
| 71 // with a period specified by 'alarmInfo'. If there is another alarm (either |
| 72 // one-shot or repeating) with the same name (or no name if none is |
| 73 // specified), it will be cancelled and replaced by this alarm. |name|: |
| 74 // Optional name to identify this alarm. Defaults to the empty string. |
| 75 static void createRepeating(optional DOMString name, |
| 76 AlarmRepeatingCreateInfo alarmInfo); |
48 | 77 |
49 // Retrieves details about the specified alarm. | 78 // Retrieves details about the specified alarm. |
50 // |name|: The name of the alarm to get. Defaults to the empty string. | 79 // |name|: The name of the alarm to get. Defaults to the empty string. |
51 static void get(optional DOMString name, AlarmCallback callback); | 80 static void get(optional DOMString name, AlarmCallback callback); |
52 | 81 |
53 // Gets an array of all the alarms. | 82 // Gets an array of all the alarms. |
54 static void getAll(AlarmListCallback callback); | 83 static void getAll(AlarmListCallback callback); |
55 | 84 |
56 // Clears the alarm with the given name. | 85 // Clears the alarm with the given name. |
57 // |name|: The name of the alarm to clear. Defaults to the empty string. | 86 // |name|: The name of the alarm to clear. Defaults to the empty string. |
58 static void clear(optional DOMString name); | 87 static void clear(optional DOMString name); |
59 | 88 |
60 // Clears all alarms. | 89 // Clears all alarms. |
61 static void clearAll(); | 90 static void clearAll(); |
62 }; | 91 }; |
63 | 92 |
64 interface Events { | 93 interface Events { |
65 // Fired when an alarm has elapsed. Useful for transient background pages. | 94 // Fired when an alarm has elapsed. Useful for transient background pages. |
66 // |alarm|: The alarm that has elapsed. | 95 // |alarm|: The alarm that has elapsed. |
67 static void onAlarm(Alarm alarm); | 96 static void onAlarm(Alarm alarm); |
68 }; | 97 }; |
69 }; | 98 }; |
OLD | NEW |