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_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 | 50 // Load the profile corresponding to |profile_id| and perform the |
57 // |operation| on the given notification once it has been loaded. | 51 // |operation| on the given notification once it has been loaded. |
58 void ProcessPersistentNotificationOperation( | 52 void ProcessPersistentNotificationOperation( |
59 NotificationOperation operation, | 53 NotificationCommon::Operation operation, |
60 const std::string& profile_id, | 54 const std::string& profile_id, |
61 bool incognito, | 55 bool incognito, |
62 const GURL& origin, | 56 const GURL& origin, |
63 int64_t persistent_notification_id, | 57 int64_t persistent_notification_id, |
64 int action_index); | 58 int action_index); |
65 | 59 |
66 // To be called when a persistent notification has been clicked on. The | 60 // To be called when a persistent notification has been clicked on. The |
67 // Service Worker associated with the registration will be started if | 61 // 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. | 62 // needed, on which the event will be fired. Must be called on the UI thread. |
69 void OnPersistentNotificationClick( | 63 void OnPersistentNotificationClick( |
70 content::BrowserContext* browser_context, | 64 content::BrowserContext* browser_context, |
71 int64_t persistent_notification_id, | 65 int64_t persistent_notification_id, |
72 const GURL& origin, | 66 const GURL& origin, |
73 int action_index); | 67 int action_index); |
74 | 68 |
75 // To be called when a persistent notification has been closed. The data | 69 // 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 | 70 // 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 | 71 // case, to make sure that it continues to be in sync. Must be called on the |
78 // UI thread. | 72 // UI thread. |
79 void OnPersistentNotificationClose(content::BrowserContext* browser_context, | 73 void OnPersistentNotificationClose(content::BrowserContext* browser_context, |
80 int64_t persistent_notification_id, | 74 int64_t persistent_notification_id, |
81 const GURL& origin, | 75 const GURL& origin, |
82 bool by_user); | 76 bool by_user); |
83 | 77 |
84 | |
85 // Open the Notification settings screen when clicking the right button. | |
86 void OpenNotificationSettings(content::BrowserContext* browser_context); | |
87 | |
88 // content::PlatformNotificationService implementation. | 78 // content::PlatformNotificationService implementation. |
89 blink::mojom::PermissionStatus CheckPermissionOnUIThread( | 79 blink::mojom::PermissionStatus CheckPermissionOnUIThread( |
90 content::BrowserContext* browser_context, | 80 content::BrowserContext* browser_context, |
91 const GURL& origin, | 81 const GURL& origin, |
92 int render_process_id) override; | 82 int render_process_id) override; |
93 blink::mojom::PermissionStatus CheckPermissionOnIOThread( | 83 blink::mojom::PermissionStatus CheckPermissionOnIOThread( |
94 content::ResourceContext* resource_context, | 84 content::ResourceContext* resource_context, |
95 const GURL& origin, | 85 const GURL& origin, |
96 int render_process_id) override; | 86 int render_process_id) override; |
97 void DisplayNotification( | 87 void DisplayNotification( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // programmatically to avoid dispatching close events for them. | 165 // programmatically to avoid dispatching close events for them. |
176 std::unordered_set<int64_t> closed_notifications_; | 166 std::unordered_set<int64_t> closed_notifications_; |
177 | 167 |
178 // Only set and used for tests, owned by the caller in that case. | 168 // Only set and used for tests, owned by the caller in that case. |
179 NotificationDisplayService* test_display_service_; | 169 NotificationDisplayService* test_display_service_; |
180 | 170 |
181 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 171 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
182 }; | 172 }; |
183 | 173 |
184 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 174 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
OLD | NEW |