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.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "chrome/browser/extensions/app_icon_loader.h"
17 #include "chrome/common/content_settings.h"
18 #include "components/favicon_base/favicon_types.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_source.h"
23 #include "ui/message_center/notifier_settings.h"
25 #if defined(OS_CHROMEOS)
26 #include "components/user_manager/user_manager.h"
30 class ProfileInfoCache
;
33 class CancelableTaskTracker
;
36 namespace favicon_base
{
37 struct FaviconImageResult
;
40 namespace message_center
{
41 class ProfileNotifierGroup
;
44 // The class to bridge between the settings UI of notifiers and the preference
46 class MessageCenterSettingsController
47 : public message_center::NotifierSettingsProvider
,
48 public content::NotificationObserver
,
49 #if defined(OS_CHROMEOS)
50 public user_manager::UserManager::UserSessionStateObserver
,
52 public extensions::AppIconLoader::Delegate
{
54 explicit MessageCenterSettingsController(
55 ProfileInfoCache
* profile_info_cache
);
56 virtual ~MessageCenterSettingsController();
58 // Overridden from message_center::NotifierSettingsProvider.
59 virtual void AddObserver(
60 message_center::NotifierSettingsObserver
* observer
) OVERRIDE
;
61 virtual void RemoveObserver(
62 message_center::NotifierSettingsObserver
* observer
) OVERRIDE
;
63 virtual size_t GetNotifierGroupCount() const OVERRIDE
;
64 virtual const message_center::NotifierGroup
& GetNotifierGroupAt(
65 size_t index
) const OVERRIDE
;
66 virtual bool IsNotifierGroupActiveAt(size_t index
) const OVERRIDE
;
67 virtual void SwitchToNotifierGroup(size_t index
) OVERRIDE
;
68 virtual const message_center::NotifierGroup
& GetActiveNotifierGroup() const
70 virtual void GetNotifierList(
71 std::vector
<message_center::Notifier
*>* notifiers
) OVERRIDE
;
72 virtual void SetNotifierEnabled(const message_center::Notifier
& notifier
,
73 bool enabled
) OVERRIDE
;
74 virtual void OnNotifierSettingsClosing() OVERRIDE
;
75 virtual bool NotifierHasAdvancedSettings(
76 const message_center::NotifierId
& notifier_id
) const OVERRIDE
;
77 virtual void OnNotifierAdvancedSettingsRequested(
78 const message_center::NotifierId
& notifier_id
,
79 const std::string
* notification_id
) OVERRIDE
;
81 #if defined(OS_CHROMEOS)
82 // Overridden from user_manager::UserManager::UserSessionStateObserver.
83 virtual void ActiveUserChanged(
84 const user_manager::User
* active_user
) OVERRIDE
;
87 // Overridden from extensions::AppIconLoader::Delegate.
88 virtual void SetAppImage(const std::string
& id
,
89 const gfx::ImageSkia
& image
) OVERRIDE
;
92 // Overridden from content::NotificationObserver.
93 virtual void Observe(int type
,
94 const content::NotificationSource
& source
,
95 const content::NotificationDetails
& details
) OVERRIDE
;
97 void OnFaviconLoaded(const GURL
& url
,
98 const favicon_base::FaviconImageResult
& favicon_result
);
100 #if defined(OS_CHROMEOS)
101 // Sets up the notifier group for the guest session. This needs to be
102 // separated from RebuildNotifierGroup() and called asynchronously to avoid
103 // the infinite loop of creating profile. See more the comment of
104 // RebuildNotifierGroups().
105 void CreateNotifierGroupForGuestLogin();
108 void RebuildNotifierGroups();
110 // The views displaying notifier settings.
111 ObserverList
<message_center::NotifierSettingsObserver
> observers_
;
113 // The task tracker for loading favicons.
114 scoped_ptr
<base::CancelableTaskTracker
> favicon_tracker_
;
116 scoped_ptr
<extensions::AppIconLoader
> app_icon_loader_
;
118 std::map
<base::string16
, ContentSettingsPattern
> patterns_
;
120 // The list of all configurable notifier groups. This is each profile that is
121 // loaded (and in the ProfileInfoCache - so no incognito profiles go here).
122 ScopedVector
<message_center::ProfileNotifierGroup
> notifier_groups_
;
123 size_t current_notifier_group_
;
125 content::NotificationRegistrar registrar_
;
127 ProfileInfoCache
* profile_info_cache_
;
129 base::WeakPtrFactory
<MessageCenterSettingsController
> weak_factory_
;
131 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController
);
134 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_