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