Home | History | Annotate | Download | only in message_center
      1 // Copyright (c) 2013 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 UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
      6 #define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/gtest_prod_util.h"
     11 #include "base/strings/string16.h"
     12 #include "ui/gfx/image/image.h"
     13 #include "ui/message_center/message_center_export.h"
     14 #include "url/gurl.h"
     15 
     16 FORWARD_DECLARE_TEST(MessageCenterTrayBridgeTest,
     17                      StatusItemOnlyAfterFirstNotification);
     18 
     19 namespace ash {
     20 class WebNotificationTrayTest;
     21 }
     22 
     23 namespace message_center {
     24 namespace test {
     25 class MessagePopupCollectionTest;
     26 }
     27 
     28 class NotifierSettingsDelegate;
     29 class NotifierSettingsProvider;
     30 
     31 // Brings up the settings dialog and returns a weak reference to the delegate,
     32 // which is typically the view. If the dialog already exists, it is brought to
     33 // the front, otherwise it is created.
     34 MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
     35     NotifierSettingsProvider* provider,
     36     gfx::NativeView context);
     37 
     38 // The struct to distinguish the notifiers.
     39 struct MESSAGE_CENTER_EXPORT NotifierId {
     40   enum NotifierType {
     41     APPLICATION,
     42     WEB_PAGE,
     43     SYSTEM_COMPONENT,
     44     SYNCED_NOTIFICATION_SERVICE,
     45   };
     46 
     47   // Constructor for non WEB_PAGE type.
     48   NotifierId(NotifierType type, const std::string& id);
     49 
     50   // Constructor for WEB_PAGE type.
     51   explicit NotifierId(const GURL& url);
     52 
     53   bool operator==(const NotifierId& other) const;
     54   // Allows NotifierId to be used as a key in std::map.
     55   bool operator<(const NotifierId& other) const;
     56 
     57   NotifierType type;
     58 
     59   // The identifier of the app notifier. Empty if it's WEB_PAGE.
     60   std::string id;
     61 
     62   // The URL pattern of the notifer.
     63   GURL url;
     64 
     65   // The identifier of the profile where the notification is created. This is
     66   // used for ChromeOS multi-profile support and can be empty.
     67   std::string profile_id;
     68 
     69  private:
     70   friend class MessageCenterTrayTest;
     71   friend class test::MessagePopupCollectionTest;
     72   friend class NotificationControllerTest;
     73   friend class PopupCollectionTest;
     74   friend class TrayViewControllerTest;
     75   friend class ash::WebNotificationTrayTest;
     76   FRIEND_TEST_ALL_PREFIXES(::MessageCenterTrayBridgeTest,
     77                            StatusItemOnlyAfterFirstNotification);
     78   FRIEND_TEST_ALL_PREFIXES(PopupControllerTest, Creation);
     79   FRIEND_TEST_ALL_PREFIXES(NotificationListTest, UnreadCountNoNegative);
     80   FRIEND_TEST_ALL_PREFIXES(NotificationListTest, TestHasNotificationOfType);
     81 
     82   // The default constructor which doesn't specify the notifier. Used for tests.
     83   NotifierId();
     84 };
     85 
     86 // The struct to hold the information of notifiers. The information will be
     87 // used by NotifierSettingsView.
     88 struct MESSAGE_CENTER_EXPORT Notifier {
     89   Notifier(const NotifierId& notifier_id, const string16& name, bool enabled);
     90   ~Notifier();
     91 
     92   NotifierId notifier_id;
     93 
     94   // The human-readable name of the notifier such like the extension name.
     95   // It can be empty.
     96   string16 name;
     97 
     98   // True if the source is allowed to send notifications. True is default.
     99   bool enabled;
    100 
    101   // The icon image of the notifier. The extension icon or favicon.
    102   gfx::Image icon;
    103 
    104  private:
    105   DISALLOW_COPY_AND_ASSIGN(Notifier);
    106 };
    107 
    108 struct MESSAGE_CENTER_EXPORT NotifierGroup {
    109   NotifierGroup(const gfx::Image& icon,
    110                 const string16& name,
    111                 const string16& login_info,
    112                 size_t index);
    113   ~NotifierGroup();
    114 
    115   // Icon of a notifier group.
    116   const gfx::Image icon;
    117 
    118   // Display name of a notifier group.
    119   const string16 name;
    120 
    121   // More display information about the notifier group.
    122   string16 login_info;
    123 
    124   // Unique identifier for the notifier group so that they can be selected in
    125   // the UI.
    126   const size_t index;
    127 
    128  private:
    129   DISALLOW_COPY_AND_ASSIGN(NotifierGroup);
    130 };
    131 
    132 // An observer class implemented by the view of the NotifierSettings to get
    133 // notified when the controller has changed data.
    134 class MESSAGE_CENTER_EXPORT NotifierSettingsObserver {
    135  public:
    136   // Called when an icon in the controller has been updated.
    137   virtual void UpdateIconImage(const NotifierId& notifier_id,
    138                                const gfx::Image& icon) = 0;
    139 
    140   // Called when any change happens to the set of notifier groups.
    141   virtual void NotifierGroupChanged() = 0;
    142 };
    143 
    144 // A class used by NotifierSettingsView to integrate with a setting system
    145 // for the clients of this module.
    146 class MESSAGE_CENTER_EXPORT NotifierSettingsProvider {
    147  public:
    148   virtual ~NotifierSettingsProvider() {};
    149 
    150   // Sets the delegate.
    151   virtual void AddObserver(NotifierSettingsObserver* observer) = 0;
    152   virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0;
    153 
    154   // Returns the number of notifier groups available.
    155   virtual size_t GetNotifierGroupCount() const = 0;
    156 
    157   // Requests the model for a particular notifier group.
    158   virtual const message_center::NotifierGroup& GetNotifierGroupAt(
    159       size_t index) const = 0;
    160 
    161   // Returns true if the notifier group at |index| is active.
    162   virtual bool IsNotifierGroupActiveAt(size_t index) const = 0;
    163 
    164   // Informs the settings provider that further requests to GetNotifierList
    165   // should return notifiers for the specified notifier group.
    166   virtual void SwitchToNotifierGroup(size_t index) = 0;
    167 
    168   // Requests the currently active notifier group.
    169   virtual const message_center::NotifierGroup& GetActiveNotifierGroup()
    170       const = 0;
    171 
    172   // Collects the current notifier list and fills to |notifiers|. Caller takes
    173   // the ownership of the elements of |notifiers|.
    174   virtual void GetNotifierList(std::vector<Notifier*>* notifiers) = 0;
    175 
    176   // Called when the |enabled| for the |notifier| has been changed by user
    177   // operation.
    178   virtual void SetNotifierEnabled(const Notifier& notifier, bool enabled) = 0;
    179 
    180   // Called when the settings window is closed.
    181   virtual void OnNotifierSettingsClosing() = 0;
    182 
    183   // Called to determine if a particular notifier can respond to a request for
    184   // more information.
    185   virtual bool NotifierHasAdvancedSettings(const NotifierId& notifier_id)
    186       const = 0;
    187 
    188   // Called upon request for more information about a particular notifier.
    189   virtual void OnNotifierAdvancedSettingsRequested(
    190       const NotifierId& notifier_id,
    191       const std::string* notification_id) = 0;
    192 };
    193 
    194 }  // namespace message_center
    195 
    196 #endif  // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
    197