Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / browser / notifications / message_center_settings_controller.h
blob78346ae926df81aaae3535e9dd8cfff6f8fa5eb0
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_
8 #include <map>
9 #include <vector>
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 "components/content_settings/core/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"
27 #endif
29 class Profile;
30 class ProfileInfoCache;
32 namespace base {
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
45 // storage.
46 class MessageCenterSettingsController
47 : public message_center::NotifierSettingsProvider,
48 public content::NotificationObserver,
49 #if defined(OS_CHROMEOS)
50 public user_manager::UserManager::UserSessionStateObserver,
51 #endif
52 public extensions::AppIconLoader::Delegate {
53 public:
54 explicit MessageCenterSettingsController(
55 ProfileInfoCache* profile_info_cache);
56 ~MessageCenterSettingsController() override;
58 // Overridden from message_center::NotifierSettingsProvider.
59 void AddObserver(message_center::NotifierSettingsObserver* observer) override;
60 void RemoveObserver(
61 message_center::NotifierSettingsObserver* observer) override;
62 size_t GetNotifierGroupCount() const override;
63 const message_center::NotifierGroup& GetNotifierGroupAt(
64 size_t index) const override;
65 bool IsNotifierGroupActiveAt(size_t index) const override;
66 void SwitchToNotifierGroup(size_t index) override;
67 const message_center::NotifierGroup& GetActiveNotifierGroup() const override;
68 void GetNotifierList(
69 std::vector<message_center::Notifier*>* notifiers) override;
70 void SetNotifierEnabled(const message_center::Notifier& notifier,
71 bool enabled) override;
72 void OnNotifierSettingsClosing() override;
73 bool NotifierHasAdvancedSettings(
74 const message_center::NotifierId& notifier_id) const override;
75 void OnNotifierAdvancedSettingsRequested(
76 const message_center::NotifierId& notifier_id,
77 const std::string* notification_id) override;
79 #if defined(OS_CHROMEOS)
80 // Overridden from user_manager::UserManager::UserSessionStateObserver.
81 virtual void ActiveUserChanged(
82 const user_manager::User* active_user) override;
83 #endif
85 // Overridden from extensions::AppIconLoader::Delegate.
86 void SetAppImage(const std::string& id, const gfx::ImageSkia& image) override;
88 private:
89 // Overridden from content::NotificationObserver.
90 void Observe(int type,
91 const content::NotificationSource& source,
92 const content::NotificationDetails& details) override;
94 void OnFaviconLoaded(const GURL& url,
95 const favicon_base::FaviconImageResult& favicon_result);
97 #if defined(OS_CHROMEOS)
98 // Sets up the notifier group for the guest session. This needs to be
99 // separated from RebuildNotifierGroup() and called asynchronously to avoid
100 // the infinite loop of creating profile. See more the comment of
101 // RebuildNotifierGroups().
102 void CreateNotifierGroupForGuestLogin();
103 #endif
105 void RebuildNotifierGroups();
107 // The views displaying notifier settings.
108 ObserverList<message_center::NotifierSettingsObserver> observers_;
110 // The task tracker for loading favicons.
111 scoped_ptr<base::CancelableTaskTracker> favicon_tracker_;
113 scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
115 std::map<base::string16, ContentSettingsPattern> patterns_;
117 // The list of all configurable notifier groups. This is each profile that is
118 // loaded (and in the ProfileInfoCache - so no incognito profiles go here).
119 ScopedVector<message_center::ProfileNotifierGroup> notifier_groups_;
120 size_t current_notifier_group_;
122 content::NotificationRegistrar registrar_;
124 ProfileInfoCache* profile_info_cache_;
126 base::WeakPtrFactory<MessageCenterSettingsController> weak_factory_;
128 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController);
131 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_