| 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 #include <map> |
| 10 |
| 8 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 10 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
| 12 #include "content/public/browser/platform_notification_service.h" | 15 #include "content/public/browser/platform_notification_service.h" |
| 13 #include "content/public/common/persistent_notification_status.h" | 16 #include "content/public/common/persistent_notification_status.h" |
| 14 | 17 |
| 15 class NotificationDelegate; | 18 class NotificationDelegate; |
| 16 class NotificationUIManager; | 19 class NotificationUIManager; |
| 17 class Profile; | 20 class Profile; |
| 18 | 21 |
| 19 namespace gcm { | 22 namespace gcm { |
| 20 class PushMessagingBrowserTest; | 23 class PushMessagingBrowserTest; |
| 21 } | 24 } |
| 22 | 25 |
| 23 // The platform notification service is the profile-agnostic entry point through | 26 // The platform notification service is the profile-agnostic entry point through |
| 24 // which Web Notifications can be controlled. | 27 // which Web Notifications can be controlled. |
| 25 class PlatformNotificationServiceImpl | 28 class PlatformNotificationServiceImpl |
| 26 : public content::PlatformNotificationService { | 29 : public content::PlatformNotificationService { |
| 27 public: | 30 public: |
| 28 // Returns the active instance of the service in the browser process. Safe to | 31 // Returns the active instance of the service in the browser process. Safe to |
| 29 // be called from any thread. | 32 // be called from any thread. |
| 30 static PlatformNotificationServiceImpl* GetInstance(); | 33 static PlatformNotificationServiceImpl* GetInstance(); |
| 31 | 34 |
| 32 // To be called when a persistent notification has been clicked on. The | |
| 33 // Service Worker associated with the registration will be started if | |
| 34 // needed, on which the event will be fired. Must be called on the UI thread. | |
| 35 void OnPersistentNotificationClick( | |
| 36 content::BrowserContext* browser_context, | |
| 37 int64 service_worker_registration_id, | |
| 38 const std::string& notification_id, | |
| 39 const GURL& origin, | |
| 40 const content::PlatformNotificationData& notification_data, | |
| 41 const base::Callback<void(content::PersistentNotificationStatus)>& | |
| 42 callback) const; | |
| 43 | |
| 44 // Returns the Notification UI Manager through which notifications can be | 35 // Returns the Notification UI Manager through which notifications can be |
| 45 // displayed to the user. Can be overridden for testing. | 36 // displayed to the user. Can be overridden for testing. |
| 46 NotificationUIManager* GetNotificationUIManager() const; | 37 NotificationUIManager* GetNotificationUIManager() const; |
| 47 | 38 |
| 48 // content::PlatformNotificationService implementation. | 39 // content::PlatformNotificationService implementation. |
| 49 blink::WebNotificationPermission CheckPermissionOnUIThread( | 40 blink::WebNotificationPermission CheckPermissionOnUIThread( |
| 50 content::BrowserContext* browser_context, | 41 content::BrowserContext* browser_context, |
| 51 const GURL& origin, | 42 const GURL& origin, |
| 52 int render_process_id) override; | 43 int render_process_id) override; |
| 53 blink::WebNotificationPermission CheckPermissionOnIOThread( | 44 blink::WebNotificationPermission CheckPermissionOnIOThread( |
| 54 content::ResourceContext* resource_context, | 45 content::ResourceContext* resource_context, |
| 55 const GURL& origin, | 46 const GURL& origin, |
| 56 int render_process_id) override; | 47 int render_process_id) override; |
| 57 void DisplayNotification( | 48 void DisplayNotification( |
| 58 content::BrowserContext* browser_context, | 49 content::BrowserContext* browser_context, |
| 59 const GURL& origin, | 50 const GURL& origin, |
| 60 const SkBitmap& icon, | 51 const SkBitmap& icon, |
| 61 const content::PlatformNotificationData& notification_data, | 52 const content::PlatformNotificationData& notification_data, |
| 62 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 53 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 63 base::Closure* cancel_callback) override; | 54 base::Closure* cancel_callback) override; |
| 64 void DisplayPersistentNotification( | 55 void DisplayPersistentNotification( |
| 65 content::BrowserContext* browser_context, | 56 content::BrowserContext* browser_context, |
| 66 int64 service_worker_registration_id, | 57 int64_t persistent_notification_id, |
| 67 const GURL& origin, | 58 const GURL& origin, |
| 68 const SkBitmap& icon, | 59 const SkBitmap& icon, |
| 69 const content::PlatformNotificationData& notification_data) override; | 60 const content::PlatformNotificationData& notification_data) override; |
| 70 void ClosePersistentNotification( | 61 void ClosePersistentNotification( |
| 71 content::BrowserContext* browser_context, | 62 content::BrowserContext* browser_context, |
| 72 const std::string& persistent_notification_id) override; | 63 int64_t persistent_notification_id) override; |
| 73 | 64 |
| 74 private: | 65 private: |
| 75 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>; | 66 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>; |
| 76 friend class PlatformNotificationServiceBrowserTest; | 67 friend class PlatformNotificationServiceBrowserTest; |
| 77 friend class PlatformNotificationServiceTest; | 68 friend class PlatformNotificationServiceTest; |
| 78 friend class PushMessagingBrowserTest; | 69 friend class PushMessagingBrowserTest; |
| 79 FRIEND_TEST_ALL_PREFIXES( | 70 FRIEND_TEST_ALL_PREFIXES( |
| 80 PlatformNotificationServiceTest, DisplayNameForOrigin); | 71 PlatformNotificationServiceTest, DisplayNameForOrigin); |
| 81 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, | 72 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, |
| 82 TestWebOriginDisplayName); | 73 TestWebOriginDisplayName); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 // Translates a URL into a slightly more readable version that may omit | 98 // Translates a URL into a slightly more readable version that may omit |
| 108 // the port and scheme for common cases. | 99 // the port and scheme for common cases. |
| 109 // TODO(dewittj): Remove this when the proper function is implemented in a | 100 // TODO(dewittj): Remove this when the proper function is implemented in a |
| 110 // chrome/browser/ui library function. See crbug.com/402698. | 101 // chrome/browser/ui library function. See crbug.com/402698. |
| 111 static base::string16 WebOriginDisplayName(const GURL& origin, | 102 static base::string16 WebOriginDisplayName(const GURL& origin, |
| 112 const std::string& languages); | 103 const std::string& languages); |
| 113 | 104 |
| 114 // Weak reference. Ownership maintains with the test. | 105 // Weak reference. Ownership maintains with the test. |
| 115 NotificationUIManager* notification_ui_manager_for_tests_; | 106 NotificationUIManager* notification_ui_manager_for_tests_; |
| 116 | 107 |
| 108 // Mapping between a persistent notification id and the id of the associated |
| 109 // message_center::Notification object. Must only be used on the UI thread. |
| 110 std::map<int64_t, std::string> persistent_notifications_; |
| 111 |
| 117 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 112 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
| 118 }; | 113 }; |
| 119 | 114 |
| 120 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 115 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| OLD | NEW |