Re-enable blink_perf.canvas on Windows
[chromium-blink-merge.git] / content / child / push_messaging / push_provider.h
blob47442ae0230820edd0ba183b93ac7531a3347b8e
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 OnRegisterFromWorkerSuccess(int request_id,
67 const GURL& endpoint,
68 const std::string& registration_id);
69 void OnRegisterFromWorkerError(int request_id, PushRegistrationStatus status);
70 void OnUnregisterSuccess(int request_id, bool did_unregister);
71 void OnUnregisterError(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 const std::string& registration_id);
77 void OnGetRegistrationError(int request_id, PushGetRegistrationStatus status);
78 void OnGetPermissionStatusSuccess(int request_id,
79 blink::WebPushPermissionStatus status);
80 void OnGetPermissionStatusError(int request_id,
81 blink::WebPushError::ErrorType error);
83 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
84 scoped_refptr<PushDispatcher> push_dispatcher_;
86 // Stores the subscription callbacks with their request ids. This class owns
87 // the callbacks.
88 IDMap<blink::WebPushSubscriptionCallbacks, IDMapOwnPointer>
89 subscription_callbacks_;
91 // Stores the permission status callbacks with their request ids. This class
92 // owns the callbacks.
93 IDMap<blink::WebPushPermissionStatusCallbacks, IDMapOwnPointer>
94 permission_status_callbacks_;
96 // Stores the unsubscription callbacks with their request ids. This class owns
97 // the callbacks.
98 IDMap<blink::WebPushUnsubscribeCallbacks, IDMapOwnPointer>
99 unsubscribe_callbacks_;
101 DISALLOW_COPY_AND_ASSIGN(PushProvider);
104 } // namespace content
106 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_