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_
10 #include "base/id_map.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/child/push_messaging/push_dispatcher.h"
13 #include "content/child/worker_task_runner.h"
14 #include "content/public/common/push_messaging_status.h"
15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError.h"
16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushProvider.h"
21 struct WebPushSubscriptionOptions
;
26 class ThreadSafeSender
;
28 class PushProvider
: public blink::WebPushProvider
,
29 public WorkerTaskRunner::Observer
{
31 ~PushProvider() override
;
33 // The |thread_safe_sender| and |push_dispatcher| are used if calling this
34 // leads to construction.
35 static PushProvider
* ThreadSpecificInstance(
36 ThreadSafeSender
* thread_safe_sender
,
37 PushDispatcher
* push_dispatcher
);
39 // WorkerTaskRunner::Observer implementation.
40 void OnWorkerRunLoopStopped() override
;
42 // blink::WebPushProvider implementation.
43 virtual void subscribe(
44 blink::WebServiceWorkerRegistration
* service_worker_registration
,
45 const blink::WebPushSubscriptionOptions
& options
,
46 blink::WebPushSubscriptionCallbacks
* callbacks
);
47 // TODO(peter): Remove this method when Blink switched over to the above.
48 virtual void registerPushMessaging(
49 blink::WebServiceWorkerRegistration
* service_worker_registration
,
50 blink::WebPushSubscriptionCallbacks
* callbacks
);
51 virtual void unsubscribe(
52 blink::WebServiceWorkerRegistration
* service_worker_registration
,
53 blink::WebPushUnsubscribeCallbacks
* callbacks
);
54 // TODO(peter): Remove this method when Blink switched over to the above.
55 virtual void unregister(
56 blink::WebServiceWorkerRegistration
* service_worker_registration
,
57 blink::WebPushUnsubscribeCallbacks
* callbacks
);
58 virtual void getSubscription(
59 blink::WebServiceWorkerRegistration
* service_worker_registration
,
60 blink::WebPushSubscriptionCallbacks
* callbacks
);
61 // TODO(peter): Remove this method when Blink switched over to the above.
62 virtual void getRegistration(
63 blink::WebServiceWorkerRegistration
* service_worker_registration
,
64 blink::WebPushSubscriptionCallbacks
* callbacks
);
65 virtual void getPermissionStatus(
66 blink::WebServiceWorkerRegistration
* service_worker_registration
,
67 const blink::WebPushSubscriptionOptions
& options
,
68 blink::WebPushPermissionStatusCallbacks
* callbacks
);
69 // TODO(peter): Remove this method when Blink switched over to the above.
70 virtual void getPermissionStatus(
71 blink::WebServiceWorkerRegistration
* service_worker_registration
,
72 blink::WebPushPermissionStatusCallbacks
* callbacks
);
74 // Called by the PushDispatcher.
75 bool OnMessageReceived(const IPC::Message
& message
);
78 PushProvider(ThreadSafeSender
* thread_safe_sender
,
79 PushDispatcher
* push_dispatcher
);
81 // IPC message handlers.
82 void OnRegisterFromWorkerSuccess(int request_id
,
84 const std::string
& registration_id
);
85 void OnRegisterFromWorkerError(int request_id
, PushRegistrationStatus status
);
86 void OnUnregisterSuccess(int request_id
, bool did_unregister
);
87 void OnUnregisterError(int request_id
,
88 blink::WebPushError::ErrorType error_type
,
89 const std::string
& error_message
);
90 void OnGetRegistrationSuccess(int request_id
,
92 const std::string
& registration_id
);
93 void OnGetRegistrationError(int request_id
, PushGetRegistrationStatus status
);
94 void OnGetPermissionStatusSuccess(int request_id
,
95 blink::WebPushPermissionStatus status
);
96 void OnGetPermissionStatusError(int request_id
);
98 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
99 scoped_refptr
<PushDispatcher
> push_dispatcher_
;
101 // Stores the subscription callbacks with their request ids. This class owns
103 IDMap
<blink::WebPushSubscriptionCallbacks
, IDMapOwnPointer
>
104 subscription_callbacks_
;
106 // Stores the permission status callbacks with their request ids. This class
107 // owns the callbacks.
108 IDMap
<blink::WebPushPermissionStatusCallbacks
, IDMapOwnPointer
>
109 permission_status_callbacks_
;
111 // Stores the unsubscription callbacks with their request ids. This class owns
113 IDMap
<blink::WebPushUnsubscribeCallbacks
, IDMapOwnPointer
>
114 unsubscribe_callbacks_
;
116 DISALLOW_COPY_AND_ASSIGN(PushProvider
);
119 } // namespace content
121 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_