notifier_settings.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
16class MessageCenterTrayBridgeTest;
17
18namespace ash {
19class WebNotificationTrayTest;
20}
21
22namespace message_center {
23namespace test {
24class MessagePopupCollectionTest;
25}
26
27class NotifierSettingsDelegate;
28class NotifierSettingsProvider;
29
30// Brings up the settings dialog and returns a weak reference to the delegate,
31// which is typically the view. If the dialog already exists, it is brought to
32// the front, otherwise it is created.
33MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
34    NotifierSettingsProvider* provider,
35    gfx::NativeView context);
36
37// The struct to distinguish the notifiers.
38struct MESSAGE_CENTER_EXPORT NotifierId {
39  enum NotifierType {
40    APPLICATION,
41    WEB_PAGE,
42    SYSTEM_COMPONENT,
43    SYNCED_NOTIFICATION_SERVICE,
44  };
45
46  // Constructor for non WEB_PAGE type.
47  NotifierId(NotifierType type, const std::string& id);
48
49  // Constructor for WEB_PAGE type.
50  explicit NotifierId(const GURL& url);
51
52  bool operator==(const NotifierId& other) const;
53  // Allows NotifierId to be used as a key in std::map.
54  bool operator<(const NotifierId& other) const;
55
56  NotifierType type;
57
58  // The identifier of the app notifier. Empty if it's WEB_PAGE.
59  std::string id;
60
61  // The URL pattern of the notifer.
62  GURL url;
63
64  // The identifier of the profile where the notification is created. This is
65  // used for ChromeOS multi-profile support and can be empty.
66  std::string profile_id;
67
68 private:
69  friend class ::MessageCenterTrayBridgeTest;
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(PopupControllerTest, Creation);
77  FRIEND_TEST_ALL_PREFIXES(NotificationListTest, UnreadCountNoNegative);
78  FRIEND_TEST_ALL_PREFIXES(NotificationListTest, TestHasNotificationOfType);
79
80  // The default constructor which doesn't specify the notifier. Used for tests.
81  NotifierId();
82};
83
84// The struct to hold the information of notifiers. The information will be
85// used by NotifierSettingsView.
86struct MESSAGE_CENTER_EXPORT Notifier {
87  Notifier(const NotifierId& notifier_id,
88           const base::string16& name,
89           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  base::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
108struct MESSAGE_CENTER_EXPORT NotifierGroup {
109  NotifierGroup(const gfx::Image& icon,
110                const base::string16& name,
111                const base::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 base::string16 name;
120
121  // More display information about the notifier group.
122  base::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.
134class 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.
146class 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