Chromium Code Reviews| 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 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/string_compare.h" | 12 #include "base/i18n/string_compare.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/task/cancelable_task_tracker.h" | |
| 15 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/notifications/application_notifier_source.h" |
| 20 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 19 #include "chrome/browser/notifications/web_page_notifier_source.h" |
| 21 #include "chrome/browser/favicon/favicon_service_factory.h" | |
| 22 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | |
| 23 #include "chrome/browser/notifications/notifier_state_tracker.h" | |
| 24 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | |
| 25 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_attributes_entry.h" | 21 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 27 #include "chrome/browser/profiles/profile_attributes_storage.h" | 22 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/common/extensions/api/notifications.h" | 24 #include "chrome/common/extensions/api/notifications.h" |
| 30 #include "chrome/common/extensions/extension_constants.h" | |
| 31 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 32 #include "components/favicon/core/favicon_service.h" | |
| 33 #include "components/favicon_base/favicon_types.h" | |
| 34 #include "components/history/core/browser/history_types.h" | |
| 35 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_source.h" | |
| 37 #include "extensions/browser/event_router.h" | 26 #include "extensions/browser/event_router.h" |
| 38 #include "extensions/browser/extension_registry.h" | |
| 39 #include "extensions/common/constants.h" | |
| 40 #include "extensions/common/extension.h" | |
| 41 #include "extensions/common/permissions/permissions_data.h" | |
| 42 #include "grit/theme_resources.h" | |
| 43 #include "ui/base/l10n/l10n_util.h" | |
| 44 #include "ui/base/resource/resource_bundle.h" | |
| 45 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 46 #include "ui/message_center/message_center_style.h" | 28 #include "ui/message_center/message_center_style.h" |
| 47 #include "ui/strings/grit/ui_strings.h" | |
| 48 | 29 |
| 49 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 50 #include "ash/system/system_notifier.h" | |
| 51 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 52 #include "chrome/browser/notifications/arc_notifier_manager.h" | 32 #include "chrome/browser/notifications/arc_application_notifier_source_chromeos. h" |
| 53 #include "components/arc/arc_bridge_service.h" | 33 #include "chrome/browser/notifications/system_component_notifier_source_chromeos .h" |
| 54 #endif | 34 #endif |
| 55 | 35 |
| 56 using message_center::Notifier; | 36 using message_center::Notifier; |
| 57 using message_center::NotifierId; | 37 using message_center::NotifierId; |
| 58 | 38 |
| 59 namespace message_center { | 39 namespace message_center { |
| 60 | 40 |
| 61 class ProfileNotifierGroup : public message_center::NotifierGroup { | 41 class ProfileNotifierGroup : public message_center::NotifierGroup { |
| 62 public: | 42 public: |
| 63 ProfileNotifierGroup(const gfx::Image& icon, | 43 ProfileNotifierGroup(const gfx::Image& icon, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 91 const base::string16& display_name, | 71 const base::string16& display_name, |
| 92 const base::string16& login_info, | 72 const base::string16& login_info, |
| 93 Profile* profile) | 73 Profile* profile) |
| 94 : message_center::NotifierGroup(icon, display_name, login_info), | 74 : message_center::NotifierGroup(icon, display_name, login_info), |
| 95 profile_(profile) { | 75 profile_(profile) { |
| 96 } | 76 } |
| 97 | 77 |
| 98 } // namespace message_center | 78 } // namespace message_center |
| 99 | 79 |
| 100 namespace { | 80 namespace { |
| 81 | |
| 101 class NotifierComparator { | 82 class NotifierComparator { |
| 102 public: | 83 public: |
| 103 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} | 84 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} |
| 104 | 85 |
| 105 bool operator() (Notifier* n1, Notifier* n2) { | 86 bool operator() (Notifier* n1, Notifier* n2) { |
| 106 if (n1->notifier_id.type != n2->notifier_id.type) | 87 if (n1->notifier_id.type != n2->notifier_id.type) |
| 107 return n1->notifier_id.type < n2->notifier_id.type; | 88 return n1->notifier_id.type < n2->notifier_id.type; |
| 108 | 89 |
| 109 if (collator_) { | 90 if (collator_) { |
| 110 return base::i18n::CompareString16WithCollator(*collator_, n1->name, | 91 return base::i18n::CompareString16WithCollator(*collator_, n1->name, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 132 content::NotificationService::AllBrowserContextsAndSources()); | 113 content::NotificationService::AllBrowserContextsAndSources()); |
| 133 registrar_.Add(this, | 114 registrar_.Add(this, |
| 134 chrome::NOTIFICATION_PROFILE_ADDED, | 115 chrome::NOTIFICATION_PROFILE_ADDED, |
| 135 content::NotificationService::AllBrowserContextsAndSources()); | 116 content::NotificationService::AllBrowserContextsAndSources()); |
| 136 registrar_.Add(this, | 117 registrar_.Add(this, |
| 137 chrome::NOTIFICATION_PROFILE_DESTROYED, | 118 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 138 content::NotificationService::AllBrowserContextsAndSources()); | 119 content::NotificationService::AllBrowserContextsAndSources()); |
| 139 profile_attributes_storage_.AddObserver(this); | 120 profile_attributes_storage_.AddObserver(this); |
| 140 RebuildNotifierGroups(false); | 121 RebuildNotifierGroups(false); |
| 141 | 122 |
| 123 sources_.insert(std::make_pair( | |
| 124 NotifierId::APPLICATION, | |
| 125 std::unique_ptr<NotifierSource>(new ApplicationNotifierSource(this)))); | |
| 126 sources_.insert(std::make_pair( | |
| 127 NotifierId::WEB_PAGE, | |
| 128 std::unique_ptr<NotifierSource>(new WebPageNotifiereSource(this)))); | |
| 129 | |
| 142 #if defined(OS_CHROMEOS) | 130 #if defined(OS_CHROMEOS) |
| 143 // UserManager may not exist in some tests. | 131 // UserManager may not exist in some tests. |
| 144 if (user_manager::UserManager::IsInitialized()) | 132 if (user_manager::UserManager::IsInitialized()) |
| 145 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 133 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 146 // Check if ARC is enabled. | 134 // FOr system components. |
|
dewittj
2016/06/20 17:14:22
nit: FOr -> For
or remove the comment, it's fairly
hirono
2016/06/21 00:46:02
Done.
| |
| 147 if (arc::ArcBridgeService::Get()) | 135 sources_.insert( |
| 148 arc_notifier_manager_.reset(new arc::ArcNotifierManager()); | 136 std::make_pair(NotifierId::SYSTEM_COMPONENT, |
| 137 std::unique_ptr<NotifierSource>( | |
| 138 new SystemComponentNotifierSourceChromeOS(this)))); | |
| 139 sources_.insert( | |
| 140 std::make_pair(NotifierId::ARC_APPLICATION, | |
| 141 std::unique_ptr<NotifierSource>( | |
| 142 new arc::ArcApplicationNotifierSourceChromeOS(this)))); | |
| 149 #endif | 143 #endif |
| 150 } | 144 } |
| 151 | 145 |
| 152 MessageCenterSettingsController::~MessageCenterSettingsController() { | 146 MessageCenterSettingsController::~MessageCenterSettingsController() { |
| 153 profile_attributes_storage_.RemoveObserver(this); | 147 profile_attributes_storage_.RemoveObserver(this); |
| 154 #if defined(OS_CHROMEOS) | 148 #if defined(OS_CHROMEOS) |
| 155 // UserManager may not exist in some tests. | 149 // UserManager may not exist in some tests. |
| 156 if (user_manager::UserManager::IsInitialized()) | 150 if (user_manager::UserManager::IsInitialized()) |
| 157 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 151 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
| 158 #endif | 152 #endif |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 188 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); | 182 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); |
| 189 return *(notifier_groups_[current_notifier_group_]); | 183 return *(notifier_groups_[current_notifier_group_]); |
| 190 } | 184 } |
| 191 | 185 |
| 192 void MessageCenterSettingsController::SwitchToNotifierGroup(size_t index) { | 186 void MessageCenterSettingsController::SwitchToNotifierGroup(size_t index) { |
| 193 DCHECK_LT(index, notifier_groups_.size()); | 187 DCHECK_LT(index, notifier_groups_.size()); |
| 194 if (current_notifier_group_ == index) | 188 if (current_notifier_group_ == index) |
| 195 return; | 189 return; |
| 196 | 190 |
| 197 current_notifier_group_ = index; | 191 current_notifier_group_ = index; |
| 198 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 192 DispatchNotifierGroupChanged(); |
| 199 observers_, | |
| 200 NotifierGroupChanged()); | |
| 201 } | 193 } |
| 202 | 194 |
| 203 void MessageCenterSettingsController::GetNotifierList( | 195 void MessageCenterSettingsController::GetNotifierList( |
| 204 std::vector<Notifier*>* notifiers) { | 196 std::vector<Notifier*>* notifiers) { |
| 205 DCHECK(notifiers); | 197 DCHECK(notifiers); |
| 206 if (notifier_groups_.size() <= current_notifier_group_) | 198 if (notifier_groups_.size() <= current_notifier_group_) |
| 207 return; | 199 return; |
| 208 // Temporarily use the last used profile to prevent chrome from crashing when | 200 // Temporarily use the last used profile to prevent chrome from crashing when |
| 209 // the default profile is not loaded. | 201 // the default profile is not loaded. |
| 210 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); | 202 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); |
| 211 | 203 |
| 212 NotifierStateTracker* notifier_state_tracker = | 204 for (auto& source : sources_) { |
| 213 NotifierStateTrackerFactory::GetForProfile(profile); | 205 auto source_notifiers = source.second->GetNotifierList(profile); |
| 214 | 206 for (auto& notifier : source_notifiers) { |
| 215 const extensions::ExtensionSet& extension_set = | |
| 216 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | |
| 217 // The extension icon size has to be 32x32 at least to load bigger icons if | |
| 218 // the icon doesn't exist for the specified size, and in that case it falls | |
| 219 // back to the default icon. The fetched icon will be resized in the settings | |
| 220 // dialog. See chrome/browser/extensions/extension_icon_image.cc and | |
| 221 // crbug.com/222931 | |
| 222 app_icon_loader_.reset(new extensions::ExtensionAppIconLoader( | |
| 223 profile, extension_misc::EXTENSION_ICON_SMALL, this)); | |
| 224 for (extensions::ExtensionSet::const_iterator iter = extension_set.begin(); | |
| 225 iter != extension_set.end(); | |
| 226 ++iter) { | |
| 227 const extensions::Extension* extension = iter->get(); | |
| 228 if (!extension->permissions_data()->HasAPIPermission( | |
| 229 extensions::APIPermission::kNotifications)) { | |
| 230 continue; | |
| 231 } | |
| 232 | |
| 233 // Hosted apps are no longer able to affect the notifications permission | |
| 234 // state for web notifications. | |
| 235 // TODO(dewittj): Deprecate the 'notifications' permission for hosted apps. | |
| 236 if (extension->is_hosted_app()) | |
| 237 continue; | |
| 238 | |
| 239 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | |
| 240 notifiers->push_back(new Notifier( | |
| 241 notifier_id, | |
| 242 base::UTF8ToUTF16(extension->name()), | |
| 243 notifier_state_tracker->IsNotifierEnabled(notifier_id))); | |
| 244 app_icon_loader_->FetchImage(extension->id()); | |
| 245 } | |
| 246 | |
| 247 ContentSettingsForOneType settings; | |
| 248 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings); | |
| 249 | |
| 250 favicon::FaviconService* favicon_service = | |
| 251 FaviconServiceFactory::GetForProfile(profile, | |
| 252 ServiceAccessType::EXPLICIT_ACCESS); | |
| 253 favicon_tracker_.reset(new base::CancelableTaskTracker()); | |
| 254 patterns_.clear(); | |
| 255 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); | |
| 256 iter != settings.end(); ++iter) { | |
| 257 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && | |
| 258 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && | |
| 259 iter->source != "preference") { | |
| 260 continue; | |
| 261 } | |
| 262 | |
| 263 std::string url_pattern = iter->primary_pattern.ToString(); | |
| 264 base::string16 name = base::UTF8ToUTF16(url_pattern); | |
| 265 GURL url(url_pattern); | |
| 266 NotifierId notifier_id(url); | |
| 267 notifiers->push_back(new Notifier( | |
| 268 notifier_id, | |
| 269 name, | |
| 270 notifier_state_tracker->IsNotifierEnabled(notifier_id))); | |
| 271 patterns_[name] = iter->primary_pattern; | |
| 272 // Note that favicon service obtains the favicon from history. This means | |
| 273 // that it will fail to obtain the image if there are no history data for | |
| 274 // that URL. | |
| 275 favicon_service->GetFaviconImageForPageURL( | |
| 276 url, | |
| 277 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, | |
| 278 base::Unretained(this), | |
| 279 url), | |
| 280 favicon_tracker_.get()); | |
| 281 } | |
| 282 | |
| 283 #if defined(OS_CHROMEOS) | |
| 284 // Add ARC++ apps. | |
| 285 if (arc_notifier_manager_) { | |
| 286 auto list = arc_notifier_manager_->GetNotifiers(profile); | |
| 287 for (auto& notifier : list) { | |
| 288 notifiers->push_back(notifier.release()); | 207 notifiers->push_back(notifier.release()); |
| 289 } | 208 } |
| 290 } | 209 } |
| 291 | 210 |
| 292 // Screenshot notification feature is only for ChromeOS. See crbug.com/238358 | |
| 293 const base::string16& screenshot_name = | |
| 294 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_NOTIFIER_SCREENSHOT_NAME); | |
| 295 NotifierId screenshot_notifier_id( | |
| 296 NotifierId::SYSTEM_COMPONENT, ash::system_notifier::kNotifierScreenshot); | |
| 297 Notifier* const screenshot_notifier = new Notifier( | |
| 298 screenshot_notifier_id, | |
| 299 screenshot_name, | |
| 300 notifier_state_tracker->IsNotifierEnabled(screenshot_notifier_id)); | |
| 301 screenshot_notifier->icon = | |
| 302 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 303 IDR_SCREENSHOT_NOTIFICATION_ICON); | |
| 304 notifiers->push_back(screenshot_notifier); | |
| 305 #endif | |
| 306 | |
| 307 UErrorCode error = U_ZERO_ERROR; | 211 UErrorCode error = U_ZERO_ERROR; |
| 308 std::unique_ptr<icu::Collator> collator(icu::Collator::createInstance(error)); | 212 std::unique_ptr<icu::Collator> collator(icu::Collator::createInstance(error)); |
| 309 std::unique_ptr<NotifierComparator> comparator( | 213 std::unique_ptr<NotifierComparator> comparator( |
| 310 new NotifierComparator(U_SUCCESS(error) ? collator.get() : NULL)); | 214 new NotifierComparator(U_SUCCESS(error) ? collator.get() : NULL)); |
| 311 | 215 |
| 312 std::sort(notifiers->begin(), notifiers->end(), *comparator); | 216 std::sort(notifiers->begin(), notifiers->end(), *comparator); |
| 313 } | 217 } |
| 314 | 218 |
| 315 void MessageCenterSettingsController::SetNotifierEnabled( | 219 void MessageCenterSettingsController::SetNotifierEnabled( |
| 316 const Notifier& notifier, | 220 const Notifier& notifier, |
| 317 bool enabled) { | 221 bool enabled) { |
| 318 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); | 222 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); |
| 319 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); | 223 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); |
| 320 | 224 |
| 321 switch (notifier.notifier_id.type) { | 225 if (!sources_.count(notifier.notifier_id.type)) { |
| 322 case NotifierId::WEB_PAGE: { | 226 NOTREACHED(); |
| 323 // WEB_PAGE notifier cannot handle in DesktopNotificationService | 227 return; |
| 324 // since it has the exact URL pattern. | 228 } |
| 325 // TODO(mukai): fix this. | |
| 326 ContentSetting default_setting = | |
| 327 HostContentSettingsMapFactory::GetForProfile(profile) | |
| 328 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 329 NULL); | |
| 330 | 229 |
| 331 DCHECK(default_setting == CONTENT_SETTING_ALLOW || | 230 sources_[notifier.notifier_id.type]->SetNotifierEnabled(profile, notifier, |
| 332 default_setting == CONTENT_SETTING_BLOCK || | 231 enabled); |
| 333 default_setting == CONTENT_SETTING_ASK); | |
| 334 | |
| 335 // The content setting for notifications needs to clear when it changes to | |
| 336 // the default value or get explicitly set when it differs from the | |
| 337 // default. | |
| 338 bool differs_from_default_value = | |
| 339 (default_setting != CONTENT_SETTING_ALLOW && enabled) || | |
| 340 (default_setting == CONTENT_SETTING_ALLOW && !enabled); | |
| 341 | |
| 342 if (differs_from_default_value) { | |
| 343 if (notifier.notifier_id.url.is_valid()) { | |
| 344 if (enabled) { | |
| 345 DesktopNotificationProfileUtil::GrantPermission( | |
| 346 profile, notifier.notifier_id.url); | |
| 347 } else { | |
| 348 DesktopNotificationProfileUtil::DenyPermission( | |
| 349 profile, notifier.notifier_id.url); | |
| 350 } | |
| 351 } else { | |
| 352 LOG(ERROR) << "Invalid url pattern: " | |
| 353 << notifier.notifier_id.url.spec(); | |
| 354 } | |
| 355 } else { | |
| 356 ContentSettingsPattern pattern; | |
| 357 | |
| 358 const auto& iter = patterns_.find(notifier.name); | |
| 359 if (iter != patterns_.end()) { | |
| 360 pattern = iter->second; | |
| 361 } else if (notifier.notifier_id.url.is_valid()) { | |
| 362 pattern = ContentSettingsPattern::FromURLNoWildcard( | |
| 363 notifier.notifier_id.url); | |
| 364 } else { | |
| 365 LOG(ERROR) << "Invalid url pattern: " | |
| 366 << notifier.notifier_id.url.spec(); | |
| 367 } | |
| 368 | |
| 369 if (pattern.IsValid()) { | |
| 370 // Note that we don't use | |
| 371 // DesktopNotificationProfileUtil::ClearSetting() | |
| 372 // here because pattern might be from user manual input and not match | |
| 373 // the default one used by ClearSetting(). | |
| 374 HostContentSettingsMapFactory::GetForProfile(profile) | |
| 375 ->SetContentSettingCustomScope( | |
| 376 pattern, ContentSettingsPattern::Wildcard(), | |
| 377 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 378 content_settings::ResourceIdentifier(), | |
| 379 CONTENT_SETTING_DEFAULT); | |
| 380 } | |
| 381 } | |
| 382 break; | |
| 383 } | |
| 384 case NotifierId::APPLICATION: | |
| 385 case NotifierId::SYSTEM_COMPONENT: { | |
| 386 NotifierStateTrackerFactory::GetForProfile(profile)->SetNotifierEnabled( | |
| 387 notifier.notifier_id, enabled); | |
| 388 break; | |
| 389 } | |
| 390 case NotifierId::ARC_APPLICATION: { | |
| 391 #if defined(OS_CHROMEOS) | |
| 392 if (arc_notifier_manager_) { | |
| 393 arc_notifier_manager_->SetNotifierEnabled(notifier.notifier_id.id, | |
| 394 enabled); | |
| 395 } | |
| 396 #else | |
| 397 NOTREACHED(); | |
| 398 #endif | |
| 399 break; | |
| 400 } | |
| 401 } | |
| 402 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 403 observers_, | |
| 404 NotifierEnabledChanged(notifier.notifier_id, enabled)); | |
| 405 } | 232 } |
| 406 | 233 |
| 407 void MessageCenterSettingsController::OnNotifierSettingsClosing() { | 234 void MessageCenterSettingsController::OnNotifierSettingsClosing() { |
| 408 DCHECK(favicon_tracker_.get()); | 235 for (auto& source : sources_) { |
| 409 favicon_tracker_->TryCancelAll(); | 236 source.second->OnNotifierSettingsClosing(); |
| 410 patterns_.clear(); | 237 } |
| 411 } | 238 } |
| 412 | 239 |
| 413 bool MessageCenterSettingsController::NotifierHasAdvancedSettings( | 240 bool MessageCenterSettingsController::NotifierHasAdvancedSettings( |
| 414 const NotifierId& notifier_id) const { | 241 const NotifierId& notifier_id) const { |
| 415 // TODO(dewittj): Refactor this so that notifiers have a delegate that can | 242 // TODO(dewittj): Refactor this so that notifiers have a delegate that can |
| 416 // handle this in a more appropriate location. | 243 // handle this in a more appropriate location. |
| 417 if (notifier_id.type != NotifierId::APPLICATION) | 244 if (notifier_id.type != NotifierId::APPLICATION) |
| 418 return false; | 245 return false; |
| 419 | 246 |
| 420 const std::string& extension_id = notifier_id.id; | 247 const std::string& extension_id = notifier_id.id; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 446 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); | 273 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); |
| 447 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 274 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 448 | 275 |
| 449 std::unique_ptr<extensions::Event> event(new extensions::Event( | 276 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 450 extensions::events::NOTIFICATIONS_ON_SHOW_SETTINGS, | 277 extensions::events::NOTIFICATIONS_ON_SHOW_SETTINGS, |
| 451 extensions::api::notifications::OnShowSettings::kEventName, | 278 extensions::api::notifications::OnShowSettings::kEventName, |
| 452 std::move(args))); | 279 std::move(args))); |
| 453 event_router->DispatchEventToExtension(extension_id, std::move(event)); | 280 event_router->DispatchEventToExtension(extension_id, std::move(event)); |
| 454 } | 281 } |
| 455 | 282 |
| 456 void MessageCenterSettingsController::OnFaviconLoaded( | |
| 457 const GURL& url, | |
| 458 const favicon_base::FaviconImageResult& favicon_result) { | |
| 459 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 460 observers_, | |
| 461 UpdateIconImage(NotifierId(url), favicon_result.image)); | |
| 462 } | |
| 463 | |
| 464 | |
| 465 #if defined(OS_CHROMEOS) | 283 #if defined(OS_CHROMEOS) |
| 466 void MessageCenterSettingsController::ActiveUserChanged( | 284 void MessageCenterSettingsController::ActiveUserChanged( |
| 467 const user_manager::User* active_user) { | 285 const user_manager::User* active_user) { |
| 468 RebuildNotifierGroups(false); | 286 RebuildNotifierGroups(false); |
| 469 } | 287 } |
| 470 #endif | 288 #endif |
| 471 | 289 |
| 472 void MessageCenterSettingsController::OnAppImageUpdated( | |
| 473 const std::string& id, const gfx::ImageSkia& image) { | |
| 474 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 475 observers_, | |
| 476 UpdateIconImage(NotifierId(NotifierId::APPLICATION, id), | |
| 477 gfx::Image(image))); | |
| 478 } | |
| 479 | |
| 480 void MessageCenterSettingsController::Observe( | 290 void MessageCenterSettingsController::Observe( |
| 481 int type, | 291 int type, |
| 482 const content::NotificationSource& source, | 292 const content::NotificationSource& source, |
| 483 const content::NotificationDetails& details) { | 293 const content::NotificationDetails& details) { |
| 484 // GetOffTheRecordProfile() may create a new off-the-record profile, but that | 294 // GetOffTheRecordProfile() may create a new off-the-record profile, but that |
| 485 // doesn't need to rebuild the groups. | 295 // doesn't need to rebuild the groups. |
| 486 if (type == chrome::NOTIFICATION_PROFILE_CREATED && | 296 if (type == chrome::NOTIFICATION_PROFILE_CREATED && |
| 487 content::Source<Profile>(source).ptr()->IsOffTheRecord()) { | 297 content::Source<Profile>(source).ptr()->IsOffTheRecord()) { |
| 488 return; | 298 return; |
| 489 } | 299 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 503 void MessageCenterSettingsController::OnProfileNameChanged( | 313 void MessageCenterSettingsController::OnProfileNameChanged( |
| 504 const base::FilePath& profile_path, | 314 const base::FilePath& profile_path, |
| 505 const base::string16& old_profile_name) { | 315 const base::string16& old_profile_name) { |
| 506 RebuildNotifierGroups(true); | 316 RebuildNotifierGroups(true); |
| 507 } | 317 } |
| 508 void MessageCenterSettingsController::OnProfileAuthInfoChanged( | 318 void MessageCenterSettingsController::OnProfileAuthInfoChanged( |
| 509 const base::FilePath& profile_path) { | 319 const base::FilePath& profile_path) { |
| 510 RebuildNotifierGroups(true); | 320 RebuildNotifierGroups(true); |
| 511 } | 321 } |
| 512 | 322 |
| 323 void MessageCenterSettingsController::OnIconImageUpdated( | |
| 324 const message_center::NotifierId& id, | |
| 325 const gfx::Image& image) { | |
| 326 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, observers_, | |
| 327 UpdateIconImage(id, image)); | |
| 328 } | |
| 329 | |
| 330 void MessageCenterSettingsController::OnNotifierEnabledChanged( | |
| 331 const message_center::NotifierId& id, | |
| 332 bool enabled) { | |
| 333 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, observers_, | |
| 334 NotifierEnabledChanged(id, enabled)); | |
| 335 } | |
| 336 | |
| 337 void MessageCenterSettingsController::DispatchNotifierGroupChanged() { | |
| 338 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, observers_, | |
| 339 NotifierGroupChanged()); | |
| 340 } | |
| 341 | |
| 513 #if defined(OS_CHROMEOS) | 342 #if defined(OS_CHROMEOS) |
| 514 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { | 343 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { |
| 515 // Already created. | 344 // Already created. |
| 516 if (!notifier_groups_.empty()) | 345 if (!notifier_groups_.empty()) |
| 517 return; | 346 return; |
| 518 | 347 |
| 519 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 348 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 520 // |notifier_groups_| can be empty in login screen too. | 349 // |notifier_groups_| can be empty in login screen too. |
| 521 if (!user_manager->IsLoggedInAsGuest()) | 350 if (!user_manager->IsLoggedInAsGuest()) |
| 522 return; | 351 return; |
| 523 | 352 |
| 524 user_manager::User* user = user_manager->GetActiveUser(); | 353 user_manager::User* user = user_manager->GetActiveUser(); |
| 525 Profile* profile = | 354 Profile* profile = |
| 526 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 355 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
| 527 DCHECK(profile); | 356 DCHECK(profile); |
| 528 | 357 |
| 529 std::unique_ptr<message_center::ProfileNotifierGroup> group( | 358 std::unique_ptr<message_center::ProfileNotifierGroup> group( |
| 530 new message_center::ProfileNotifierGroup( | 359 new message_center::ProfileNotifierGroup( |
| 531 gfx::Image(user->GetImage()), user->GetDisplayName(), | 360 gfx::Image(user->GetImage()), user->GetDisplayName(), |
| 532 user->GetDisplayName(), profile)); | 361 user->GetDisplayName(), profile)); |
| 533 | 362 |
| 534 notifier_groups_.push_back(std::move(group)); | 363 notifier_groups_.push_back(std::move(group)); |
| 535 | 364 DispatchNotifierGroupChanged(); |
| 536 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 537 observers_, | |
| 538 NotifierGroupChanged()); | |
| 539 } | 365 } |
| 540 #endif | 366 #endif |
| 541 | 367 |
| 542 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { | 368 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { |
| 543 notifier_groups_.clear(); | 369 notifier_groups_.clear(); |
| 544 current_notifier_group_ = 0; | 370 current_notifier_group_ = 0; |
| 545 | 371 |
| 546 std::vector<ProfileAttributesEntry*> entries = | 372 std::vector<ProfileAttributesEntry*> entries = |
| 547 profile_attributes_storage_.GetAllProfilesAttributes(); | 373 profile_attributes_storage_.GetAllProfilesAttributes(); |
| 548 for (const auto entry : entries) { | 374 for (const auto entry : entries) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 // another creating a primary profile, and causes an infinite loop. | 414 // another creating a primary profile, and causes an infinite loop. |
| 589 // Thus, it would be better to delay creating group for guest login. | 415 // Thus, it would be better to delay creating group for guest login. |
| 590 base::ThreadTaskRunnerHandle::Get()->PostTask( | 416 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 591 FROM_HERE, | 417 FROM_HERE, |
| 592 base::Bind( | 418 base::Bind( |
| 593 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, | 419 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, |
| 594 weak_factory_.GetWeakPtr())); | 420 weak_factory_.GetWeakPtr())); |
| 595 } | 421 } |
| 596 #endif | 422 #endif |
| 597 | 423 |
| 598 if (notify) { | 424 if (notify) |
| 599 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 425 DispatchNotifierGroupChanged(); |
| 600 observers_, | |
| 601 NotifierGroupChanged()); | |
| 602 } | |
| 603 } | 426 } |
| OLD | NEW |