| 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> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 class PlatformNotificationServiceImpl | 43 class PlatformNotificationServiceImpl |
| 44 : public content::PlatformNotificationService { | 44 : public content::PlatformNotificationService { |
| 45 public: | 45 public: |
| 46 // Returns the active instance of the service in the browser process. Safe to | 46 // Returns the active instance of the service in the browser process. Safe to |
| 47 // be called from any thread. | 47 // be called from any thread. |
| 48 static PlatformNotificationServiceImpl* GetInstance(); | 48 static PlatformNotificationServiceImpl* GetInstance(); |
| 49 | 49 |
| 50 // To be called when a persistent notification has been clicked on. The | 50 // To be called when a persistent notification has been clicked on. The |
| 51 // Service Worker associated with the registration will be started if | 51 // Service Worker associated with the registration will be started if |
| 52 // needed, on which the event will be fired. Must be called on the UI thread. | 52 // needed, on which the event will be fired. Must be called on the UI thread. |
| 53 void OnPersistentNotificationClick( | 53 void OnPersistentNotificationClick(content::BrowserContext* browser_context, |
| 54 content::BrowserContext* browser_context, | 54 const std::string& notification_id, |
| 55 int64_t persistent_notification_id, | 55 const GURL& origin, |
| 56 const GURL& origin, | 56 int action_index); |
| 57 int action_index); | |
| 58 | 57 |
| 59 // To be called when a persistent notification has been closed. The data | 58 // To be called when a persistent notification has been closed. The data |
| 60 // associated with the notification has to be pruned from the database in this | 59 // associated with the notification has to be pruned from the database in this |
| 61 // case, to make sure that it continues to be in sync. Must be called on the | 60 // case, to make sure that it continues to be in sync. Must be called on the |
| 62 // UI thread. | 61 // UI thread. |
| 63 void OnPersistentNotificationClose(content::BrowserContext* browser_context, | 62 void OnPersistentNotificationClose(content::BrowserContext* browser_context, |
| 64 int64_t persistent_notification_id, | 63 const std::string& notification_id, |
| 65 const GURL& origin, | 64 const GURL& origin, |
| 66 bool by_user); | 65 bool by_user); |
| 67 | 66 |
| 68 // content::PlatformNotificationService implementation. | 67 // content::PlatformNotificationService implementation. |
| 69 blink::mojom::PermissionStatus CheckPermissionOnUIThread( | 68 blink::mojom::PermissionStatus CheckPermissionOnUIThread( |
| 70 content::BrowserContext* browser_context, | 69 content::BrowserContext* browser_context, |
| 71 const GURL& origin, | 70 const GURL& origin, |
| 72 int render_process_id) override; | 71 int render_process_id) override; |
| 73 blink::mojom::PermissionStatus CheckPermissionOnIOThread( | 72 blink::mojom::PermissionStatus CheckPermissionOnIOThread( |
| 74 content::ResourceContext* resource_context, | 73 content::ResourceContext* resource_context, |
| 75 const GURL& origin, | 74 const GURL& origin, |
| 76 int render_process_id) override; | 75 int render_process_id) override; |
| 77 void DisplayNotification( | 76 void DisplayNotification( |
| 78 content::BrowserContext* browser_context, | 77 content::BrowserContext* browser_context, |
| 78 const std::string& notification_id, |
| 79 const GURL& origin, | 79 const GURL& origin, |
| 80 const content::PlatformNotificationData& notification_data, | 80 const content::PlatformNotificationData& notification_data, |
| 81 const content::NotificationResources& notification_resources, | 81 const content::NotificationResources& notification_resources, |
| 82 std::unique_ptr<content::DesktopNotificationDelegate> delegate, | 82 std::unique_ptr<content::DesktopNotificationDelegate> delegate, |
| 83 base::Closure* cancel_callback) override; | 83 base::Closure* cancel_callback) override; |
| 84 void DisplayPersistentNotification( | 84 void DisplayPersistentNotification( |
| 85 content::BrowserContext* browser_context, | 85 content::BrowserContext* browser_context, |
| 86 int64_t persistent_notification_id, | 86 const std::string& notification_id, |
| 87 const GURL& service_worker_scope, | 87 const GURL& service_worker_scope, |
| 88 const GURL& origin, | 88 const GURL& origin, |
| 89 const content::PlatformNotificationData& notification_data, | 89 const content::PlatformNotificationData& notification_data, |
| 90 const content::NotificationResources& notification_resources) override; | 90 const content::NotificationResources& notification_resources) override; |
| 91 void ClosePersistentNotification( | 91 void ClosePersistentNotification(content::BrowserContext* browser_context, |
| 92 content::BrowserContext* browser_context, | 92 const std::string& notification_id) override; |
| 93 int64_t persistent_notification_id) override; | |
| 94 bool GetDisplayedPersistentNotifications( | 93 bool GetDisplayedPersistentNotifications( |
| 95 content::BrowserContext* browser_context, | 94 content::BrowserContext* browser_context, |
| 96 std::set<std::string>* displayed_notifications) override; | 95 std::set<std::string>* displayed_notifications) override; |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 friend struct base::DefaultSingletonTraits<PlatformNotificationServiceImpl>; | 98 friend struct base::DefaultSingletonTraits<PlatformNotificationServiceImpl>; |
| 100 friend class PlatformNotificationServiceBrowserTest; | 99 friend class PlatformNotificationServiceBrowserTest; |
| 101 friend class PlatformNotificationServiceTest; | 100 friend class PlatformNotificationServiceTest; |
| 102 friend class PushMessagingBrowserTest; | 101 friend class PushMessagingBrowserTest; |
| 103 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, | 102 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 #if BUILDFLAG(ENABLE_BACKGROUND) | 141 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 143 // Makes sure we keep the browser alive while the event in being processed. | 142 // Makes sure we keep the browser alive while the event in being processed. |
| 144 // As we have no control on the click handling, the notification could be | 143 // As we have no control on the click handling, the notification could be |
| 145 // closed before a browser is brought up, thus terminating Chrome if it was | 144 // closed before a browser is brought up, thus terminating Chrome if it was |
| 146 // the last KeepAlive. (see https://crbug.com/612815) | 145 // the last KeepAlive. (see https://crbug.com/612815) |
| 147 std::unique_ptr<ScopedKeepAlive> click_dispatch_keep_alive_; | 146 std::unique_ptr<ScopedKeepAlive> click_dispatch_keep_alive_; |
| 148 | 147 |
| 149 int pending_click_dispatch_events_; | 148 int pending_click_dispatch_events_; |
| 150 #endif | 149 #endif |
| 151 | 150 |
| 152 // Mapping between a persistent notification id and the id of the associated | |
| 153 // message_center::Notification object. Must only be used on the UI thread. | |
| 154 std::map<int64_t, std::string> persistent_notifications_; | |
| 155 | |
| 156 // Tracks the id of persistent notifications that have been closed | 151 // Tracks the id of persistent notifications that have been closed |
| 157 // programmatically to avoid dispatching close events for them. | 152 // programmatically to avoid dispatching close events for them. |
| 158 std::unordered_set<int64_t> closed_notifications_; | 153 std::unordered_set<std::string> closed_notifications_; |
| 159 | 154 |
| 160 // Only set and used for tests, owned by the caller in that case. | 155 // Only set and used for tests, owned by the caller in that case. |
| 161 NotificationDisplayService* test_display_service_; | 156 NotificationDisplayService* test_display_service_; |
| 162 | 157 |
| 163 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 158 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
| 164 }; | 159 }; |
| 165 | 160 |
| 166 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 161 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| OLD | NEW |