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 #if defined(OS_CHROMEOS)
     24 #include "chrome/browser/chromeos/login/user_manager.h"
     25 #endif
     26 
     27 class CancelableTaskTracker;
     28 class Profile;
     29 class ProfileInfoCache;
     30 
     31 namespace chrome {
     32 struct FaviconImageResult;
     33 }
     34 
     35 namespace message_center {
     36 class ProfileNotifierGroup;
     37 }
     38 
     39 // The class to bridge between the settings UI of notifiers and the preference
     40 // storage.
     41 class MessageCenterSettingsController
     42     : public message_center::NotifierSettingsProvider,
     43       public content::NotificationObserver,
     44 #if defined(OS_CHROMEOS)
     45       public chromeos::UserManager::UserSessionStateObserver,
     46 #endif
     47       public extensions::AppIconLoader::Delegate {
     48  public:
     49   explicit MessageCenterSettingsController(
     50       ProfileInfoCache* profile_info_cache);
     51   virtual ~MessageCenterSettingsController();
     52 
     53   // Overridden from message_center::NotifierSettingsProvider.
     54   virtual void AddObserver(
     55       message_center::NotifierSettingsObserver* observer) OVERRIDE;
     56   virtual void RemoveObserver(
     57       message_center::NotifierSettingsObserver* observer) OVERRIDE;
     58   virtual size_t GetNotifierGroupCount() const OVERRIDE;
     59   virtual const message_center::NotifierGroup& GetNotifierGroupAt(
     60       size_t index) const OVERRIDE;
     61   virtual bool IsNotifierGroupActiveAt(size_t index) const OVERRIDE;
     62   virtual void SwitchToNotifierGroup(size_t index) OVERRIDE;
     63   virtual const message_center::NotifierGroup& GetActiveNotifierGroup() const
     64       OVERRIDE;
     65   virtual void GetNotifierList(
     66       std::vector<message_center::Notifier*>* notifiers) OVERRIDE;
     67   virtual void SetNotifierEnabled(const message_center::Notifier& notifier,
     68                                   bool enabled) OVERRIDE;
     69   virtual void OnNotifierSettingsClosing() OVERRIDE;
     70   virtual bool NotifierHasAdvancedSettings(
     71       const message_center::NotifierId& notifier_id) const OVERRIDE;
     72   virtual void OnNotifierAdvancedSettingsRequested(
     73       const message_center::NotifierId& notifier_id,
     74       const std::string* notification_id) OVERRIDE;
     75 
     76 #if defined(OS_CHROMEOS)
     77   // Overridden from chromeos::UserManager::UserSessionStateObserver.
     78   virtual void ActiveUserChanged(const chromeos::User* active_user) OVERRIDE;
     79 #endif
     80 
     81   // Overridden from extensions::AppIconLoader::Delegate.
     82   virtual void SetAppImage(const std::string& id,
     83                            const gfx::ImageSkia& image) OVERRIDE;
     84 
     85  private:
     86   // Overridden from content::NotificationObserver.
     87   virtual void Observe(int type,
     88                        const content::NotificationSource& source,
     89                        const content::NotificationDetails& details) OVERRIDE;
     90 
     91   void OnFaviconLoaded(const GURL& url,
     92                        const chrome::FaviconImageResult& favicon_result);
     93 
     94   Profile* GetCurrentProfile() const;
     95 
     96   void RebuildNotifierGroups();
     97 
     98   // The views displaying notifier settings.
     99   ObserverList<message_center::NotifierSettingsObserver> observers_;
    100 
    101   // The task tracker for loading favicons.
    102   scoped_ptr<CancelableTaskTracker> favicon_tracker_;
    103 
    104   scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
    105 
    106   std::map<base::string16, ContentSettingsPattern> patterns_;
    107 
    108   // The list of all configurable notifier groups. This is each profile that is
    109   // loaded (and in the ProfileInfoCache - so no incognito profiles go here).
    110   ScopedVector<message_center::ProfileNotifierGroup> notifier_groups_;
    111   size_t current_notifier_group_;
    112 
    113   content::NotificationRegistrar registrar_;
    114 
    115   ProfileInfoCache* profile_info_cache_;
    116 
    117   DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController);
    118 };
    119 
    120 #endif  // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
    121