Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: content/child/push_messaging/push_provider.h

Issue 2690203003: Convert push_messaging IPC msgs into mojo interfaces (Closed)
Patch Set: remove DCHECK(ChildThreadImpl::Current()) Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner);
Peter Beverloo 2017/02/16 16:08:33 nit: const&
ke.he 2017/02/17 08:22:33 Done.
46 PushDispatcher* push_dispatcher); 42
43 static void BindRequest(mojom::PushMessagingRequest request);
Peter Beverloo 2017/02/16 16:08:32 nit: this can be private
ke.he 2017/02/17 08:22:38 Done.
47 44
48 // WorkerThread::Observer implementation. 45 // WorkerThread::Observer implementation.
49 void WillStopCurrentWorkerThread() override; 46 void WillStopCurrentWorkerThread() override;
50 47
51 // blink::WebPushProvider implementation. 48 // blink::WebPushProvider implementation.
52 void subscribe( 49 void subscribe(
53 blink::WebServiceWorkerRegistration* service_worker_registration, 50 blink::WebServiceWorkerRegistration* service_worker_registration,
54 const blink::WebPushSubscriptionOptions& options, 51 const blink::WebPushSubscriptionOptions& options,
55 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; 52 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override;
56 void unsubscribe( 53 void unsubscribe(
57 blink::WebServiceWorkerRegistration* service_worker_registration, 54 blink::WebServiceWorkerRegistration* service_worker_registration,
58 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks) override; 55 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks) override;
59 void getSubscription( 56 void getSubscription(
60 blink::WebServiceWorkerRegistration* service_worker_registration, 57 blink::WebServiceWorkerRegistration* service_worker_registration,
61 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override; 58 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) override;
62 void getPermissionStatus( 59 void getPermissionStatus(
63 blink::WebServiceWorkerRegistration* service_worker_registration, 60 blink::WebServiceWorkerRegistration* service_worker_registration,
64 const blink::WebPushSubscriptionOptions& options, 61 const blink::WebPushSubscriptionOptions& options,
65 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks) 62 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks)
66 override; 63 override;
67 64
68 // Called by the PushDispatcher. 65 private:
69 bool OnMessageReceived(const IPC::Message& message); 66 explicit PushProvider(
67 scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner);
Peter Beverloo 2017/02/16 16:08:33 nit: const&
ke.he 2017/02/17 08:22:34 Done.
70 68
71 private: 69 void SubscribeCallback(
Peter Beverloo 2017/02/16 16:08:33 nit: I have a mild preference of naming these DidF
ke.he 2017/02/17 08:22:37 Yeah, I'll rename it in later. Record this in 6933
72 PushProvider(ThreadSafeSender* thread_safe_sender, 70 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
73 PushDispatcher* push_dispatcher); 71 content::PushRegistrationStatus status,
72 const base::Optional<GURL>& endpoint,
73 const base::Optional<content::PushSubscriptionOptions>& options,
74 const base::Optional<std::vector<uint8_t>>& p256dh,
75 const base::Optional<std::vector<uint8_t>>& auth);
74 76
75 // IPC message handlers. 77 void UnsubscribeCallback(
76 void OnSubscribeFromWorkerSuccess(int request_id, 78 std::unique_ptr<blink::WebPushUnsubscribeCallbacks> callbacks,
77 const GURL& endpoint, 79 bool is_success,
78 const PushSubscriptionOptions& options, 80 bool did_unsubscribe,
79 const std::vector<uint8_t>& p256dh, 81 blink::WebPushError::ErrorType error_type,
80 const std::vector<uint8_t>& auth); 82 const base::Optional<std::string>& error_message);
81 void OnSubscribeFromWorkerError(int request_id,
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 83
98 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 84 void GetSubscriptionCallback(
99 scoped_refptr<PushDispatcher> push_dispatcher_; 85 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks,
86 content::PushGetRegistrationStatus status,
87 const base::Optional<GURL>& endpoint,
88 const base::Optional<content::PushSubscriptionOptions>& options,
89 const base::Optional<std::vector<uint8_t>>& p256dh,
90 const base::Optional<std::vector<uint8_t>>& auth);
Peter Beverloo 2017/02/16 16:08:33 Also as a potential follow-up, we can extract {end
ke.he 2017/02/17 08:22:34 tracked by 693366.
100 91
101 // Stores the subscription callbacks with their request ids. This class owns 92 void GetPermissionStatusCallback(
102 // the callbacks. 93 std::unique_ptr<blink::WebPushPermissionStatusCallbacks> callbacks,
103 IDMap<std::unique_ptr<blink::WebPushSubscriptionCallbacks>> 94 bool is_success,
104 subscription_callbacks_; 95 blink::WebPushPermissionStatus status,
96 blink::WebPushError::ErrorType error);
105 97
106 // Stores the permission status callbacks with their request ids. This class 98 mojom::PushMessagingPtr push_messaging_;
Peter Beverloo 2017/02/16 16:08:33 nit: push_messaging_manager_
ke.he 2017/02/17 08:22:35 Done.
107 // owns the callbacks.
108 IDMap<std::unique_ptr<blink::WebPushPermissionStatusCallbacks>>
109 permission_status_callbacks_;
110
111 // Stores the unsubscription callbacks with their request ids. This class owns
112 // the callbacks.
113 IDMap<std::unique_ptr<blink::WebPushUnsubscribeCallbacks>>
114 unsubscribe_callbacks_;
115 99
116 DISALLOW_COPY_AND_ASSIGN(PushProvider); 100 DISALLOW_COPY_AND_ASSIGN(PushProvider);
117 }; 101 };
118 102
119 } // namespace content 103 } // namespace content
120 104
121 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_ 105 #endif // CONTENT_CHILD_PUSH_MESSAGING_PUSH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698