| 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 | 35 // To be called when a persistent notification has been clicked on. The |
| 33 // Service Worker associated with the registration will be started if | 36 // 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. | 37 // needed, on which the event will be fired. Must be called on the UI thread. |
| 35 void OnPersistentNotificationClick( | 38 void OnPersistentNotificationClick( |
| 36 content::BrowserContext* browser_context, | 39 content::BrowserContext* browser_context, |
| 37 int64 service_worker_registration_id, | 40 int64_t persistent_notification_id, |
| 38 const std::string& notification_id, | |
| 39 const GURL& origin, | 41 const GURL& origin, |
| 40 const content::PlatformNotificationData& notification_data, | |
| 41 const base::Callback<void(content::PersistentNotificationStatus)>& | 42 const base::Callback<void(content::PersistentNotificationStatus)>& |
| 42 callback) const; | 43 callback) const; |
| 43 | 44 |
| 44 // Returns the Notification UI Manager through which notifications can be | 45 // Returns the Notification UI Manager through which notifications can be |
| 45 // displayed to the user. Can be overridden for testing. | 46 // displayed to the user. Can be overridden for testing. |
| 46 NotificationUIManager* GetNotificationUIManager() const; | 47 NotificationUIManager* GetNotificationUIManager() const; |
| 47 | 48 |
| 48 // content::PlatformNotificationService implementation. | 49 // content::PlatformNotificationService implementation. |
| 49 blink::WebNotificationPermission CheckPermissionOnUIThread( | 50 blink::WebNotificationPermission CheckPermissionOnUIThread( |
| 50 content::BrowserContext* browser_context, | 51 content::BrowserContext* browser_context, |
| 51 const GURL& origin, | 52 const GURL& origin, |
| 52 int render_process_id) override; | 53 int render_process_id) override; |
| 53 blink::WebNotificationPermission CheckPermissionOnIOThread( | 54 blink::WebNotificationPermission CheckPermissionOnIOThread( |
| 54 content::ResourceContext* resource_context, | 55 content::ResourceContext* resource_context, |
| 55 const GURL& origin, | 56 const GURL& origin, |
| 56 int render_process_id) override; | 57 int render_process_id) override; |
| 57 void DisplayNotification( | 58 void DisplayNotification( |
| 58 content::BrowserContext* browser_context, | 59 content::BrowserContext* browser_context, |
| 59 const GURL& origin, | 60 const GURL& origin, |
| 60 const SkBitmap& icon, | 61 const SkBitmap& icon, |
| 61 const content::PlatformNotificationData& notification_data, | 62 const content::PlatformNotificationData& notification_data, |
| 62 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 63 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 63 base::Closure* cancel_callback) override; | 64 base::Closure* cancel_callback) override; |
| 64 void DisplayPersistentNotification( | 65 void DisplayPersistentNotification( |
| 65 content::BrowserContext* browser_context, | 66 content::BrowserContext* browser_context, |
| 66 int64 service_worker_registration_id, | 67 int64_t persistent_notification_id, |
| 67 const GURL& origin, | 68 const GURL& origin, |
| 68 const SkBitmap& icon, | 69 const SkBitmap& icon, |
| 69 const content::PlatformNotificationData& notification_data) override; | 70 const content::PlatformNotificationData& notification_data) override; |
| 70 void ClosePersistentNotification( | 71 void ClosePersistentNotification( |
| 71 content::BrowserContext* browser_context, | 72 content::BrowserContext* browser_context, |
| 72 const std::string& persistent_notification_id) override; | 73 int64_t persistent_notification_id) override; |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>; | 76 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>; |
| 76 friend class PlatformNotificationServiceBrowserTest; | 77 friend class PlatformNotificationServiceBrowserTest; |
| 77 friend class PlatformNotificationServiceTest; | 78 friend class PlatformNotificationServiceTest; |
| 78 friend class PushMessagingBrowserTest; | 79 friend class PushMessagingBrowserTest; |
| 79 FRIEND_TEST_ALL_PREFIXES( | 80 FRIEND_TEST_ALL_PREFIXES( |
| 80 PlatformNotificationServiceTest, DisplayNameForOrigin); | 81 PlatformNotificationServiceTest, DisplayNameForOrigin); |
| 81 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, | 82 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, |
| 82 TestWebOriginDisplayName); | 83 TestWebOriginDisplayName); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 // Translates a URL into a slightly more readable version that may omit | 108 // Translates a URL into a slightly more readable version that may omit |
| 108 // the port and scheme for common cases. | 109 // the port and scheme for common cases. |
| 109 // TODO(dewittj): Remove this when the proper function is implemented in a | 110 // TODO(dewittj): Remove this when the proper function is implemented in a |
| 110 // chrome/browser/ui library function. See crbug.com/402698. | 111 // chrome/browser/ui library function. See crbug.com/402698. |
| 111 static base::string16 WebOriginDisplayName(const GURL& origin, | 112 static base::string16 WebOriginDisplayName(const GURL& origin, |
| 112 const std::string& languages); | 113 const std::string& languages); |
| 113 | 114 |
| 114 // Weak reference. Ownership maintains with the test. | 115 // Weak reference. Ownership maintains with the test. |
| 115 NotificationUIManager* notification_ui_manager_for_tests_; | 116 NotificationUIManager* notification_ui_manager_for_tests_; |
| 116 | 117 |
| 118 // Mapping between a persistent notification id and the id of the associated |
| 119 // message_center::Notification object. |
| 120 std::map<int64_t, std::string> persistent_notifications_; |
| 121 |
| 117 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 122 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 125 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| OLD | NEW |