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_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ |
6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "chrome/browser/background/background_trigger.h" | 18 #include "chrome/browser/background/background_trigger.h" |
19 #include "components/content_settings/core/browser/content_settings_observer.h" | 19 #include "components/content_settings/core/browser/content_settings_observer.h" |
20 #include "components/content_settings/core/common/content_settings.h" | 20 #include "components/content_settings/core/common/content_settings.h" |
21 #include "components/gcm_driver/common/gcm_messages.h" | 21 #include "components/gcm_driver/common/gcm_messages.h" |
22 #include "components/gcm_driver/gcm_app_handler.h" | 22 #include "components/gcm_driver/gcm_app_handler.h" |
23 #include "components/gcm_driver/gcm_client.h" | 23 #include "components/gcm_driver/instance_id/instance_id.h" |
24 #include "components/keyed_service/core/keyed_service.h" | 24 #include "components/keyed_service/core/keyed_service.h" |
25 #include "content/public/browser/push_messaging_service.h" | 25 #include "content/public/browser/push_messaging_service.h" |
26 #include "content/public/common/push_event_payload.h" | 26 #include "content/public/common/push_event_payload.h" |
27 #include "content/public/common/push_messaging_status.h" | 27 #include "content/public/common/push_messaging_status.h" |
28 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 28 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
29 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" | 29 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" |
30 | 30 |
31 #if defined(ENABLE_NOTIFICATIONS) | 31 #if defined(ENABLE_NOTIFICATIONS) |
32 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" | 32 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
33 #endif | 33 #endif |
34 | 34 |
35 class Profile; | 35 class Profile; |
36 class PushMessagingAppIdentifier; | 36 class PushMessagingAppIdentifier; |
37 class PushMessagingServiceObserver; | 37 class PushMessagingServiceObserver; |
38 struct PushSubscriptionOptions; | 38 struct PushSubscriptionOptions; |
39 | 39 |
40 namespace gcm { | 40 namespace gcm { |
41 class GCMDriver; | 41 class GCMDriver; |
42 class GCMProfileService; | 42 } |
| 43 namespace instance_id { |
| 44 class InstanceIDDriver; |
43 } | 45 } |
44 | 46 |
45 namespace user_prefs { | 47 namespace user_prefs { |
46 class PrefRegistrySyncable; | 48 class PrefRegistrySyncable; |
47 } | 49 } |
48 | 50 |
49 class PushMessagingServiceImpl : public content::PushMessagingService, | 51 class PushMessagingServiceImpl : public content::PushMessagingService, |
50 public gcm::GCMAppHandler, | 52 public gcm::GCMAppHandler, |
51 public content_settings::Observer, | 53 public content_settings::Observer, |
52 public KeyedService, | 54 public KeyedService, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 const content::PushSubscriptionOptions& options, | 87 const content::PushSubscriptionOptions& options, |
86 const content::PushMessagingService::RegisterCallback& callback) override; | 88 const content::PushMessagingService::RegisterCallback& callback) override; |
87 void GetEncryptionInfo( | 89 void GetEncryptionInfo( |
88 const GURL& origin, | 90 const GURL& origin, |
89 int64_t service_worker_registration_id, | 91 int64_t service_worker_registration_id, |
90 const content::PushMessagingService::EncryptionInfoCallback& callback) | 92 const content::PushMessagingService::EncryptionInfoCallback& callback) |
91 override; | 93 override; |
92 void Unsubscribe( | 94 void Unsubscribe( |
93 const GURL& requesting_origin, | 95 const GURL& requesting_origin, |
94 int64_t service_worker_registration_id, | 96 int64_t service_worker_registration_id, |
95 const std::string& sender_id, | |
96 const content::PushMessagingService::UnregisterCallback&) override; | 97 const content::PushMessagingService::UnregisterCallback&) override; |
97 blink::WebPushPermissionStatus GetPermissionStatus( | 98 blink::WebPushPermissionStatus GetPermissionStatus( |
98 const GURL& origin, | 99 const GURL& origin, |
99 bool user_visible) override; | 100 bool user_visible) override; |
100 bool SupportNonVisibleMessages() override; | 101 bool SupportNonVisibleMessages() override; |
101 | 102 |
102 // content_settings::Observer implementation. | 103 // content_settings::Observer implementation. |
103 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 104 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
104 const ContentSettingsPattern& secondary_pattern, | 105 const ContentSettingsPattern& secondary_pattern, |
105 ContentSettingsType content_type, | 106 ContentSettingsType content_type, |
(...skipping 26 matching lines...) Expand all Loading... |
132 int64_t service_worker_registration_id, | 133 int64_t service_worker_registration_id, |
133 const gcm::IncomingMessage& message, | 134 const gcm::IncomingMessage& message, |
134 const base::Closure& message_handled_closure, | 135 const base::Closure& message_handled_closure, |
135 content::PushDeliveryStatus status); | 136 content::PushDeliveryStatus status); |
136 | 137 |
137 void DidHandleMessage(const std::string& app_id, | 138 void DidHandleMessage(const std::string& app_id, |
138 const base::Closure& completion_closure); | 139 const base::Closure& completion_closure); |
139 | 140 |
140 // Subscribe methods --------------------------------------------------------- | 141 // Subscribe methods --------------------------------------------------------- |
141 | 142 |
| 143 void DoSubscribe( |
| 144 const PushMessagingAppIdentifier& app_identifier, |
| 145 const content::PushSubscriptionOptions& options, |
| 146 const content::PushMessagingService::RegisterCallback& callback, |
| 147 blink::mojom::PermissionStatus permission_status); |
| 148 |
142 void SubscribeEnd( | 149 void SubscribeEnd( |
143 const content::PushMessagingService::RegisterCallback& callback, | 150 const content::PushMessagingService::RegisterCallback& callback, |
144 const std::string& subscription_id, | 151 const std::string& subscription_id, |
145 const std::vector<uint8_t>& p256dh, | 152 const std::vector<uint8_t>& p256dh, |
146 const std::vector<uint8_t>& auth, | 153 const std::vector<uint8_t>& auth, |
147 content::PushRegistrationStatus status); | 154 content::PushRegistrationStatus status); |
148 | 155 |
149 void SubscribeEndWithError( | 156 void SubscribeEndWithError( |
150 const content::PushMessagingService::RegisterCallback& callback, | 157 const content::PushMessagingService::RegisterCallback& callback, |
151 content::PushRegistrationStatus status); | 158 content::PushRegistrationStatus status); |
152 | 159 |
153 void DidSubscribe( | 160 void DidSubscribe( |
154 const PushMessagingAppIdentifier& app_identifier, | 161 const PushMessagingAppIdentifier& app_identifier, |
155 const content::PushMessagingService::RegisterCallback& callback, | 162 const content::PushMessagingService::RegisterCallback& callback, |
156 const std::string& subscription_id, | 163 const std::string& subscription_id, |
157 gcm::GCMClient::Result result); | 164 instance_id::InstanceID::Result result); |
158 | 165 |
159 void DidSubscribeWithEncryptionInfo( | 166 void DidSubscribeWithEncryptionInfo( |
160 const PushMessagingAppIdentifier& app_identifier, | 167 const PushMessagingAppIdentifier& app_identifier, |
161 const content::PushMessagingService::RegisterCallback& callback, | 168 const content::PushMessagingService::RegisterCallback& callback, |
162 const std::string& subscription_id, | 169 const std::string& subscription_id, |
163 const std::string& p256dh, | 170 const std::string& p256dh, |
164 const std::string& auth_secret); | 171 const std::string& auth_secret); |
165 | 172 |
166 void DidRequestPermission( | |
167 const PushMessagingAppIdentifier& app_identifier, | |
168 const content::PushSubscriptionOptions& options, | |
169 const content::PushMessagingService::RegisterCallback& callback, | |
170 blink::mojom::PermissionStatus permission_status); | |
171 | |
172 // GetEncryptionInfo method -------------------------------------------------- | 173 // GetEncryptionInfo method -------------------------------------------------- |
173 | 174 |
174 void DidGetEncryptionInfo( | 175 void DidGetEncryptionInfo( |
175 const PushMessagingService::EncryptionInfoCallback& callback, | 176 const PushMessagingService::EncryptionInfoCallback& callback, |
176 const std::string& p256dh, | 177 const std::string& p256dh, |
177 const std::string& auth_secret) const; | 178 const std::string& auth_secret) const; |
178 | 179 |
179 // Unsubscribe methods ------------------------------------------------------- | 180 // Unsubscribe methods ------------------------------------------------------- |
180 | 181 |
181 void Unsubscribe(const std::string& app_id, | 182 void Unsubscribe(const std::string& app_id, |
182 const std::string& sender_id, | |
183 const content::PushMessagingService::UnregisterCallback&); | 183 const content::PushMessagingService::UnregisterCallback&); |
184 | 184 |
185 void DidUnsubscribe(bool was_subscribed, | 185 void DidUnsubscribe(const std::string& app_id, |
| 186 bool was_subscribed, |
186 const content::PushMessagingService::UnregisterCallback&, | 187 const content::PushMessagingService::UnregisterCallback&, |
187 gcm::GCMClient::Result result); | 188 instance_id::InstanceID::Result result); |
188 | 189 |
189 // OnContentSettingChanged methods ------------------------------------------- | 190 // OnContentSettingChanged methods ------------------------------------------- |
190 | 191 |
191 void UnsubscribeBecausePermissionRevoked( | 192 void UnsubscribeBecausePermissionRevoked( |
192 const PushMessagingAppIdentifier& app_identifier, | 193 const PushMessagingAppIdentifier& app_identifier, |
193 const base::Closure& closure, | 194 const base::Closure& closure); |
194 const std::string& sender_id, | |
195 bool success, | |
196 bool not_found); | |
197 | 195 |
198 // Helper methods ------------------------------------------------------------ | 196 // Helper methods ------------------------------------------------------------ |
199 | 197 |
200 // Normalizes the |sender_info|. In most cases the |sender_info| will be | 198 // Normalizes the |sender_info|. In most cases the |sender_info| will be |
201 // passed through to the GCM Driver as-is, but NIST P-256 application server | 199 // passed through to the GCM Driver as-is, but NIST P-256 application server |
202 // keys have to be encoded using the URL-safe variant of the base64 encoding. | 200 // keys have to be encoded using the URL-safe variant of the base64 encoding. |
203 std::string NormalizeSenderInfo(const std::string& sender_info) const; | 201 std::string NormalizeSenderInfo(const std::string& sender_info) const; |
204 | 202 |
205 // Checks if a given origin is allowed to use Push. | 203 // Checks if a given origin is allowed to use Push. |
206 bool IsPermissionSet(const GURL& origin); | 204 bool IsPermissionSet(const GURL& origin); |
207 | 205 |
208 gcm::GCMDriver* GetGCMDriver() const; | 206 gcm::GCMDriver* GetGCMDriver() const; |
209 | 207 |
| 208 instance_id::InstanceIDDriver* GetInstanceIDDriver() const; |
| 209 |
210 // Testing methods ----------------------------------------------------------- | 210 // Testing methods ----------------------------------------------------------- |
211 | 211 |
212 // Callback to be invoked when a message has been dispatched. Enables tests to | 212 // Callback to be invoked when a message has been dispatched. Enables tests to |
213 // observe message delivery before it's dispatched to the Service Worker. | 213 // observe message delivery before it's dispatched to the Service Worker. |
214 using MessageDispatchedCallback = | 214 using MessageDispatchedCallback = |
215 base::Callback<void(const std::string& app_id, | 215 base::Callback<void(const std::string& app_id, |
216 const GURL& origin, | 216 const GURL& origin, |
217 int64_t service_worker_registration_id, | 217 int64_t service_worker_registration_id, |
218 const content::PushEventPayload& payload)>; | 218 const content::PushEventPayload& payload)>; |
219 | 219 |
(...skipping 21 matching lines...) Expand all Loading... |
241 MessageDispatchedCallback message_dispatched_callback_for_testing_; | 241 MessageDispatchedCallback message_dispatched_callback_for_testing_; |
242 | 242 |
243 scoped_ptr<PushMessagingServiceObserver> push_messaging_service_observer_; | 243 scoped_ptr<PushMessagingServiceObserver> push_messaging_service_observer_; |
244 | 244 |
245 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; | 245 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; |
246 | 246 |
247 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); | 247 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); |
248 }; | 248 }; |
249 | 249 |
250 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ | 250 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ |
OLD | NEW |