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