notifier_settings.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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/strings/string16.h" 11#include "ui/gfx/image/image.h" 12#include "ui/message_center/message_center_export.h" 13#include "url/gurl.h" 14 15namespace message_center { 16 17class NotifierSettingsDelegate; 18class NotifierSettingsProvider; 19 20// Brings up the settings dialog and returns a weak reference to the delegate, 21// which is typically the view. If the dialog already exists, it is brought to 22// the front, otherwise it is created. 23MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings( 24 NotifierSettingsProvider* provider, 25 gfx::NativeView context); 26 27// The struct to distinguish the notifiers. 28struct MESSAGE_CENTER_EXPORT NotifierId { 29 enum NotifierType { 30 APPLICATION, 31 WEB_PAGE, 32 SYSTEM_COMPONENT, 33 SYNCED_NOTIFICATION_SERVICE, 34 }; 35 36 enum SystemComponentNotifierType { 37 NONE, 38 SCREENSHOT, 39 }; 40 41 // Constructor for APPLICATION and SYNCED_NOTIFICATION_SERVICE type. 42 NotifierId(NotifierType type, const std::string& id); 43 44 // Constructor for WEB_PAGE type. 45 explicit NotifierId(const GURL& url); 46 47 // Constructor for SYSTEM_COMPONENT type. 48 explicit NotifierId(SystemComponentNotifierType type); 49 50 bool operator==(const NotifierId& other) const; 51 52 NotifierType type; 53 54 // The identifier of the app notifier. Empty if it's not APPLICATION or 55 // SYNCED_NOTIFICATION_SERVICE. 56 std::string id; 57 58 // The URL pattern of the notifer. 59 GURL url; 60 61 // The type of system component notifier. 62 SystemComponentNotifierType system_component_type; 63}; 64 65// The struct to hold the information of notifiers. The information will be 66// used by NotifierSettingsView. 67struct MESSAGE_CENTER_EXPORT Notifier { 68 Notifier(const NotifierId& notifier_id, const string16& name, bool enabled); 69 ~Notifier(); 70 71 NotifierId notifier_id; 72 73 // The human-readable name of the notifier such like the extension name. 74 // It can be empty. 75 string16 name; 76 77 // True if the source is allowed to send notifications. True is default. 78 bool enabled; 79 80 // The icon image of the notifier. The extension icon or favicon. 81 gfx::Image icon; 82 83 private: 84 DISALLOW_COPY_AND_ASSIGN(Notifier); 85}; 86 87MESSAGE_CENTER_EXPORT std::string ToString( 88 NotifierId::SystemComponentNotifierType type); 89MESSAGE_CENTER_EXPORT NotifierId::SystemComponentNotifierType 90 ParseSystemComponentName(const std::string& name); 91 92// An observer class implemented by the view of the NotifierSettings to get 93// notified when the controller has changed data. 94class MESSAGE_CENTER_EXPORT NotifierSettingsObserver { 95 public: 96 // Called when an icon in the controller has been updated. 97 virtual void UpdateIconImage(const NotifierId& notifier_id, 98 const gfx::Image& icon) = 0; 99}; 100 101// A class used by NotifierSettingsView to integrate with a setting system 102// for the clients of this module. 103class MESSAGE_CENTER_EXPORT NotifierSettingsProvider { 104 public: 105 // Sets the delegate. 106 virtual void AddObserver(NotifierSettingsObserver* observer) = 0; 107 virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0; 108 109 // Collects the current notifier list and fills to |notifiers|. Caller takes 110 // the ownership of the elements of |notifiers|. 111 virtual void GetNotifierList(std::vector<Notifier*>* notifiers) = 0; 112 113 // Called when the |enabled| for the |notifier| has been changed by user 114 // operation. 115 virtual void SetNotifierEnabled(const Notifier& notifier, bool enabled) = 0; 116 117 // Called when the settings window is closed. 118 virtual void OnNotifierSettingsClosing() = 0; 119}; 120 121} // namespace message_center 122 123#endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_ 124