| 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 CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 5 #ifndef CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 
| 6 #define CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 6 #define CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 
| 7 | 7 | 
| 8 #include <stdint.h> | 8 #include <stdint.h> | 
| 9 | 9 | 
| 10 #include <memory> | 10 #include <memory> | 
| 11 #include <string> | 11 #include <string> | 
| 12 #include <vector> | 12 #include <vector> | 
| 13 | 13 | 
| 14 #include "base/id_map.h" |  | 
| 15 #include "base/macros.h" | 14 #include "base/macros.h" | 
| 16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" | 
| 17 #include "content/child/push_messaging/push_dispatcher.h" | 16 #include "content/common/push_messaging.mojom.h" | 
| 18 #include "content/public/child/worker_thread.h" | 17 #include "content/public/child/worker_thread.h" | 
| 19 #include "content/public/common/push_messaging_status.h" | 18 #include "content/public/common/push_messaging_status.h" | 
| 20 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
     .h" | 19 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
     .h" | 
| 21 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushProvi
     der.h" | 20 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushProvi
     der.h" | 
| 22 | 21 | 
| 23 class GURL; | 22 class GURL; | 
| 24 | 23 | 
| 25 namespace blink { | 24 namespace blink { | 
| 26 struct WebPushSubscriptionOptions; | 25 struct WebPushSubscriptionOptions; | 
| 27 } | 26 } | 
| 28 | 27 | 
| 29 namespace content { | 28 namespace content { | 
| 30 | 29 | 
| 31 class ThreadSafeSender; |  | 
| 32 struct PushSubscriptionOptions; | 30 struct PushSubscriptionOptions; | 
| 33 | 31 | 
| 34 blink::WebPushError PushRegistrationStatusToWebPushError( | 32 blink::WebPushError PushRegistrationStatusToWebPushError( | 
| 35     PushRegistrationStatus status); | 33     PushRegistrationStatus status); | 
| 36 | 34 | 
| 37 class PushProvider : public blink::WebPushProvider, | 35 class PushProvider : public blink::WebPushProvider, | 
| 38                      public WorkerThread::Observer { | 36                      public WorkerThread::Observer { | 
| 39  public: | 37  public: | 
| 40   ~PushProvider() override; | 38   ~PushProvider() override; | 
| 41 | 39 | 
| 42   // The |thread_safe_sender| and |push_dispatcher| are used if calling this |  | 
| 43   // leads to construction. |  | 
| 44   static PushProvider* ThreadSpecificInstance( | 40   static PushProvider* ThreadSpecificInstance( | 
| 45       ThreadSafeSender* thread_safe_sender, | 41       const scoped_refptr<base::SingleThreadTaskRunner>& | 
| 46       PushDispatcher* push_dispatcher); | 42           main_thread_task_runner); | 
| 47 | 43 | 
| 48   // WorkerThread::Observer implementation. | 44   // WorkerThread::Observer implementation. | 
| 49   void WillStopCurrentWorkerThread() override; | 45   void WillStopCurrentWorkerThread() override; | 
| 50 | 46 | 
| 51   // blink::WebPushProvider implementation. | 47   // blink::WebPushProvider implementation. | 
| 52   void subscribe( | 48   void subscribe( | 
| 53       blink::WebServiceWorkerRegistration* service_worker_registration, | 49       blink::WebServiceWorkerRegistration* service_worker_registration, | 
| 54       const blink::WebPushSubscriptionOptions& options, | 50       const blink::WebPushSubscriptionOptions& options, | 
| 55       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; | 51       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; | 
| 56   void unsubscribe( | 52   void unsubscribe( | 
| 57       blink::WebServiceWorkerRegistration* service_worker_registration, | 53       blink::WebServiceWorkerRegistration* service_worker_registration, | 
| 58       std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks) override; | 54       std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks) override; | 
| 59   void getSubscription( | 55   void getSubscription( | 
| 60       blink::WebServiceWorkerRegistration* service_worker_registration, | 56       blink::WebServiceWorkerRegistration* service_worker_registration, | 
| 61       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; | 57       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; | 
| 62   void getPermissionStatus( | 58   void getPermissionStatus( | 
| 63       blink::WebServiceWorkerRegistration* service_worker_registration, | 59       blink::WebServiceWorkerRegistration* service_worker_registration, | 
| 64       const blink::WebPushSubscriptionOptions& options, | 60       const blink::WebPushSubscriptionOptions& options, | 
| 65       std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks) | 61       std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks) | 
| 66       override; | 62       override; | 
| 67 | 63 | 
| 68   // Called by the PushDispatcher. | 64  private: | 
| 69   bool OnMessageReceived(const IPC::Message& message); | 65   explicit PushProvider(const scoped_refptr<base::SingleThreadTaskRunner>& | 
|  | 66                             main_thread_task_runner); | 
| 70 | 67 | 
| 71  private: | 68   static void GetInterface(mojom::PushMessagingRequest request); | 
| 72   PushProvider(ThreadSafeSender* thread_safe_sender, |  | 
| 73                PushDispatcher* push_dispatcher); |  | 
| 74 | 69 | 
| 75   // IPC message handlers. | 70   void SubscribeCallback( | 
| 76   void OnSubscribeFromWorkerSuccess(int request_id, | 71       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, | 
| 77                                     const GURL& endpoint, | 72       content::PushRegistrationStatus status, | 
| 78                                     const PushSubscriptionOptions& options, | 73       const base::Optional<GURL>& endpoint, | 
| 79                                     const std::vector<uint8_t>& p256dh, | 74       const base::Optional<content::PushSubscriptionOptions>& options, | 
| 80                                     const std::vector<uint8_t>& auth); | 75       const base::Optional<std::vector<uint8_t>>& p256dh, | 
| 81   void OnSubscribeFromWorkerError(int request_id, | 76       const base::Optional<std::vector<uint8_t>>& auth); | 
| 82                                   PushRegistrationStatus status); |  | 
| 83   void OnUnsubscribeSuccess(int request_id, bool did_unsubscribe); |  | 
| 84   void OnUnsubscribeError(int request_id, |  | 
| 85                           blink::WebPushError::ErrorType error_type, |  | 
| 86                           const std::string& error_message); |  | 
| 87   void OnGetSubscriptionSuccess(int request_id, |  | 
| 88                                 const GURL& endpoint, |  | 
| 89                                 const PushSubscriptionOptions& options, |  | 
| 90                                 const std::vector<uint8_t>& p256dh, |  | 
| 91                                 const std::vector<uint8_t>& auth); |  | 
| 92   void OnGetSubscriptionError(int request_id, PushGetRegistrationStatus status); |  | 
| 93   void OnGetPermissionStatusSuccess(int request_id, |  | 
| 94                                     blink::WebPushPermissionStatus status); |  | 
| 95   void OnGetPermissionStatusError(int request_id, |  | 
| 96                                   blink::WebPushError::ErrorType error); |  | 
| 97 | 77 | 
| 98   scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 78   void UnsubscribeCallback( | 
| 99   scoped_refptr<PushDispatcher> push_dispatcher_; | 79       std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks, | 
|  | 80       bool is_success, | 
|  | 81       bool did_unsubscribe, | 
|  | 82       blink::WebPushError::ErrorType error_type, | 
|  | 83       const base::Optional<std::string>& error_message); | 
| 100 | 84 | 
| 101   // Stores the subscription callbacks with their request ids. This class owns | 85   void GetSubscriptionCallback( | 
| 102   // the callbacks. | 86       std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, | 
| 103   IDMap<std::unique_ptr<blink::WebPushSubscriptionCallbacks>> | 87       content::PushGetRegistrationStatus status, | 
| 104       subscription_callbacks_; | 88       const base::Optional<GURL>& endpoint, | 
|  | 89       const base::Optional<content::PushSubscriptionOptions>& options, | 
|  | 90       const base::Optional<std::vector<uint8_t>>& p256dh, | 
|  | 91       const base::Optional<std::vector<uint8_t>>& auth); | 
| 105 | 92 | 
| 106   // Stores the permission status callbacks with their request ids. This class | 93   void GetPermissionStatusCallback( | 
| 107   // owns the callbacks. | 94       std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks, | 
| 108   IDMap<std::unique_ptr<blink::WebPushPermissionStatusCallbacks>> | 95       bool is_success, | 
| 109       permission_status_callbacks_; | 96       blink::WebPushPermissionStatus status, | 
|  | 97       blink::WebPushError::ErrorType error); | 
| 110 | 98 | 
| 111   // Stores the unsubscription callbacks with their request ids. This class owns | 99   mojom::PushMessagingPtr push_messaging_manager_; | 
| 112   // the callbacks. |  | 
| 113   IDMap<std::unique_ptr<blink::WebPushUnsubscribeCallbacks>> |  | 
| 114       unsubscribe_callbacks_; |  | 
| 115 | 100 | 
| 116   DISALLOW_COPY_AND_ASSIGN(PushProvider); | 101   DISALLOW_COPY_AND_ASSIGN(PushProvider); | 
| 117 }; | 102 }; | 
| 118 | 103 | 
| 119 }  // namespace content | 104 }  // namespace content | 
| 120 | 105 | 
| 121 #endif  // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 106 #endif  // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ | 
| OLD | NEW | 
|---|