Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: chrome/browser/notifications/message_center_settings_controller.h

Issue 2064363002: Refactor MessageCenterSettingsController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix misspell. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/notifications/notifier_source.h"
18 #include "chrome/browser/profiles/profile_attributes_storage.h" 19 #include "chrome/browser/profiles/profile_attributes_storage.h"
19 #include "chrome/browser/ui/app_icon_loader.h" 20 #include "chrome/browser/ui/app_icon_loader.h"
20 #include "components/content_settings/core/common/content_settings.h" 21 #include "components/content_settings/core/common/content_settings.h"
21 #include "components/favicon_base/favicon_types.h" 22 #include "components/favicon_base/favicon_types.h"
22 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
26 #include "ui/message_center/notifier_settings.h" 27 #include "ui/message_center/notifier_settings.h"
27 28
28 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
29 #include "components/user_manager/user_manager.h" 30 #include "components/user_manager/user_manager.h"
30 #endif 31 #endif
31 32
32 class Profile; 33 class Profile;
33 34 class NotifierSource;
34 #if defined(OS_CHROMEOS)
35 namespace arc {
36 class ArcNotifierManager;
37 }
38 #endif
39 35
40 namespace base { 36 namespace base {
41 class CancelableTaskTracker; 37 class CancelableTaskTracker;
42 } 38 }
43 39
44 namespace favicon_base { 40 namespace favicon_base {
45 struct FaviconImageResult; 41 struct FaviconImageResult;
46 } 42 }
47 43
48 namespace message_center { 44 namespace message_center {
49 class ProfileNotifierGroup; 45 class ProfileNotifierGroup;
50 } 46 }
51 47
52 // The class to bridge between the settings UI of notifiers and the preference 48 // The class to bridge between the settings UI of notifiers and the preference
53 // storage. 49 // storage.
54 class MessageCenterSettingsController 50 class MessageCenterSettingsController
55 : public message_center::NotifierSettingsProvider, 51 : public message_center::NotifierSettingsProvider,
56 public content::NotificationObserver, 52 public content::NotificationObserver,
57 public ProfileAttributesStorage::Observer, 53 public ProfileAttributesStorage::Observer,
58 #if defined(OS_CHROMEOS) 54 #if defined(OS_CHROMEOS)
59 public user_manager::UserManager::UserSessionStateObserver, 55 public user_manager::UserManager::UserSessionStateObserver,
60 #endif 56 #endif
61 public AppIconLoaderDelegate { 57 public NotifierSource::Observer {
62 public: 58 public:
63 explicit MessageCenterSettingsController( 59 explicit MessageCenterSettingsController(
64 ProfileAttributesStorage& profile_attributes_storage); 60 ProfileAttributesStorage& profile_attributes_storage);
65 ~MessageCenterSettingsController() override; 61 ~MessageCenterSettingsController() override;
66 62
67 // Overridden from message_center::NotifierSettingsProvider. 63 // Overridden from message_center::NotifierSettingsProvider.
68 void AddObserver(message_center::NotifierSettingsObserver* observer) override; 64 void AddObserver(message_center::NotifierSettingsObserver* observer) override;
69 void RemoveObserver( 65 void RemoveObserver(
70 message_center::NotifierSettingsObserver* observer) override; 66 message_center::NotifierSettingsObserver* observer) override;
71 size_t GetNotifierGroupCount() const override; 67 size_t GetNotifierGroupCount() const override;
(...skipping 11 matching lines...) Expand all
83 const message_center::NotifierId& notifier_id) const override; 79 const message_center::NotifierId& notifier_id) const override;
84 void OnNotifierAdvancedSettingsRequested( 80 void OnNotifierAdvancedSettingsRequested(
85 const message_center::NotifierId& notifier_id, 81 const message_center::NotifierId& notifier_id,
86 const std::string* notification_id) override; 82 const std::string* notification_id) override;
87 83
88 #if defined(OS_CHROMEOS) 84 #if defined(OS_CHROMEOS)
89 // Overridden from user_manager::UserManager::UserSessionStateObserver. 85 // Overridden from user_manager::UserManager::UserSessionStateObserver.
90 void ActiveUserChanged(const user_manager::User* active_user) override; 86 void ActiveUserChanged(const user_manager::User* active_user) override;
91 #endif 87 #endif
92 88
93 // Overridden from AppIconLoaderDelegate.
94 void OnAppImageUpdated(const std::string& id,
95 const gfx::ImageSkia& image) override;
96
97 private: 89 private:
98 // Overridden from content::NotificationObserver. 90 // Overridden from content::NotificationObserver.
99 void Observe(int type, 91 void Observe(int type,
100 const content::NotificationSource& source, 92 const content::NotificationSource& source,
101 const content::NotificationDetails& details) override; 93 const content::NotificationDetails& details) override;
102 94
103 // ProfileAttributesStorage::Observer: 95 // Overridden from ProfileAttributesStorage::Observer.
104 void OnProfileAdded(const base::FilePath& profile_path) override; 96 void OnProfileAdded(const base::FilePath& profile_path) override;
105 void OnProfileWasRemoved(const base::FilePath& profile_path, 97 void OnProfileWasRemoved(const base::FilePath& profile_path,
106 const base::string16& profile_name) override; 98 const base::string16& profile_name) override;
107 void OnProfileNameChanged(const base::FilePath& profile_path, 99 void OnProfileNameChanged(const base::FilePath& profile_path,
108 const base::string16& old_profile_name) override; 100 const base::string16& old_profile_name) override;
109 void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override; 101 void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
110 102
111 void OnFaviconLoaded(const GURL& url, 103 // Overridden from NotifierSource::Observer.
112 const favicon_base::FaviconImageResult& favicon_result); 104 void OnIconImageUpdated(const message_center::NotifierId&,
105 const gfx::Image&) override;
106 void OnNotifierEnabledChanged(const message_center::NotifierId&,
107 bool) override;
108
109 void DispatchNotifierGroupChanged();
113 110
114 #if defined(OS_CHROMEOS) 111 #if defined(OS_CHROMEOS)
115 // Sets up the notifier group for the guest session. This needs to be 112 // Sets up the notifier group for the guest session. This needs to be
116 // separated from RebuildNotifierGroup() and called asynchronously to avoid 113 // separated from RebuildNotifierGroup() and called asynchronously to avoid
117 // the infinite loop of creating profile. See more the comment of 114 // the infinite loop of creating profile. See more the comment of
118 // RebuildNotifierGroups(). 115 // RebuildNotifierGroups().
119 void CreateNotifierGroupForGuestLogin(); 116 void CreateNotifierGroupForGuestLogin();
120 #endif 117 #endif
121 118
122 // Sets up the notifier groups for all profiles. If |notify| is true, then 119 // Sets up the notifier groups for all profiles. If |notify| is true, then
123 // it sends out a NotifierGroupChange notification to each observer. 120 // it sends out a NotifierGroupChange notification to each observer.
124 void RebuildNotifierGroups(bool notify); 121 void RebuildNotifierGroups(bool notify);
125 122
126 // The views displaying notifier settings. 123 // The views displaying notifier settings.
127 base::ObserverList<message_center::NotifierSettingsObserver> observers_; 124 base::ObserverList<message_center::NotifierSettingsObserver> observers_;
128 125
129 // The task tracker for loading favicons.
130 std::unique_ptr<base::CancelableTaskTracker> favicon_tracker_;
131
132 std::unique_ptr<AppIconLoader> app_icon_loader_;
133
134 #if defined(OS_CHROMEOS)
135 std::unique_ptr<arc::ArcNotifierManager> arc_notifier_manager_;
136 #endif
137
138 std::map<base::string16, ContentSettingsPattern> patterns_;
139
140 // The list of all configurable notifier groups. This is each profile that is 126 // The list of all configurable notifier groups. This is each profile that is
141 // loaded (and in the ProfileAttributesStorage - so no incognito profiles go 127 // loaded (and in the ProfileAttributesStorage - so no incognito profiles go
142 // here). 128 // here).
143 std::vector<std::unique_ptr<message_center::ProfileNotifierGroup>> 129 std::vector<std::unique_ptr<message_center::ProfileNotifierGroup>>
144 notifier_groups_; 130 notifier_groups_;
145 131
132 // Notifier source for each notifier type.
133 std::map<message_center::NotifierId::NotifierType,
134 std::unique_ptr<NotifierSource>>
135 sources_;
136
146 size_t current_notifier_group_; 137 size_t current_notifier_group_;
147 138
148 content::NotificationRegistrar registrar_; 139 content::NotificationRegistrar registrar_;
149 140
150 ProfileAttributesStorage& profile_attributes_storage_; 141 ProfileAttributesStorage& profile_attributes_storage_;
151 142
152 base::WeakPtrFactory<MessageCenterSettingsController> weak_factory_; 143 base::WeakPtrFactory<MessageCenterSettingsController> weak_factory_;
153 144
154 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController); 145 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsController);
155 }; 146 };
156 147
157 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_ 148 #endif // CHROME_BROWSER_NOTIFICATIONS_MESSAGE_CENTER_SETTINGS_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698