Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ |
| 6 | #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 13 | #include "base/memory/scoped_vector.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 14 | #include "base/observer_list.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "chrome/browser/extensions/app_icon_loader.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 16 | #include "chrome/common/content_settings.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 17 | #include "content/public/browser/notification_details.h" |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 18 | #include "content/public/browser/notification_observer.h" |
| 19 | #include "content/public/browser/notification_registrar.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 20 | #include "content/public/browser/notification_source.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | #include "ui/message_center/notifier_settings.h" |
| 22 | |
| 23 | class CancelableTaskTracker; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 24 | class ProfileInfoCache; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 26 | namespace chrome { |
| 27 | struct FaviconImageResult; |
| 28 | } |
| 29 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 30 | namespace message_center { |
| 31 | class ProfileNotifierGroup; |
| 32 | } |
| 33 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 34 | // The class to bridge between the settings UI of notifiers and the preference |
| 35 | // storage. |
| 36 | class MessageCenterSettingsController |
| 37 | : public message_center::NotifierSettingsProvider, |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 38 | public content::NotificationObserver, |
| 39 | public extensions::AppIconLoader::Delegate { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 40 | public: |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 41 | explicit MessageCenterSettingsController( |
| 42 | ProfileInfoCache* profile_info_cache); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 43 | virtual ~MessageCenterSettingsController(); |
| 44 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 45 | // Overridden from message_center::NotifierSettingsProvider. |
| 46 | virtual void AddObserver( |
| 47 | message_center::NotifierSettingsObserver* observer) OVERRIDE; |
| 48 | virtual void RemoveObserver( |
| 49 | message_center::NotifierSettingsObserver* observer) OVERRIDE; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 50 | virtual size_t GetNotifierGroupCount() const OVERRIDE; |
| 51 | virtual const message_center::NotifierGroup& GetNotifierGroupAt( |
| 52 | size_t index) const OVERRIDE; |
| 53 | virtual void SwitchToNotifierGroup(size_t index) OVERRIDE; |
| 54 | virtual const message_center::NotifierGroup& GetActiveNotifierGroup() const |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 55 | OVERRIDE; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 56 | virtual void GetNotifierList( |
| 57 | std::vector<message_center::Notifier*>* notifiers) OVERRIDE; |
| 58 | virtual void SetNotifierEnabled(const message_center::Notifier& notifier, |
| 59 | bool enabled) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 60 | virtual void OnNotifierSettingsClosing() OVERRIDE; |
| 61 | |
| 62 | // Overridden from extensions::AppIconLoader::Delegate. |
| 63 | virtual void SetAppImage(const std::string& id, |
| 64 | const gfx::ImageSkia& image) OVERRIDE; |
| 65 | |
| 66 | private: |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 67 | // Overridden from content::NotificationObserver. |
| 68 | virtual void Observe(int type, |
| 69 | const content::NotificationSource& source, |
| 70 | const content::NotificationDetails& details) OVERRIDE; |
| 71 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 72 | void OnFaviconLoaded(const GURL& url, |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 73 | const chrome::FaviconImageResult& favicon_result); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 74 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 75 | void RebuildNotifierGroups(); |
| 76 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 77 | // The views displaying notifier settings. |
| 78 | ObserverList<message_center::NotifierSettingsObserver> observers_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 79 | |
| 80 | // The task tracker for loading favicons. |
| 81 | scoped_ptr<CancelableTaskTracker> favicon_tracker_; |
| 82 | |
| 83 | scoped_ptr<extensions::AppIconLoader> app_icon_loader_; |
| 84 | |
| 85 | std::map<string16, ContentSettingsPattern> patterns_; |
| 86 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 87 | // The list of all configurable notifier groups. This is each profile that is |
| 88 | // loaded (and in the ProfileInfoCache - so no incognito profiles go here). |
| 89 | ScopedVector<message_center::ProfileNotifierGroup> notifier_groups_; |
| 90 | size_t current_notifier_group_; |
| 91 | |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 92 | content::NotificationRegistrar registrar_; |
| 93 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 94 | ProfileInfoCache* profile_info_cache_; |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 95 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 96 | DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController); |
| 97 | }; |
| 98 | |
| 99 | #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ |