[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / child / push_messaging / push_provider.h
blobb47eea8076e751e224bd594b66c4bc71dac8cc13
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_
8 #include <string>
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"
18 class GURL;
20 namespace blink {
21 struct WebPushSubscriptionOptions;
24 namespace content {
26 class ThreadSafeSender;
28 class PushProvider : public blink::WebPushProvider,
29 public WorkerTaskRunner::Observer {
30 public:
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 virtual void unsubscribe(
48 blink::WebServiceWorkerRegistration* service_worker_registration,
49 blink::WebPushUnsubscribeCallbacks* callbacks);
50 virtual void getSubscription(
51 blink::WebServiceWorkerRegistration* service_worker_registration,
52 blink::WebPushSubscriptionCallbacks* callbacks);
53 virtual void getPermissionStatus(
54 blink::WebServiceWorkerRegistration* service_worker_registration,
55 const blink::WebPushSubscriptionOptions& options,
56 blink::WebPushPermissionStatusCallbacks* callbacks);
58 // Called by the PushDispatcher.
59 bool OnMessageReceived(const IPC::Message& message);
61 private:
62 PushProvider(ThreadSafeSender* thread_safe_sender,
63 PushDispatcher* push_dispatcher);
65 // IPC message handlers.
66 void OnSubscribeFromWorkerSuccess(int request_id,
67 const GURL& endpoint);
68 void OnSubscribeFromWorkerError(int request_id,
69 PushRegistrationStatus status);
70 void OnUnsubscribeSuccess(int request_id, bool did_unsubscribe);
71 void OnUnsubscribeError(int request_id,
72 blink::WebPushError::ErrorType error_type,
73 const std::string& error_message);
74 void OnGetRegistrationSuccess(int request_id,
75 const GURL& endpoint);
76 void OnGetRegistrationError(int request_id, PushGetRegistrationStatus status);
77 void OnGetPermissionStatusSuccess(int request_id,
78 blink::WebPushPermissionStatus status);
79 void OnGetPermissionStatusError(int request_id,
80 blink::WebPushError::ErrorType error);
82 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
83 scoped_refptr<PushDispatcher> push_dispatcher_;
85 // Stores the subscription callbacks with their request ids. This class owns
86 // the callbacks.
87 IDMap<blink::WebPushSubscriptionCallbacks, IDMapOwnPointer>
88 subscription_callbacks_;
90 // Stores the permission status callbacks with their request ids. This class
91 // owns the callbacks.
92 IDMap<blink::WebPushPermissionStatusCallbacks, IDMapOwnPointer>
93 permission_status_callbacks_;
95 // Stores the unsubscription callbacks with their request ids. This class owns
96 // the callbacks.
97 IDMap<blink::WebPushUnsubscribeCallbacks, IDMapOwnPointer>
98 unsubscribe_callbacks_;
100 DISALLOW_COPY_AND_ASSIGN(PushProvider);
103 } // namespace content
105 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_