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 25 matching lines...) Expand all Loading... |
131 int64_t service_worker_registration_id, | 132 int64_t service_worker_registration_id, |
132 const gcm::IncomingMessage& message, | 133 const gcm::IncomingMessage& message, |
133 const base::Closure& message_handled_closure, | 134 const base::Closure& message_handled_closure, |
134 content::PushDeliveryStatus status); | 135 content::PushDeliveryStatus status); |
135 | 136 |
136 void DidHandleMessage(const std::string& app_id, | 137 void DidHandleMessage(const std::string& app_id, |
137 const base::Closure& completion_closure); | 138 const base::Closure& completion_closure); |
138 | 139 |
139 // Subscribe methods --------------------------------------------------------- | 140 // Subscribe methods --------------------------------------------------------- |
140 | 141 |
| 142 void DoSubscribe( |
| 143 const PushMessagingAppIdentifier& app_identifier, |
| 144 const content::PushSubscriptionOptions& options, |
| 145 const content::PushMessagingService::RegisterCallback& callback, |
| 146 blink::mojom::PermissionStatus permission_status); |
| 147 |
141 void SubscribeEnd( | 148 void SubscribeEnd( |
142 const content::PushMessagingService::RegisterCallback& callback, | 149 const content::PushMessagingService::RegisterCallback& callback, |
143 const std::string& subscription_id, | 150 const std::string& subscription_id, |
144 const std::vector<uint8_t>& p256dh, | 151 const std::vector<uint8_t>& p256dh, |
145 const std::vector<uint8_t>& auth, | 152 const std::vector<uint8_t>& auth, |
146 content::PushRegistrationStatus status); | 153 content::PushRegistrationStatus status); |
147 | 154 |
148 void SubscribeEndWithError( | 155 void SubscribeEndWithError( |
149 const content::PushMessagingService::RegisterCallback& callback, | 156 const content::PushMessagingService::RegisterCallback& callback, |
150 content::PushRegistrationStatus status); | 157 content::PushRegistrationStatus status); |
151 | 158 |
152 void DidSubscribe( | 159 void DidSubscribe( |
153 const PushMessagingAppIdentifier& app_identifier, | 160 const PushMessagingAppIdentifier& app_identifier, |
154 const content::PushMessagingService::RegisterCallback& callback, | 161 const content::PushMessagingService::RegisterCallback& callback, |
155 const std::string& subscription_id, | 162 const std::string& subscription_id, |
156 gcm::GCMClient::Result result); | 163 instance_id::InstanceID::Result result); |
157 | 164 |
158 void DidSubscribeWithEncryptionInfo( | 165 void DidSubscribeWithEncryptionInfo( |
159 const PushMessagingAppIdentifier& app_identifier, | 166 const PushMessagingAppIdentifier& app_identifier, |
160 const content::PushMessagingService::RegisterCallback& callback, | 167 const content::PushMessagingService::RegisterCallback& callback, |
161 const std::string& subscription_id, | 168 const std::string& subscription_id, |
162 const std::string& p256dh, | 169 const std::string& p256dh, |
163 const std::string& auth_secret); | 170 const std::string& auth_secret); |
164 | 171 |
165 void DidRequestPermission( | |
166 const PushMessagingAppIdentifier& app_identifier, | |
167 const content::PushSubscriptionOptions& options, | |
168 const content::PushMessagingService::RegisterCallback& callback, | |
169 blink::mojom::PermissionStatus permission_status); | |
170 | |
171 // GetEncryptionInfo method -------------------------------------------------- | 172 // GetEncryptionInfo method -------------------------------------------------- |
172 | 173 |
173 void DidGetEncryptionInfo( | 174 void DidGetEncryptionInfo( |
174 const PushMessagingService::EncryptionInfoCallback& callback, | 175 const PushMessagingService::EncryptionInfoCallback& callback, |
175 const std::string& p256dh, | 176 const std::string& p256dh, |
176 const std::string& auth_secret) const; | 177 const std::string& auth_secret) const; |
177 | 178 |
178 // Unsubscribe methods ------------------------------------------------------- | 179 // Unsubscribe methods ------------------------------------------------------- |
179 | 180 |
180 void Unsubscribe(const std::string& app_id, | 181 void Unsubscribe(const std::string& app_id, |
181 const std::string& sender_id, | |
182 const content::PushMessagingService::UnregisterCallback&); | 182 const content::PushMessagingService::UnregisterCallback&); |
183 | 183 |
184 void DidUnsubscribe(bool was_subscribed, | 184 void DidUnsubscribe(const std::string& app_id, |
| 185 bool was_subscribed, |
185 const content::PushMessagingService::UnregisterCallback&, | 186 const content::PushMessagingService::UnregisterCallback&, |
186 gcm::GCMClient::Result result); | 187 instance_id::InstanceID::Result result); |
187 | 188 |
188 // OnContentSettingChanged methods ------------------------------------------- | 189 // OnContentSettingChanged methods ------------------------------------------- |
189 | 190 |
190 void UnsubscribeBecausePermissionRevoked( | 191 void UnsubscribeBecausePermissionRevoked( |
191 const PushMessagingAppIdentifier& app_identifier, | 192 const PushMessagingAppIdentifier& app_identifier, |
192 const base::Closure& closure, | 193 const base::Closure& closure); |
193 const std::string& sender_id, | |
194 bool success, | |
195 bool not_found); | |
196 | 194 |
197 // Helper methods ------------------------------------------------------------ | 195 // Helper methods ------------------------------------------------------------ |
198 | 196 |
199 // Checks if a given origin is allowed to use Push. | 197 // Checks if a given origin is allowed to use Push. |
200 bool IsPermissionSet(const GURL& origin); | 198 bool IsPermissionSet(const GURL& origin); |
201 | 199 |
202 gcm::GCMDriver* GetGCMDriver() const; | 200 gcm::GCMDriver* GetGCMDriver() const; |
203 | 201 |
| 202 instance_id::InstanceIDDriver* GetInstanceIDDriver() const; |
| 203 |
204 // Testing methods ----------------------------------------------------------- | 204 // Testing methods ----------------------------------------------------------- |
205 | 205 |
206 // Callback to be invoked when a message has been dispatched. Enables tests to | 206 // Callback to be invoked when a message has been dispatched. Enables tests to |
207 // observe message delivery before it's dispatched to the Service Worker. | 207 // observe message delivery before it's dispatched to the Service Worker. |
208 using MessageDispatchedCallback = | 208 using MessageDispatchedCallback = |
209 base::Callback<void(const std::string& app_id, | 209 base::Callback<void(const std::string& app_id, |
210 const GURL& origin, | 210 const GURL& origin, |
211 int64_t service_worker_registration_id, | 211 int64_t service_worker_registration_id, |
212 const content::PushEventPayload& payload)>; | 212 const content::PushEventPayload& payload)>; |
213 | 213 |
(...skipping 21 matching lines...) Expand all Loading... |
235 MessageDispatchedCallback message_dispatched_callback_for_testing_; | 235 MessageDispatchedCallback message_dispatched_callback_for_testing_; |
236 | 236 |
237 scoped_ptr<PushMessagingServiceObserver> push_messaging_service_observer_; | 237 scoped_ptr<PushMessagingServiceObserver> push_messaging_service_observer_; |
238 | 238 |
239 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; | 239 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; |
240 | 240 |
241 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); | 241 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); |
242 }; | 242 }; |
243 | 243 |
244 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ | 244 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ |
OLD | NEW |