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> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <unordered_set> | 14 #include <unordered_set> |
15 | 15 |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
| 21 #include "chrome/browser/notifications/notification_operation_common.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/features.h" | 23 #include "chrome/common/features.h" |
23 #include "content/public/browser/platform_notification_service.h" | 24 #include "content/public/browser/platform_notification_service.h" |
24 #include "content/public/common/persistent_notification_status.h" | 25 #include "content/public/common/persistent_notification_status.h" |
25 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 26 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
26 | 27 |
27 class NotificationDelegate; | 28 class NotificationDelegate; |
28 class NotificationDisplayService; | 29 class NotificationDisplayService; |
29 class ScopedKeepAlive; | 30 class ScopedKeepAlive; |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 class BrowserContext; | 33 class BrowserContext; |
33 struct NotificationResources; | 34 struct NotificationResources; |
34 } | 35 } |
35 | 36 |
36 namespace gcm { | 37 namespace gcm { |
37 class PushMessagingBrowserTest; | 38 class PushMessagingBrowserTest; |
38 } | 39 } |
39 | 40 |
40 // The platform notification service is the profile-agnostic entry point through | 41 // The platform notification service is the profile-agnostic entry point through |
41 // which Web Notifications can be controlled. | 42 // which Web Notifications can be controlled. |
42 class PlatformNotificationServiceImpl | 43 class PlatformNotificationServiceImpl |
43 : public content::PlatformNotificationService { | 44 : public content::PlatformNotificationService { |
44 public: | 45 public: |
45 // Things you can do to a notification. | |
46 enum NotificationOperation { | |
47 NOTIFICATION_CLICK, | |
48 NOTIFICATION_CLOSE, | |
49 NOTIFICATION_SETTINGS | |
50 }; | |
51 | |
52 // 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 |
53 // be called from any thread. | 47 // be called from any thread. |
54 static PlatformNotificationServiceImpl* GetInstance(); | 48 static PlatformNotificationServiceImpl* GetInstance(); |
55 | 49 |
56 // Load the profile corresponding to |profile_id| and perform the | |
57 // |operation| on the given notification once it has been loaded. | |
58 void ProcessPersistentNotificationOperation( | |
59 NotificationOperation operation, | |
60 const std::string& profile_id, | |
61 bool incognito, | |
62 const GURL& origin, | |
63 int64_t persistent_notification_id, | |
64 int action_index); | |
65 | |
66 // 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 |
67 // Service Worker associated with the registration will be started if | 51 // Service Worker associated with the registration will be started if |
68 // 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. |
69 void OnPersistentNotificationClick( | 53 void OnPersistentNotificationClick( |
70 content::BrowserContext* browser_context, | 54 content::BrowserContext* browser_context, |
71 int64_t persistent_notification_id, | 55 int64_t persistent_notification_id, |
72 const GURL& origin, | 56 const GURL& origin, |
73 int action_index); | 57 int action_index); |
74 | 58 |
75 // To be called when a persistent notification has been closed. The data | 59 // To be called when a persistent notification has been closed. The data |
76 // associated with the notification has to be pruned from the database in this | 60 // associated with the notification has to be pruned from the database in this |
77 // case, to make sure that it continues to be in sync. Must be called on the | 61 // case, to make sure that it continues to be in sync. Must be called on the |
78 // UI thread. | 62 // UI thread. |
79 void OnPersistentNotificationClose(content::BrowserContext* browser_context, | 63 void OnPersistentNotificationClose(content::BrowserContext* browser_context, |
80 int64_t persistent_notification_id, | 64 int64_t persistent_notification_id, |
81 const GURL& origin, | 65 const GURL& origin, |
82 bool by_user); | 66 bool by_user); |
83 | 67 |
84 | |
85 // Open the Notification settings screen when clicking the right button. | |
86 void OpenNotificationSettings(content::BrowserContext* browser_context); | |
87 | |
88 // content::PlatformNotificationService implementation. | 68 // content::PlatformNotificationService implementation. |
89 blink::mojom::PermissionStatus CheckPermissionOnUIThread( | 69 blink::mojom::PermissionStatus CheckPermissionOnUIThread( |
90 content::BrowserContext* browser_context, | 70 content::BrowserContext* browser_context, |
91 const GURL& origin, | 71 const GURL& origin, |
92 int render_process_id) override; | 72 int render_process_id) override; |
93 blink::mojom::PermissionStatus CheckPermissionOnIOThread( | 73 blink::mojom::PermissionStatus CheckPermissionOnIOThread( |
94 content::ResourceContext* resource_context, | 74 content::ResourceContext* resource_context, |
95 const GURL& origin, | 75 const GURL& origin, |
96 int render_process_id) override; | 76 int render_process_id) override; |
97 void DisplayNotification( | 77 void DisplayNotification( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // programmatically to avoid dispatching close events for them. | 155 // programmatically to avoid dispatching close events for them. |
176 std::unordered_set<int64_t> closed_notifications_; | 156 std::unordered_set<int64_t> closed_notifications_; |
177 | 157 |
178 // Only set and used for tests, owned by the caller in that case. | 158 // Only set and used for tests, owned by the caller in that case. |
179 NotificationDisplayService* test_display_service_; | 159 NotificationDisplayService* test_display_service_; |
180 | 160 |
181 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 161 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
182 }; | 162 }; |
183 | 163 |
184 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 164 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
OLD | NEW |