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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_
6 #define CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_
12 #include "base/id_map.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/child/push_messaging/push_dispatcher.h"
15 #include "content/public/child/worker_thread.h"
16 #include "content/public/common/push_messaging_status.h"
17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError.h"
18 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushProvider.h"
23 struct WebPushSubscriptionOptions
;
28 class ThreadSafeSender
;
30 class PushProvider
: public blink::WebPushProvider
,
31 public WorkerThread::Observer
{
33 ~PushProvider() override
;
35 // The |thread_safe_sender| and |push_dispatcher| are used if calling this
36 // leads to construction.
37 static PushProvider
* ThreadSpecificInstance(
38 ThreadSafeSender
* thread_safe_sender
,
39 PushDispatcher
* push_dispatcher
);
41 // WorkerThread::Observer implementation.
42 void WillStopCurrentWorkerThread() override
;
44 // blink::WebPushProvider implementation.
45 virtual void subscribe(
46 blink::WebServiceWorkerRegistration
* service_worker_registration
,
47 const blink::WebPushSubscriptionOptions
& options
,
48 blink::WebPushSubscriptionCallbacks
* callbacks
);
49 virtual void unsubscribe(
50 blink::WebServiceWorkerRegistration
* service_worker_registration
,
51 blink::WebPushUnsubscribeCallbacks
* callbacks
);
52 virtual void getSubscription(
53 blink::WebServiceWorkerRegistration
* service_worker_registration
,
54 blink::WebPushSubscriptionCallbacks
* callbacks
);
55 virtual void getPermissionStatus(
56 blink::WebServiceWorkerRegistration
* service_worker_registration
,
57 const blink::WebPushSubscriptionOptions
& options
,
58 blink::WebPushPermissionStatusCallbacks
* callbacks
);
60 // Called by the PushDispatcher.
61 bool OnMessageReceived(const IPC::Message
& message
);
64 PushProvider(ThreadSafeSender
* thread_safe_sender
,
65 PushDispatcher
* push_dispatcher
);
67 // IPC message handlers.
68 void OnSubscribeFromWorkerSuccess(int request_id
,
70 const std::vector
<uint8_t>& curve25519dh
);
71 void OnSubscribeFromWorkerError(int request_id
,
72 PushRegistrationStatus status
);
73 void OnUnsubscribeSuccess(int request_id
, bool did_unsubscribe
);
74 void OnUnsubscribeError(int request_id
,
75 blink::WebPushError::ErrorType error_type
,
76 const std::string
& error_message
);
77 void OnGetRegistrationSuccess(int request_id
,
79 const std::vector
<uint8_t>& curve25519dh
);
80 void OnGetRegistrationError(int request_id
, PushGetRegistrationStatus status
);
81 void OnGetPermissionStatusSuccess(int request_id
,
82 blink::WebPushPermissionStatus status
);
83 void OnGetPermissionStatusError(int request_id
,
84 blink::WebPushError::ErrorType error
);
86 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
87 scoped_refptr
<PushDispatcher
> push_dispatcher_
;
89 // Stores the subscription callbacks with their request ids. This class owns
91 IDMap
<blink::WebPushSubscriptionCallbacks
, IDMapOwnPointer
>
92 subscription_callbacks_
;
94 // Stores the permission status callbacks with their request ids. This class
95 // owns the callbacks.
96 IDMap
<blink::WebPushPermissionStatusCallbacks
, IDMapOwnPointer
>
97 permission_status_callbacks_
;
99 // Stores the unsubscription callbacks with their request ids. This class owns
101 IDMap
<blink::WebPushUnsubscribeCallbacks
, IDMapOwnPointer
>
102 unsubscribe_callbacks_
;
104 DISALLOW_COPY_AND_ASSIGN(PushProvider
);
107 } // namespace content
109 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_