notifications_api.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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_NOTIFICATIONS_NOTIFICATIONS_API_H_
6#define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_
7
8#include <string>
9
10#include "base/memory/ref_counted.h"
11#include "chrome/browser/extensions/api/api_function.h"
12#include "chrome/browser/extensions/extension_function.h"
13#include "chrome/common/extensions/api/notifications.h"
14#include "ui/message_center/notification_types.h"
15
16namespace extensions {
17
18class NotificationsApiFunction : public ApiFunction {
19 public:
20  // Whether the current extension and channel allow the API. Public for
21  // testing.
22  bool IsNotificationsApiAvailable();
23
24 protected:
25  NotificationsApiFunction();
26  virtual ~NotificationsApiFunction();
27
28  bool CreateNotification(const std::string& id,
29                          api::notifications::NotificationOptions* options);
30
31  bool IsNotificationsApiEnabled();
32
33  // Called inside of RunImpl.
34  virtual bool RunNotificationsApi() = 0;
35
36  // UITHreadExtensionFunction:
37  virtual bool RunImpl() OVERRIDE;
38
39  message_center::NotificationType MapApiTemplateTypeToType(
40      api::notifications::TemplateType type);
41};
42
43class NotificationsCreateFunction : public NotificationsApiFunction {
44 public:
45  NotificationsCreateFunction();
46
47  // UIThreadExtensionFunction:
48  virtual bool RunNotificationsApi() OVERRIDE;
49
50 protected:
51  virtual ~NotificationsCreateFunction();
52
53 private:
54  scoped_ptr<api::notifications::Create::Params> params_;
55
56  DECLARE_EXTENSION_FUNCTION("notifications.create", NOTIFICATIONS_CREATE)
57};
58
59class NotificationsUpdateFunction : public NotificationsApiFunction {
60 public:
61  NotificationsUpdateFunction();
62
63  // UIThreadExtensionFunction:
64  virtual bool RunNotificationsApi() OVERRIDE;
65
66 protected:
67  virtual ~NotificationsUpdateFunction();
68
69 private:
70  scoped_ptr<api::notifications::Update::Params> params_;
71
72  DECLARE_EXTENSION_FUNCTION("notifications.update", NOTIFICATIONS_UPDATE)
73};
74
75class NotificationsClearFunction : public NotificationsApiFunction {
76 public:
77  NotificationsClearFunction();
78
79  // UIThreadExtensionFunction:
80  virtual bool RunNotificationsApi() OVERRIDE;
81
82 protected:
83  virtual ~NotificationsClearFunction();
84
85 private:
86  scoped_ptr<api::notifications::Clear::Params> params_;
87
88  DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR)
89};
90
91class NotificationsGetAllFunction : public NotificationsApiFunction {
92 public:
93  NotificationsGetAllFunction();
94
95  // UIThreadExtensionFunction:
96  virtual bool RunNotificationsApi() OVERRIDE;
97
98 protected:
99  virtual ~NotificationsGetAllFunction();
100
101 private:
102  DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL)
103};
104
105}  // namespace extensions
106
107#endif  // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_
108