OLD | NEW |
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 #include "chrome/browser/notifications/message_center_settings_controller.h" | 5 #include "chrome/browser/notifications/message_center_settings_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/string_compare.h" | 10 #include "base/i18n/string_compare.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/extensions/app_icon_loader_impl.h" | 14 #include "chrome/browser/extensions/app_icon_loader_impl.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/favicon/favicon_service.h" | 16 #include "chrome/browser/favicon/favicon_service.h" |
16 #include "chrome/browser/favicon/favicon_service_factory.h" | 17 #include "chrome/browser/favicon/favicon_service_factory.h" |
17 #include "chrome/browser/history/history_types.h" | 18 #include "chrome/browser/history/history_types.h" |
18 #include "chrome/browser/notifications/desktop_notification_service.h" | 19 #include "chrome/browser/notifications/desktop_notification_service.h" |
19 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
20 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 21 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
21 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_info_cache.h" |
22 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
23 #include "chrome/common/cancelable_task_tracker.h" | 26 #include "chrome/common/cancelable_task_tracker.h" |
24 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
25 #include "chrome/common/favicon/favicon_types.h" | 28 #include "chrome/common/favicon/favicon_types.h" |
26 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
28 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
29 #include "grit/ui_strings.h" | 32 #include "grit/ui_strings.h" |
30 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
33 #include "ui/message_center/message_center_style.h" | 36 #include "ui/message_center/message_center_style.h" |
34 | 37 |
35 #if defined(USE_ASH) | |
36 #include "ash/shell.h" | |
37 #include "ash/system/web_notification/web_notification_tray.h" | |
38 #endif | |
39 | |
40 using message_center::Notifier; | 38 using message_center::Notifier; |
41 using message_center::NotifierId; | 39 using message_center::NotifierId; |
42 | 40 |
| 41 namespace message_center { |
| 42 class ProfileNotifierGroup : public message_center::NotifierGroup { |
| 43 public: |
| 44 ProfileNotifierGroup(const gfx::Image& icon, |
| 45 const string16& display_name, |
| 46 const string16& login_info, |
| 47 size_t index, |
| 48 const base::FilePath& profile_path); |
| 49 virtual ~ProfileNotifierGroup() {} |
| 50 |
| 51 Profile* profile() const { return profile_; } |
| 52 |
| 53 private: |
| 54 Profile* profile_; |
| 55 }; |
| 56 |
| 57 ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, |
| 58 const string16& display_name, |
| 59 const string16& login_info, |
| 60 size_t index, |
| 61 const base::FilePath& profile_path) |
| 62 : message_center::NotifierGroup(icon, display_name, login_info, index), |
| 63 profile_(NULL) { |
| 64 // Try to get the profile |
| 65 profile_ = |
| 66 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 67 } |
| 68 } // namespace message_center |
| 69 |
43 namespace { | 70 namespace { |
44 | |
45 class NotifierComparator { | 71 class NotifierComparator { |
46 public: | 72 public: |
47 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} | 73 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} |
48 | 74 |
49 bool operator() (Notifier* n1, Notifier* n2) { | 75 bool operator() (Notifier* n1, Notifier* n2) { |
50 return base::i18n::CompareString16WithCollator( | 76 return base::i18n::CompareString16WithCollator( |
51 collator_, n1->name, n2->name) == UCOL_LESS; | 77 collator_, n1->name, n2->name) == UCOL_LESS; |
52 } | 78 } |
53 | 79 |
54 private: | 80 private: |
55 icu::Collator* collator_; | 81 icu::Collator* collator_; |
56 }; | 82 }; |
57 | 83 |
58 bool SimpleCompareNotifiers(Notifier* n1, Notifier* n2) { | 84 bool SimpleCompareNotifiers(Notifier* n1, Notifier* n2) { |
59 return n1->name < n2->name; | 85 return n1->name < n2->name; |
60 } | 86 } |
61 | 87 |
62 } // namespace | 88 } // namespace |
63 | 89 |
64 MessageCenterSettingsController::MessageCenterSettingsController() | 90 MessageCenterSettingsController::MessageCenterSettingsController( |
65 : profile_(NULL) { | 91 ProfileInfoCache* profile_info_cache) |
66 // We set the profile associated with the settings at the beginning and fail | 92 : current_notifier_group_(0), profile_info_cache_(profile_info_cache) { |
67 // silently if this profile is destroyed later. This is a temporary fix for | 93 DCHECK(profile_info_cache_); |
68 // http://crbug.com/263193 | 94 // The following events all represent changes that may need to be reflected in |
69 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 95 // the profile selector context menu, so listen for them all. We'll just |
70 content::NotificationService::AllSources()); | 96 // rebuild the list when we get any of them. |
| 97 registrar_.Add(this, |
| 98 chrome::NOTIFICATION_PROFILE_CREATED, |
| 99 content::NotificationService::AllBrowserContextsAndSources()); |
| 100 registrar_.Add(this, |
| 101 chrome::NOTIFICATION_PROFILE_ADDED, |
| 102 content::NotificationService::AllBrowserContextsAndSources()); |
| 103 registrar_.Add(this, |
| 104 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 105 content::NotificationService::AllBrowserContextsAndSources()); |
| 106 registrar_.Add(this, |
| 107 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 108 content::NotificationService::AllBrowserContextsAndSources()); |
| 109 RebuildNotifierGroups(); |
71 } | 110 } |
72 | 111 |
73 MessageCenterSettingsController::~MessageCenterSettingsController() { | 112 MessageCenterSettingsController::~MessageCenterSettingsController() { |
74 } | 113 } |
75 | 114 |
76 void MessageCenterSettingsController::AddObserver( | 115 void MessageCenterSettingsController::AddObserver( |
77 message_center::NotifierSettingsObserver* observer) { | 116 message_center::NotifierSettingsObserver* observer) { |
78 observers_.AddObserver(observer); | 117 observers_.AddObserver(observer); |
79 } | 118 } |
80 | 119 |
81 void MessageCenterSettingsController::RemoveObserver( | 120 void MessageCenterSettingsController::RemoveObserver( |
82 message_center::NotifierSettingsObserver* observer) { | 121 message_center::NotifierSettingsObserver* observer) { |
83 observers_.RemoveObserver(observer); | 122 observers_.RemoveObserver(observer); |
84 } | 123 } |
85 | 124 |
| 125 size_t MessageCenterSettingsController::GetNotifierGroupCount() const { |
| 126 return notifier_groups_.size(); |
| 127 } |
| 128 |
| 129 const message_center::NotifierGroup& |
| 130 MessageCenterSettingsController::GetNotifierGroupAt(size_t index) const { |
| 131 DCHECK_LT(index, notifier_groups_.size()); |
| 132 return *(notifier_groups_[index]); |
| 133 } |
| 134 |
| 135 const message_center::NotifierGroup& |
| 136 MessageCenterSettingsController::GetActiveNotifierGroup() const { |
| 137 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); |
| 138 return *(notifier_groups_[current_notifier_group_]); |
| 139 } |
| 140 |
| 141 void MessageCenterSettingsController::SwitchToNotifierGroup(size_t index) { |
| 142 DCHECK_LT(index, notifier_groups_.size()); |
| 143 if (current_notifier_group_ == index) |
| 144 return; |
| 145 |
| 146 current_notifier_group_ = index; |
| 147 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
| 148 observers_, |
| 149 NotifierGroupChanged()); |
| 150 } |
| 151 |
86 void MessageCenterSettingsController::GetNotifierList( | 152 void MessageCenterSettingsController::GetNotifierList( |
87 std::vector<Notifier*>* notifiers) { | 153 std::vector<Notifier*>* notifiers) { |
88 DCHECK(notifiers); | 154 DCHECK(notifiers); |
89 // TODO(mukai): Fix this for multi-profile. | 155 // TODO(mukai): Fix this for multi-profile. |
90 // Temporarily use the last used profile to prevent chrome from crashing when | 156 // Temporarily use the last used profile to prevent chrome from crashing when |
91 // the default profile is not loaded. | 157 // the default profile is not loaded. |
92 profile_ = ProfileManager::GetLastUsedProfileAllowedByPolicy(); | 158 message_center::ProfileNotifierGroup* group = |
| 159 notifier_groups_[current_notifier_group_]; |
| 160 Profile* profile = group->profile(); |
| 161 if (!profile) |
| 162 return; |
| 163 |
93 DesktopNotificationService* notification_service = | 164 DesktopNotificationService* notification_service = |
94 DesktopNotificationServiceFactory::GetForProfile(profile_); | 165 DesktopNotificationServiceFactory::GetForProfile(profile); |
95 | 166 |
96 UErrorCode error; | 167 UErrorCode error; |
97 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error)); | 168 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error)); |
98 scoped_ptr<NotifierComparator> comparator; | 169 scoped_ptr<NotifierComparator> comparator; |
99 if (!U_FAILURE(error)) | 170 if (!U_FAILURE(error)) |
100 comparator.reset(new NotifierComparator(collator.get())); | 171 comparator.reset(new NotifierComparator(collator.get())); |
101 | 172 |
102 ExtensionService* extension_service = profile_->GetExtensionService(); | 173 ExtensionService* extension_service = profile->GetExtensionService(); |
103 const ExtensionSet* extension_set = extension_service->extensions(); | 174 const ExtensionSet* extension_set = extension_service->extensions(); |
104 // The extension icon size has to be 32x32 at least to load bigger icons if | 175 // The extension icon size has to be 32x32 at least to load bigger icons if |
105 // the icon doesn't exist for the specified size, and in that case it falls | 176 // the icon doesn't exist for the specified size, and in that case it falls |
106 // back to the default icon. The fetched icon will be resized in the settings | 177 // back to the default icon. The fetched icon will be resized in the settings |
107 // dialog. See chrome/browser/extensions/extension_icon_image.cc and | 178 // dialog. See chrome/browser/extensions/extension_icon_image.cc and |
108 // crbug.com/222931 | 179 // crbug.com/222931 |
109 app_icon_loader_.reset(new extensions::AppIconLoaderImpl( | 180 app_icon_loader_.reset(new extensions::AppIconLoaderImpl( |
110 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); | 181 profile, extension_misc::EXTENSION_ICON_SMALL, this)); |
111 for (ExtensionSet::const_iterator iter = extension_set->begin(); | 182 for (ExtensionSet::const_iterator iter = extension_set->begin(); |
112 iter != extension_set->end(); ++iter) { | 183 iter != extension_set->end(); |
| 184 ++iter) { |
113 const extensions::Extension* extension = iter->get(); | 185 const extensions::Extension* extension = iter->get(); |
114 if (!extension->HasAPIPermission( | 186 if (!extension->HasAPIPermission( |
115 extensions::APIPermission::kNotification)) { | 187 extensions::APIPermission::kNotification)) { |
116 continue; | 188 continue; |
117 } | 189 } |
118 | 190 |
119 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 191 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
120 notifiers->push_back(new Notifier( | 192 notifiers->push_back(new Notifier( |
121 notifier_id, | 193 notifier_id, |
122 UTF8ToUTF16(extension->name()), | 194 UTF8ToUTF16(extension->name()), |
123 notification_service->IsNotifierEnabled(notifier_id))); | 195 notification_service->IsNotifierEnabled(notifier_id))); |
124 app_icon_loader_->FetchImage(extension->id()); | 196 app_icon_loader_->FetchImage(extension->id()); |
125 } | 197 } |
126 | 198 |
127 if (notifier::ChromeNotifierServiceFactory::UseSyncedNotifications( | 199 if (notifier::ChromeNotifierServiceFactory::UseSyncedNotifications( |
128 CommandLine::ForCurrentProcess())) { | 200 CommandLine::ForCurrentProcess())) { |
129 notifier::ChromeNotifierService* sync_notifier_service = | 201 notifier::ChromeNotifierService* sync_notifier_service = |
130 notifier::ChromeNotifierServiceFactory::GetInstance()->GetForProfile( | 202 notifier::ChromeNotifierServiceFactory::GetInstance()->GetForProfile( |
131 profile_, Profile::EXPLICIT_ACCESS); | 203 profile, Profile::EXPLICIT_ACCESS); |
132 sync_notifier_service->GetSyncedNotificationServices(notifiers); | 204 sync_notifier_service->GetSyncedNotificationServices(notifiers); |
133 | 205 |
134 if (comparator) | 206 if (comparator) |
135 std::sort(notifiers->begin(), notifiers->end(), *comparator); | 207 std::sort(notifiers->begin(), notifiers->end(), *comparator); |
136 else | 208 else |
137 std::sort(notifiers->begin(), notifiers->end(), SimpleCompareNotifiers); | 209 std::sort(notifiers->begin(), notifiers->end(), SimpleCompareNotifiers); |
138 } | 210 } |
139 | 211 |
140 int app_count = notifiers->size(); | 212 int app_count = notifiers->size(); |
141 | 213 |
142 ContentSettingsForOneType settings; | 214 ContentSettingsForOneType settings; |
143 notification_service->GetNotificationsSettings(&settings); | 215 notification_service->GetNotificationsSettings(&settings); |
144 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 216 FaviconService* favicon_service = |
145 profile_, Profile::EXPLICIT_ACCESS); | 217 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
146 favicon_tracker_.reset(new CancelableTaskTracker()); | 218 favicon_tracker_.reset(new CancelableTaskTracker()); |
147 patterns_.clear(); | 219 patterns_.clear(); |
148 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); | 220 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); |
149 iter != settings.end(); ++iter) { | 221 iter != settings.end(); ++iter) { |
150 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && | 222 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && |
151 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && | 223 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && |
152 iter->source != "preference") { | 224 iter->source != "preference") { |
153 continue; | 225 continue; |
154 } | 226 } |
155 | 227 |
156 std::string url_pattern = iter->primary_pattern.ToString(); | 228 std::string url_pattern = iter->primary_pattern.ToString(); |
157 string16 name = UTF8ToUTF16(url_pattern); | 229 string16 name = UTF8ToUTF16(url_pattern); |
158 GURL url(url_pattern); | 230 GURL url(url_pattern); |
159 NotifierId notifier_id(url); | 231 NotifierId notifier_id(url); |
160 notifiers->push_back(new Notifier( | 232 notifiers->push_back(new Notifier( |
161 notifier_id, | 233 notifier_id, |
162 name, | 234 name, |
163 notification_service->IsNotifierEnabled(notifier_id))); | 235 notification_service->IsNotifierEnabled(notifier_id))); |
164 patterns_[name] = iter->primary_pattern; | 236 patterns_[name] = iter->primary_pattern; |
165 FaviconService::FaviconForURLParams favicon_params( | 237 FaviconService::FaviconForURLParams favicon_params( |
166 profile_, url, chrome::FAVICON | chrome::TOUCH_ICON, | 238 profile, |
| 239 url, |
| 240 chrome::FAVICON | chrome::TOUCH_ICON, |
167 message_center::kSettingsIconSize); | 241 message_center::kSettingsIconSize); |
168 // Note that favicon service obtains the favicon from history. This means | 242 // Note that favicon service obtains the favicon from history. This means |
169 // that it will fail to obtain the image if there are no history data for | 243 // that it will fail to obtain the image if there are no history data for |
170 // that URL. | 244 // that URL. |
171 favicon_service->GetFaviconImageForURL( | 245 favicon_service->GetFaviconImageForURL( |
172 favicon_params, | 246 favicon_params, |
173 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, | 247 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, |
174 base::Unretained(this), url), | 248 base::Unretained(this), url), |
175 favicon_tracker_.get()); | 249 favicon_tracker_.get()); |
176 } | 250 } |
(...skipping 17 matching lines...) Expand all Loading... |
194 std::sort(notifiers->begin() + app_count, notifiers->end(), *comparator); | 268 std::sort(notifiers->begin() + app_count, notifiers->end(), *comparator); |
195 } else { | 269 } else { |
196 std::sort(notifiers->begin() + app_count, notifiers->end(), | 270 std::sort(notifiers->begin() + app_count, notifiers->end(), |
197 SimpleCompareNotifiers); | 271 SimpleCompareNotifiers); |
198 } | 272 } |
199 } | 273 } |
200 | 274 |
201 void MessageCenterSettingsController::SetNotifierEnabled( | 275 void MessageCenterSettingsController::SetNotifierEnabled( |
202 const Notifier& notifier, | 276 const Notifier& notifier, |
203 bool enabled) { | 277 bool enabled) { |
204 // TODO(mukai): Fix this for multi-profile. | 278 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); |
205 // If the profile has been destroyed, fail silently. | 279 DCHECK(profile); |
206 if (!profile_) | 280 |
207 return; | |
208 DesktopNotificationService* notification_service = | 281 DesktopNotificationService* notification_service = |
209 DesktopNotificationServiceFactory::GetForProfile(profile_); | 282 DesktopNotificationServiceFactory::GetForProfile(profile); |
210 | 283 |
211 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) { | 284 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) { |
212 // WEB_PAGE notifier cannot handle in DesktopNotificationService | 285 // WEB_PAGE notifier cannot handle in DesktopNotificationService |
213 // since it has the exact URL pattern. | 286 // since it has the exact URL pattern. |
214 // TODO(mukai): fix this. | 287 // TODO(mukai): fix this. |
215 ContentSetting default_setting = | 288 ContentSetting default_setting = |
216 notification_service->GetDefaultContentSetting(NULL); | 289 notification_service->GetDefaultContentSetting(NULL); |
217 DCHECK(default_setting == CONTENT_SETTING_ALLOW || | 290 DCHECK(default_setting == CONTENT_SETTING_ALLOW || |
218 default_setting == CONTENT_SETTING_BLOCK || | 291 default_setting == CONTENT_SETTING_BLOCK || |
219 default_setting == CONTENT_SETTING_ASK); | 292 default_setting == CONTENT_SETTING_ASK); |
(...skipping 16 matching lines...) Expand all Loading... |
236 } else { | 309 } else { |
237 LOG(ERROR) << "Invalid url pattern: " | 310 LOG(ERROR) << "Invalid url pattern: " |
238 << notifier.notifier_id.url.spec(); | 311 << notifier.notifier_id.url.spec(); |
239 } | 312 } |
240 } | 313 } |
241 } else { | 314 } else { |
242 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); | 315 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); |
243 if (notifier.notifier_id.type == NotifierId::SYNCED_NOTIFICATION_SERVICE) { | 316 if (notifier.notifier_id.type == NotifierId::SYNCED_NOTIFICATION_SERVICE) { |
244 notifier::ChromeNotifierService* notifier_service = | 317 notifier::ChromeNotifierService* notifier_service = |
245 notifier::ChromeNotifierServiceFactory::GetInstance()->GetForProfile( | 318 notifier::ChromeNotifierServiceFactory::GetInstance()->GetForProfile( |
246 profile_, Profile::EXPLICIT_ACCESS); | 319 profile, Profile::EXPLICIT_ACCESS); |
247 notifier_service->OnSyncedNotificationServiceEnabled( | 320 notifier_service->OnSyncedNotificationServiceEnabled( |
248 notifier.notifier_id.id, enabled); | 321 notifier.notifier_id.id, enabled); |
249 } | 322 } |
250 } | 323 } |
251 } | 324 } |
252 | 325 |
253 void MessageCenterSettingsController::OnNotifierSettingsClosing() { | 326 void MessageCenterSettingsController::OnNotifierSettingsClosing() { |
254 DCHECK(favicon_tracker_.get()); | 327 DCHECK(favicon_tracker_.get()); |
255 favicon_tracker_->TryCancelAll(); | 328 favicon_tracker_->TryCancelAll(); |
256 patterns_.clear(); | 329 patterns_.clear(); |
257 } | 330 } |
258 | 331 |
259 void MessageCenterSettingsController::Observe( | |
260 int type, | |
261 const content::NotificationSource& source, | |
262 const content::NotificationDetails& details) { | |
263 if (type == chrome::NOTIFICATION_PROFILE_DESTROYED && | |
264 content::Source<Profile>(source).ptr() == profile_) { | |
265 // Our profile just got destroyed, so we delete our pointer to it. | |
266 profile_ = NULL; | |
267 } | |
268 } | |
269 | |
270 void MessageCenterSettingsController::OnFaviconLoaded( | 332 void MessageCenterSettingsController::OnFaviconLoaded( |
271 const GURL& url, | 333 const GURL& url, |
272 const chrome::FaviconImageResult& favicon_result) { | 334 const chrome::FaviconImageResult& favicon_result) { |
273 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 335 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
274 observers_, | 336 observers_, |
275 UpdateIconImage(NotifierId(url), favicon_result.image)); | 337 UpdateIconImage(NotifierId(url), favicon_result.image)); |
276 } | 338 } |
277 | 339 |
278 | 340 |
279 void MessageCenterSettingsController::SetAppImage(const std::string& id, | 341 void MessageCenterSettingsController::SetAppImage(const std::string& id, |
280 const gfx::ImageSkia& image) { | 342 const gfx::ImageSkia& image) { |
281 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 343 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
282 observers_, | 344 observers_, |
283 UpdateIconImage(NotifierId(NotifierId::APPLICATION, id), | 345 UpdateIconImage(NotifierId(NotifierId::APPLICATION, id), |
284 gfx::Image(image))); | 346 gfx::Image(image))); |
285 } | 347 } |
| 348 |
| 349 void MessageCenterSettingsController::Observe( |
| 350 int type, |
| 351 const content::NotificationSource& source, |
| 352 const content::NotificationDetails& details) { |
| 353 RebuildNotifierGroups(); |
| 354 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
| 355 observers_, |
| 356 NotifierGroupChanged()); |
| 357 } |
| 358 |
| 359 void MessageCenterSettingsController::RebuildNotifierGroups() { |
| 360 notifier_groups_.clear(); |
| 361 current_notifier_group_ = 0; |
| 362 |
| 363 const size_t count = profile_info_cache_->GetNumberOfProfiles(); |
| 364 for (size_t i = 0; i < count; ++i) { |
| 365 message_center::ProfileNotifierGroup* group = |
| 366 new message_center::ProfileNotifierGroup( |
| 367 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), |
| 368 profile_info_cache_->GetNameOfProfileAtIndex(i), |
| 369 profile_info_cache_->GetUserNameOfProfileAtIndex(i), |
| 370 i, |
| 371 profile_info_cache_->GetPathOfProfileAtIndex(i)); |
| 372 if (group->profile() != NULL) { |
| 373 notifier_groups_.push_back(group); |
| 374 } |
| 375 } |
| 376 } |
OLD | NEW |