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