Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 17 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 18 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 18 #include "chrome/browser/notifications/notification_object_proxy.h" | 19 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 19 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 20 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 21 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_io_data.h" | 23 #include "chrome/browser/profiles/profile_io_data.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 47 #if defined(ENABLE_EXTENSIONS) | 48 #if defined(ENABLE_EXTENSIONS) |
| 48 #include "chrome/browser/notifications/notifier_state_tracker.h" | 49 #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 49 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 50 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| 50 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
| 51 #include "extensions/browser/info_map.h" | 52 #include "extensions/browser/info_map.h" |
| 52 #include "extensions/common/constants.h" | 53 #include "extensions/common/constants.h" |
| 53 #include "extensions/common/permissions/api_permission.h" | 54 #include "extensions/common/permissions/api_permission.h" |
| 54 #include "extensions/common/permissions/permissions_data.h" | 55 #include "extensions/common/permissions/permissions_data.h" |
| 55 #endif | 56 #endif |
| 56 | 57 |
| 57 #if defined(OS_ANDROID) | |
| 58 #include "base/strings/string_number_conversions.h" | |
| 59 #endif | |
| 60 | |
| 61 using content::BrowserContext; | 58 using content::BrowserContext; |
| 62 using content::BrowserThread; | 59 using content::BrowserThread; |
| 63 using content::PlatformNotificationContext; | 60 using content::PlatformNotificationContext; |
| 64 using message_center::NotifierId; | 61 using message_center::NotifierId; |
| 65 | 62 |
| 66 namespace { | 63 namespace { |
| 67 | 64 |
| 68 // Invalid id for a renderer process. Used in cases where we need to check for | 65 // Invalid id for a renderer process. Used in cases where we need to check for |
| 69 // permission without having an associated renderer process yet. | 66 // permission without having an associated renderer process yet. |
| 70 const int kInvalidRenderProcessId = -1; | 67 const int kInvalidRenderProcessId = -1; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 92 | 89 |
| 93 } // namespace | 90 } // namespace |
| 94 | 91 |
| 95 // static | 92 // static |
| 96 PlatformNotificationServiceImpl* | 93 PlatformNotificationServiceImpl* |
| 97 PlatformNotificationServiceImpl::GetInstance() { | 94 PlatformNotificationServiceImpl::GetInstance() { |
| 98 return base::Singleton<PlatformNotificationServiceImpl>::get(); | 95 return base::Singleton<PlatformNotificationServiceImpl>::get(); |
| 99 } | 96 } |
| 100 | 97 |
| 101 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() | 98 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
| 102 : notification_ui_manager_for_tests_(nullptr) {} | 99 : notification_ui_manager_for_tests_(nullptr) { |
| 100 #if defined(OS_MACOSX) | |
| 101 native_notification_ui_manager_.reset( | |
| 102 NotificationUIManager::CreateNativeNotificationManager()); | |
|
Peter Beverloo
2016/01/08 05:14:26
Could you revert the changes to notification_ui_ma
Miguel Garcia
2016/01/08 11:46:55
So the problem with doing it the way you suggest i
Peter Beverloo
2016/01/08 19:40:19
This is a good point. Looking at various other fil
| |
| 103 #endif | |
| 104 } | |
| 103 | 105 |
| 104 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 106 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
| 105 | 107 |
| 106 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 108 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 107 BrowserContext* browser_context, | 109 BrowserContext* browser_context, |
| 108 int64_t persistent_notification_id, | 110 int64_t persistent_notification_id, |
| 109 const GURL& origin, | 111 const GURL& origin, |
| 110 int action_index) { | 112 int action_index) { |
| 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 112 blink::WebNotificationPermission permission = | 114 blink::WebNotificationPermission permission = |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 BrowserContext* browser_context, | 331 BrowserContext* browser_context, |
| 330 int64_t persistent_notification_id) { | 332 int64_t persistent_notification_id) { |
| 331 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 332 | 334 |
| 333 Profile* profile = Profile::FromBrowserContext(browser_context); | 335 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 334 DCHECK(profile); | 336 DCHECK(profile); |
| 335 | 337 |
| 336 #if defined(OS_ANDROID) | 338 #if defined(OS_ANDROID) |
| 337 // TODO(peter): Remove this conversion when the notification ids are being | 339 // TODO(peter): Remove this conversion when the notification ids are being |
| 338 // generated by the caller of this method. | 340 // generated by the caller of this method. |
| 339 std::string textual_persistent_notification_id = | |
| 340 base::Int64ToString(persistent_notification_id); | |
| 341 GetNotificationUIManager()->CancelById( | 341 GetNotificationUIManager()->CancelById( |
| 342 textual_persistent_notification_id, | 342 base::Int64ToString(persistent_notification_id), |
|
Peter Beverloo
2016/01/08 05:14:26
I very badly need to clean this up :-(.
Per the p
Miguel Garcia
2016/01/08 11:46:55
Done.
| |
| 343 NotificationUIManager::GetProfileID(profile)); | 343 NotificationUIManager::GetProfileID(profile)); |
| 344 #else | 344 #else |
| 345 if (native_notification_ui_manager_ && | |
| 346 native_notification_ui_manager_->AcceptNativeNotifications()) { | |
| 347 GetNotificationUIManager()->CancelById( | |
| 348 base::Int64ToString(persistent_notification_id), | |
| 349 NotificationUIManager::GetProfileID(profile)); | |
| 350 } | |
| 351 | |
| 345 auto iter = persistent_notifications_.find(persistent_notification_id); | 352 auto iter = persistent_notifications_.find(persistent_notification_id); |
| 346 if (iter == persistent_notifications_.end()) | 353 if (iter == persistent_notifications_.end()) |
| 347 return; | 354 return; |
| 348 | 355 |
| 349 GetNotificationUIManager()->CancelById( | 356 GetNotificationUIManager()->CancelById( |
| 350 iter->second, NotificationUIManager::GetProfileID(profile)); | 357 iter->second, NotificationUIManager::GetProfileID(profile)); |
| 351 | 358 |
| 352 persistent_notifications_.erase(iter); | 359 persistent_notifications_.erase(iter); |
| 353 #endif | 360 #endif |
| 354 } | 361 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 notification.set_never_timeout(true); | 426 notification.set_never_timeout(true); |
| 420 | 427 |
| 421 return notification; | 428 return notification; |
| 422 } | 429 } |
| 423 | 430 |
| 424 NotificationUIManager* | 431 NotificationUIManager* |
| 425 PlatformNotificationServiceImpl::GetNotificationUIManager() const { | 432 PlatformNotificationServiceImpl::GetNotificationUIManager() const { |
| 426 if (notification_ui_manager_for_tests_) | 433 if (notification_ui_manager_for_tests_) |
| 427 return notification_ui_manager_for_tests_; | 434 return notification_ui_manager_for_tests_; |
| 428 | 435 |
| 436 if (native_notification_ui_manager_ && | |
| 437 native_notification_ui_manager_->AcceptNativeNotifications()) { | |
| 438 return native_notification_ui_manager_.get(); | |
| 439 } | |
| 440 | |
| 429 return g_browser_process->notification_ui_manager(); | 441 return g_browser_process->notification_ui_manager(); |
| 430 } | 442 } |
| 431 | 443 |
| 432 void PlatformNotificationServiceImpl::OpenNotificationSettings( | 444 void PlatformNotificationServiceImpl::OpenNotificationSettings( |
| 433 BrowserContext* browser_context) { | 445 BrowserContext* browser_context) { |
| 434 #if defined(OS_ANDROID) | 446 #if defined(OS_ANDROID) |
| 435 NOTIMPLEMENTED(); | 447 NOTIMPLEMENTED(); |
| 436 #else | 448 #else |
| 437 | 449 |
| 438 Profile* profile = Profile::FromBrowserContext(browser_context); | 450 Profile* profile = Profile::FromBrowserContext(browser_context); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 466 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 478 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 467 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 479 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 468 DCHECK(extension); | 480 DCHECK(extension); |
| 469 | 481 |
| 470 return base::UTF8ToUTF16(extension->name()); | 482 return base::UTF8ToUTF16(extension->name()); |
| 471 } | 483 } |
| 472 #endif | 484 #endif |
| 473 | 485 |
| 474 return base::string16(); | 486 return base::string16(); |
| 475 } | 487 } |
| OLD | NEW |