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 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ |
6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class Clock; | 13 class Clock; |
14 } // namespace base | 14 } // namespace base |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 struct Alarm; | 17 struct Alarm; |
18 typedef std::vector<Alarm> AlarmList; | 18 typedef std::vector<Alarm> AlarmList; |
19 | 19 |
20 class AlarmsCreateFunction : public ChromeAsyncExtensionFunction { | 20 class AlarmsCreateFunction : public ChromeAsyncExtensionFunction { |
21 public: | 21 public: |
22 AlarmsCreateFunction(); | 22 AlarmsCreateFunction(); |
23 // Use |clock| instead of the default clock. Does not take ownership | 23 // Use |clock| instead of the default clock. Does not take ownership |
24 // of |clock|. Used for testing. | 24 // of |clock|. Used for testing. |
25 explicit AlarmsCreateFunction(base::Clock* clock); | 25 explicit AlarmsCreateFunction(base::Clock* clock); |
26 protected: | 26 protected: |
27 virtual ~AlarmsCreateFunction(); | 27 virtual ~AlarmsCreateFunction(); |
28 | 28 |
29 // ExtensionFunction: | 29 // ExtensionFunction: |
30 virtual bool RunImpl() OVERRIDE; | 30 virtual bool RunAsync() OVERRIDE; |
31 DECLARE_EXTENSION_FUNCTION("alarms.create", ALARMS_CREATE) | 31 DECLARE_EXTENSION_FUNCTION("alarms.create", ALARMS_CREATE) |
32 private: | 32 private: |
33 void Callback(); | 33 void Callback(); |
34 | 34 |
35 base::Clock* const clock_; | 35 base::Clock* const clock_; |
36 // Whether or not we own |clock_|. This is needed because we own it | 36 // Whether or not we own |clock_|. This is needed because we own it |
37 // when we create it ourselves, but not when it's passed in for | 37 // when we create it ourselves, but not when it's passed in for |
38 // testing. | 38 // testing. |
39 bool owns_clock_; | 39 bool owns_clock_; |
40 }; | 40 }; |
41 | 41 |
42 class AlarmsGetFunction : public ChromeAsyncExtensionFunction { | 42 class AlarmsGetFunction : public ChromeAsyncExtensionFunction { |
43 protected: | 43 protected: |
44 virtual ~AlarmsGetFunction() {} | 44 virtual ~AlarmsGetFunction() {} |
45 | 45 |
46 // ExtensionFunction: | 46 // ExtensionFunction: |
47 virtual bool RunImpl() OVERRIDE; | 47 virtual bool RunAsync() OVERRIDE; |
48 | 48 |
49 private: | 49 private: |
50 void Callback(const std::string& name, Alarm* alarm); | 50 void Callback(const std::string& name, Alarm* alarm); |
51 DECLARE_EXTENSION_FUNCTION("alarms.get", ALARMS_GET) | 51 DECLARE_EXTENSION_FUNCTION("alarms.get", ALARMS_GET) |
52 }; | 52 }; |
53 | 53 |
54 class AlarmsGetAllFunction : public ChromeAsyncExtensionFunction { | 54 class AlarmsGetAllFunction : public ChromeAsyncExtensionFunction { |
55 protected: | 55 protected: |
56 virtual ~AlarmsGetAllFunction() {} | 56 virtual ~AlarmsGetAllFunction() {} |
57 | 57 |
58 // ExtensionFunction: | 58 // ExtensionFunction: |
59 virtual bool RunImpl() OVERRIDE; | 59 virtual bool RunAsync() OVERRIDE; |
| 60 |
60 private: | 61 private: |
61 void Callback(const AlarmList* alarms); | 62 void Callback(const AlarmList* alarms); |
62 DECLARE_EXTENSION_FUNCTION("alarms.getAll", ALARMS_GETALL) | 63 DECLARE_EXTENSION_FUNCTION("alarms.getAll", ALARMS_GETALL) |
63 }; | 64 }; |
64 | 65 |
65 class AlarmsClearFunction : public ChromeAsyncExtensionFunction { | 66 class AlarmsClearFunction : public ChromeAsyncExtensionFunction { |
66 protected: | 67 protected: |
67 virtual ~AlarmsClearFunction() {} | 68 virtual ~AlarmsClearFunction() {} |
68 | 69 |
69 // ExtensionFunction: | 70 // ExtensionFunction: |
70 virtual bool RunImpl() OVERRIDE; | 71 virtual bool RunAsync() OVERRIDE; |
| 72 |
71 private: | 73 private: |
72 void Callback(const std::string& name, bool success); | 74 void Callback(const std::string& name, bool success); |
73 DECLARE_EXTENSION_FUNCTION("alarms.clear", ALARMS_CLEAR) | 75 DECLARE_EXTENSION_FUNCTION("alarms.clear", ALARMS_CLEAR) |
74 }; | 76 }; |
75 | 77 |
76 class AlarmsClearAllFunction : public ChromeAsyncExtensionFunction { | 78 class AlarmsClearAllFunction : public ChromeAsyncExtensionFunction { |
77 protected: | 79 protected: |
78 virtual ~AlarmsClearAllFunction() {} | 80 virtual ~AlarmsClearAllFunction() {} |
79 | 81 |
80 // ExtensionFunction: | 82 // ExtensionFunction: |
81 virtual bool RunImpl() OVERRIDE; | 83 virtual bool RunAsync() OVERRIDE; |
| 84 |
82 private: | 85 private: |
83 void Callback(); | 86 void Callback(); |
84 DECLARE_EXTENSION_FUNCTION("alarms.clearAll", ALARMS_CLEARALL) | 87 DECLARE_EXTENSION_FUNCTION("alarms.clearAll", ALARMS_CLEARALL) |
85 }; | 88 }; |
86 | 89 |
87 } // namespace extensions | 90 } // namespace extensions |
88 | 91 |
89 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ | 92 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ |
OLD | NEW |