Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_impl.h

Issue 1851423003: Make Web Push use InstanceID tokens instead of GCM registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid4default
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.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 "chrome/common/features.h" 19 #include "chrome/common/features.h"
20 #include "components/content_settings/core/browser/content_settings_observer.h" 20 #include "components/content_settings/core/browser/content_settings_observer.h"
21 #include "components/content_settings/core/common/content_settings.h" 21 #include "components/content_settings/core/common/content_settings.h"
22 #include "components/gcm_driver/common/gcm_messages.h" 22 #include "components/gcm_driver/common/gcm_messages.h"
23 #include "components/gcm_driver/gcm_app_handler.h" 23 #include "components/gcm_driver/gcm_app_handler.h"
24 #include "components/gcm_driver/gcm_client.h" 24 #include "components/gcm_driver/gcm_client.h"
25 #include "components/gcm_driver/instance_id/instance_id.h"
25 #include "components/keyed_service/core/keyed_service.h" 26 #include "components/keyed_service/core/keyed_service.h"
26 #include "content/public/browser/push_messaging_service.h" 27 #include "content/public/browser/push_messaging_service.h"
27 #include "content/public/common/push_event_payload.h" 28 #include "content/public/common/push_event_payload.h"
28 #include "content/public/common/push_messaging_status.h" 29 #include "content/public/common/push_messaging_status.h"
29 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 30 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
30 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h" 31 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h"
31 32
32 #if defined(ENABLE_NOTIFICATIONS) 33 #if defined(ENABLE_NOTIFICATIONS)
33 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" 34 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h"
34 #endif 35 #endif
35 36
36 class Profile; 37 class Profile;
37 class PushMessagingAppIdentifier; 38 class PushMessagingAppIdentifier;
38 class PushMessagingServiceObserver; 39 class PushMessagingServiceObserver;
40 class PushMessagingServiceTest;
39 class ScopedKeepAlive; 41 class ScopedKeepAlive;
40 struct PushSubscriptionOptions; 42 struct PushSubscriptionOptions;
41 43
42 namespace gcm { 44 namespace gcm {
43 class GCMDriver; 45 class GCMDriver;
44 class GCMProfileService; 46 }
47 namespace instance_id {
48 class InstanceIDDriver;
45 } 49 }
46 50
47 namespace user_prefs { 51 namespace user_prefs {
48 class PrefRegistrySyncable; 52 class PrefRegistrySyncable;
49 } 53 }
50 54
51 class PushMessagingServiceImpl : public content::PushMessagingService, 55 class PushMessagingServiceImpl : public content::PushMessagingService,
52 public gcm::GCMAppHandler, 56 public gcm::GCMAppHandler,
53 public content_settings::Observer, 57 public content_settings::Observer,
54 public KeyedService, 58 public KeyedService,
(...skipping 27 matching lines...) Expand all
82 const content::PushSubscriptionOptions& options, 86 const content::PushSubscriptionOptions& options,
83 const content::PushMessagingService::RegisterCallback& callback) override; 87 const content::PushMessagingService::RegisterCallback& callback) override;
84 void SubscribeFromWorker( 88 void SubscribeFromWorker(
85 const GURL& requesting_origin, 89 const GURL& requesting_origin,
86 int64_t service_worker_registration_id, 90 int64_t service_worker_registration_id,
87 const content::PushSubscriptionOptions& options, 91 const content::PushSubscriptionOptions& options,
88 const content::PushMessagingService::RegisterCallback& callback) override; 92 const content::PushMessagingService::RegisterCallback& callback) override;
89 void GetEncryptionInfo( 93 void GetEncryptionInfo(
90 const GURL& origin, 94 const GURL& origin,
91 int64_t service_worker_registration_id, 95 int64_t service_worker_registration_id,
96 const std::string& sender_id,
92 const content::PushMessagingService::EncryptionInfoCallback& callback) 97 const content::PushMessagingService::EncryptionInfoCallback& callback)
93 override; 98 override;
94 void Unsubscribe( 99 void Unsubscribe(
95 const GURL& requesting_origin, 100 const GURL& requesting_origin,
96 int64_t service_worker_registration_id, 101 int64_t service_worker_registration_id,
97 const std::string& sender_id, 102 const std::string& sender_id,
98 const content::PushMessagingService::UnregisterCallback&) override; 103 const content::PushMessagingService::UnregisterCallback&) override;
99 blink::WebPushPermissionStatus GetPermissionStatus( 104 blink::WebPushPermissionStatus GetPermissionStatus(
100 const GURL& origin, 105 const GURL& origin,
101 bool user_visible) override; 106 bool user_visible) override;
(...skipping 11 matching lines...) Expand all
113 // BackgroundTrigger implementation. 118 // BackgroundTrigger implementation.
114 base::string16 GetName() override; 119 base::string16 GetName() override;
115 gfx::ImageSkia* GetIcon() override; 120 gfx::ImageSkia* GetIcon() override;
116 void OnMenuClick() override; 121 void OnMenuClick() override;
117 122
118 void SetMessageCallbackForTesting(const base::Closure& callback); 123 void SetMessageCallbackForTesting(const base::Closure& callback);
119 void SetContentSettingChangedCallbackForTesting( 124 void SetContentSettingChangedCallbackForTesting(
120 const base::Closure& callback); 125 const base::Closure& callback);
121 126
122 private: 127 private:
128 friend class PushMessagingBrowserTest;
123 FRIEND_TEST_ALL_PREFIXES(PushMessagingServiceTest, NormalizeSenderInfo); 129 FRIEND_TEST_ALL_PREFIXES(PushMessagingServiceTest, NormalizeSenderInfo);
124 FRIEND_TEST_ALL_PREFIXES(PushMessagingServiceTest, PayloadEncryptionTest); 130 FRIEND_TEST_ALL_PREFIXES(PushMessagingServiceTest, PayloadEncryptionTest);
125 131
126 // A subscription is pending until it has succeeded or failed. 132 // A subscription is pending until it has succeeded or failed.
127 void IncreasePushSubscriptionCount(int add, bool is_pending); 133 void IncreasePushSubscriptionCount(int add, bool is_pending);
128 void DecreasePushSubscriptionCount(int subtract, bool was_pending); 134 void DecreasePushSubscriptionCount(int subtract, bool was_pending);
129 135
130 // OnMessage methods --------------------------------------------------------- 136 // OnMessage methods ---------------------------------------------------------
131 137
132 void DeliverMessageCallback(const std::string& app_id, 138 void DeliverMessageCallback(const std::string& app_id,
133 const GURL& requesting_origin, 139 const GURL& requesting_origin,
134 int64_t service_worker_registration_id, 140 int64_t service_worker_registration_id,
135 const gcm::IncomingMessage& message, 141 const gcm::IncomingMessage& message,
136 const base::Closure& message_handled_closure, 142 const base::Closure& message_handled_closure,
137 content::PushDeliveryStatus status); 143 content::PushDeliveryStatus status);
138 144
139 void DidHandleMessage(const std::string& app_id, 145 void DidHandleMessage(const std::string& app_id,
140 const base::Closure& completion_closure); 146 const base::Closure& completion_closure);
141 147
142 // Subscribe methods --------------------------------------------------------- 148 // Subscribe methods ---------------------------------------------------------
143 149
150 void DoSubscribe(
151 const PushMessagingAppIdentifier& app_identifier,
152 const content::PushSubscriptionOptions& options,
153 const content::PushMessagingService::RegisterCallback& callback,
154 blink::mojom::PermissionStatus permission_status);
155
144 void SubscribeEnd( 156 void SubscribeEnd(
145 const content::PushMessagingService::RegisterCallback& callback, 157 const content::PushMessagingService::RegisterCallback& callback,
146 const std::string& subscription_id, 158 const std::string& subscription_id,
147 const std::vector<uint8_t>& p256dh, 159 const std::vector<uint8_t>& p256dh,
148 const std::vector<uint8_t>& auth, 160 const std::vector<uint8_t>& auth,
149 content::PushRegistrationStatus status); 161 content::PushRegistrationStatus status);
150 162
151 void SubscribeEndWithError( 163 void SubscribeEndWithError(
152 const content::PushMessagingService::RegisterCallback& callback, 164 const content::PushMessagingService::RegisterCallback& callback,
153 content::PushRegistrationStatus status); 165 content::PushRegistrationStatus status);
154 166
155 void DidSubscribe( 167 void DidSubscribe(
156 const PushMessagingAppIdentifier& app_identifier, 168 const PushMessagingAppIdentifier& app_identifier,
169 const std::string& sender_id,
157 const content::PushMessagingService::RegisterCallback& callback, 170 const content::PushMessagingService::RegisterCallback& callback,
158 const std::string& subscription_id, 171 const std::string& subscription_id,
159 gcm::GCMClient::Result result); 172 instance_id::InstanceID::Result result);
160 173
161 void DidSubscribeWithEncryptionInfo( 174 void DidSubscribeWithEncryptionInfo(
162 const PushMessagingAppIdentifier& app_identifier, 175 const PushMessagingAppIdentifier& app_identifier,
163 const content::PushMessagingService::RegisterCallback& callback, 176 const content::PushMessagingService::RegisterCallback& callback,
164 const std::string& subscription_id, 177 const std::string& subscription_id,
165 const std::string& p256dh, 178 const std::string& p256dh,
166 const std::string& auth_secret); 179 const std::string& auth_secret);
167 180
168 void DidRequestPermission(
169 const PushMessagingAppIdentifier& app_identifier,
170 const content::PushSubscriptionOptions& options,
171 const content::PushMessagingService::RegisterCallback& callback,
172 blink::mojom::PermissionStatus permission_status);
173
174 // GetEncryptionInfo method -------------------------------------------------- 181 // GetEncryptionInfo method --------------------------------------------------
175 182
176 void DidGetEncryptionInfo( 183 void DidGetEncryptionInfo(
177 const PushMessagingService::EncryptionInfoCallback& callback, 184 const PushMessagingService::EncryptionInfoCallback& callback,
178 const std::string& p256dh, 185 const std::string& p256dh,
179 const std::string& auth_secret) const; 186 const std::string& auth_secret) const;
180 187
181 // Unsubscribe methods ------------------------------------------------------- 188 // Unsubscribe methods -------------------------------------------------------
182 189
183 void Unsubscribe(const std::string& app_id, 190 void Unsubscribe(const std::string& app_id,
184 const std::string& sender_id, 191 const std::string& sender_id,
185 const content::PushMessagingService::UnregisterCallback&); 192 const content::PushMessagingService::UnregisterCallback&);
186 193
194 void DidDeleteID(const std::string& app_id,
195 bool was_subscribed,
196 const content::PushMessagingService::UnregisterCallback&,
197 instance_id::InstanceID::Result result);
198
199 void DidUnsubscribeInstanceID(
200 const std::string& app_id,
201 bool was_subscribed,
202 const content::PushMessagingService::UnregisterCallback&,
203 instance_id::InstanceID::Result result);
204
187 void DidUnsubscribe(bool was_subscribed, 205 void DidUnsubscribe(bool was_subscribed,
188 const content::PushMessagingService::UnregisterCallback&, 206 const content::PushMessagingService::UnregisterCallback&,
189 gcm::GCMClient::Result result); 207 gcm::GCMClient::Result result);
190 208
191 // OnContentSettingChanged methods ------------------------------------------- 209 // OnContentSettingChanged methods -------------------------------------------
192 210
193 void UnsubscribeBecausePermissionRevoked( 211 void UnsubscribeBecausePermissionRevoked(
194 const PushMessagingAppIdentifier& app_identifier, 212 const PushMessagingAppIdentifier& app_identifier,
195 const base::Closure& closure, 213 const base::Closure& closure,
196 const std::string& sender_id, 214 const std::string& sender_id,
197 bool success, 215 bool success,
198 bool not_found); 216 bool not_found);
199 217
200 // Helper methods ------------------------------------------------------------ 218 // Helper methods ------------------------------------------------------------
201 219
202 // Normalizes the |sender_info|. In most cases the |sender_info| will be 220 // Normalizes the |sender_info|. In most cases the |sender_info| will be
203 // passed through to the GCM Driver as-is, but NIST P-256 application server 221 // passed through to the GCM Driver as-is, but NIST P-256 application server
204 // keys have to be encoded using the URL-safe variant of the base64 encoding. 222 // keys have to be encoded using the URL-safe variant of the base64 encoding.
205 std::string NormalizeSenderInfo(const std::string& sender_info) const; 223 std::string NormalizeSenderInfo(const std::string& sender_info) const;
206 224
207 // Checks if a given origin is allowed to use Push. 225 // Checks if a given origin is allowed to use Push.
208 bool IsPermissionSet(const GURL& origin); 226 bool IsPermissionSet(const GURL& origin);
209 227
228 // Wrapper around {GCMDriver, InstanceID}::GetEncryptionInfo.
229 void GetEncryptionInfoForAppId(
230 const std::string& app_id,
231 const std::string& sender_id,
232 gcm::GCMEncryptionProvider::EncryptionInfoCallback callback);
233
210 gcm::GCMDriver* GetGCMDriver() const; 234 gcm::GCMDriver* GetGCMDriver() const;
211 235
236 instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
237
212 // Testing methods ----------------------------------------------------------- 238 // Testing methods -----------------------------------------------------------
213 239
214 // Callback to be invoked when a message has been dispatched. Enables tests to 240 // Callback to be invoked when a message has been dispatched. Enables tests to
215 // observe message delivery before it's dispatched to the Service Worker. 241 // observe message delivery before it's dispatched to the Service Worker.
216 using MessageDispatchedCallback = 242 using MessageDispatchedCallback =
217 base::Callback<void(const std::string& app_id, 243 base::Callback<void(const std::string& app_id,
218 const GURL& origin, 244 const GURL& origin,
219 int64_t service_worker_registration_id, 245 int64_t service_worker_registration_id,
220 const content::PushEventPayload& payload)>; 246 const content::PushEventPayload& payload)>;
221 247
(...skipping 28 matching lines...) Expand all
250 // we can finish processing them without being interrupted. 276 // we can finish processing them without being interrupted.
251 std::unique_ptr<ScopedKeepAlive> in_flight_keep_alive_; 277 std::unique_ptr<ScopedKeepAlive> in_flight_keep_alive_;
252 #endif 278 #endif
253 279
254 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; 280 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_;
255 281
256 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); 282 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl);
257 }; 283 };
258 284
259 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ 285 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698