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 <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/browser/push_messaging/push_messaging_notification_manager.h" | 19 #include "chrome/browser/push_messaging/push_messaging_notification_manager.h" |
20 #include "chrome/common/features.h" | 20 #include "chrome/common/features.h" |
21 #include "components/content_settings/core/browser/content_settings_observer.h" | 21 #include "components/content_settings/core/browser/content_settings_observer.h" |
22 #include "components/content_settings/core/common/content_settings.h" | 22 #include "components/content_settings/core/common/content_settings.h" |
23 #include "components/content_settings/core/common/content_settings_types.h" | 23 #include "components/content_settings/core/common/content_settings_types.h" |
24 #include "components/gcm_driver/common/gcm_messages.h" | 24 #include "components/gcm_driver/common/gcm_messages.h" |
25 #include "components/gcm_driver/gcm_app_handler.h" | 25 #include "components/gcm_driver/gcm_app_handler.h" |
26 #include "components/gcm_driver/gcm_client.h" | 26 #include "components/gcm_driver/gcm_client.h" |
27 #include "components/gcm_driver/instance_id/instance_id.h" | 27 #include "components/gcm_driver/instance_id/instance_id.h" |
28 #include "components/keyed_service/core/keyed_service.h" | 28 #include "components/keyed_service/core/keyed_service.h" |
| 29 #include "content/public/browser/notification_observer.h" |
| 30 #include "content/public/browser/notification_registrar.h" |
29 #include "content/public/browser/push_messaging_service.h" | 31 #include "content/public/browser/push_messaging_service.h" |
30 #include "content/public/common/push_event_payload.h" | 32 #include "content/public/common/push_event_payload.h" |
31 #include "content/public/common/push_messaging_status.h" | 33 #include "content/public/common/push_messaging_status.h" |
32 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 34 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
33 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" | 35 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" |
34 | 36 |
35 class Profile; | 37 class Profile; |
36 class PushMessagingAppIdentifier; | 38 class PushMessagingAppIdentifier; |
37 class PushMessagingServiceObserver; | 39 class PushMessagingServiceObserver; |
38 class PushMessagingServiceTest; | 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 } | 46 } |
45 namespace instance_id { | 47 namespace instance_id { |
46 class InstanceIDDriver; | 48 class InstanceIDDriver; |
47 } | 49 } |
48 | 50 |
49 class PushMessagingServiceImpl : public content::PushMessagingService, | 51 class PushMessagingServiceImpl : public content::PushMessagingService, |
| 52 public content::NotificationObserver, |
50 public gcm::GCMAppHandler, | 53 public gcm::GCMAppHandler, |
51 public content_settings::Observer, | 54 public content_settings::Observer, |
52 public KeyedService, | 55 public KeyedService, |
53 public BackgroundTrigger { | 56 public BackgroundTrigger { |
54 public: | 57 public: |
55 // If any Service Workers are using push, starts GCM and adds an app handler. | 58 // If any Service Workers are using push, starts GCM and adds an app handler. |
56 static void InitializeForProfile(Profile* profile); | 59 static void InitializeForProfile(Profile* profile); |
57 | 60 |
58 explicit PushMessagingServiceImpl(Profile* profile); | 61 explicit PushMessagingServiceImpl(Profile* profile); |
59 ~PushMessagingServiceImpl() override; | 62 ~PushMessagingServiceImpl() override; |
60 | 63 |
61 // gcm::GCMAppHandler implementation. | 64 // gcm::GCMAppHandler implementation. |
62 void ShutdownHandler() override; | 65 void ShutdownHandler() override; |
63 void OnStoreReset() override; | 66 void OnStoreReset() override; |
64 void OnMessage(const std::string& app_id, | 67 void OnMessage(const std::string& app_id, |
65 const gcm::IncomingMessage& message) override; | 68 const gcm::IncomingMessage& message) override; |
66 void OnMessagesDeleted(const std::string& app_id) override; | 69 void OnMessagesDeleted(const std::string& app_id) override; |
67 void OnSendError( | 70 void OnSendError( |
68 const std::string& app_id, | 71 const std::string& app_id, |
69 const gcm::GCMClient::SendErrorDetails& send_error_details) override; | 72 const gcm::GCMClient::SendErrorDetails& send_error_details) override; |
70 void OnSendAcknowledged(const std::string& app_id, | 73 void OnSendAcknowledged(const std::string& app_id, |
71 const std::string& message_id) override; | 74 const std::string& message_id) override; |
72 bool CanHandle(const std::string& app_id) const override; | 75 bool CanHandle(const std::string& app_id) const override; |
73 | 76 |
| 77 // content::NotificationObserver: |
| 78 void Observe(int type, |
| 79 const content::NotificationSource& source, |
| 80 const content::NotificationDetails& details) override; |
| 81 |
74 // content::PushMessagingService implementation: | 82 // content::PushMessagingService implementation: |
75 GURL GetEndpoint(bool standard_protocol) const override; | 83 GURL GetEndpoint(bool standard_protocol) const override; |
76 void SubscribeFromDocument(const GURL& requesting_origin, | 84 void SubscribeFromDocument(const GURL& requesting_origin, |
77 int64_t service_worker_registration_id, | 85 int64_t service_worker_registration_id, |
78 int renderer_id, | 86 int renderer_id, |
79 int render_frame_id, | 87 int render_frame_id, |
80 const content::PushSubscriptionOptions& options, | 88 const content::PushSubscriptionOptions& options, |
81 const RegisterCallback& callback) override; | 89 const RegisterCallback& callback) override; |
82 void SubscribeFromWorker(const GURL& requesting_origin, | 90 void SubscribeFromWorker(const GURL& requesting_origin, |
83 int64_t service_worker_registration_id, | 91 int64_t service_worker_registration_id, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 267 |
260 // A multiset containing one entry for each in-flight push message delivery, | 268 // A multiset containing one entry for each in-flight push message delivery, |
261 // keyed by the receiver's app id. | 269 // keyed by the receiver's app id. |
262 std::multiset<std::string> in_flight_message_deliveries_; | 270 std::multiset<std::string> in_flight_message_deliveries_; |
263 | 271 |
264 MessageDispatchedCallback message_dispatched_callback_for_testing_; | 272 MessageDispatchedCallback message_dispatched_callback_for_testing_; |
265 | 273 |
266 std::unique_ptr<PushMessagingServiceObserver> | 274 std::unique_ptr<PushMessagingServiceObserver> |
267 push_messaging_service_observer_; | 275 push_messaging_service_observer_; |
268 | 276 |
| 277 content::NotificationRegistrar registrar_; |
| 278 |
269 #if BUILDFLAG(ENABLE_BACKGROUND) | 279 #if BUILDFLAG(ENABLE_BACKGROUND) |
270 // KeepAlive registered while we have in-flight push messages, to make sure | 280 // KeepAlive registered while we have in-flight push messages, to make sure |
271 // we can finish processing them without being interrupted. | 281 // we can finish processing them without being interrupted. |
272 std::unique_ptr<ScopedKeepAlive> in_flight_keep_alive_; | 282 std::unique_ptr<ScopedKeepAlive> in_flight_keep_alive_; |
273 #endif | 283 #endif |
274 | 284 |
275 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; | 285 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_; |
276 | 286 |
277 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); | 287 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl); |
278 }; | 288 }; |
279 | 289 |
280 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ | 290 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_SERVICE_IMPL_H_ |
OLD | NEW |