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

Side by Side Diff: content/browser/push_messaging/push_messaging_manager.h

Issue 2690203003: Convert push_messaging IPC msgs into mojo interfaces (Closed)
Patch Set: code rebase 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
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/push_messaging/push_messaging_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ 5 #ifndef CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MANAGER_H_
6 #define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ 6 #define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MANAGER_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 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "content/common/push_messaging.mojom.h"
16 #include "content/common/service_worker/service_worker_status_code.h" 17 #include "content/common/service_worker/service_worker_status_code.h"
17 #include "content/public/browser/browser_message_filter.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/common/push_messaging_status.h" 19 #include "content/public/common/push_messaging_status.h"
20 #include "mojo/public/cpp/bindings/binding_set.h"
19 #include "url/gurl.h" 21 #include "url/gurl.h"
20 22
21 namespace content { 23 namespace content {
22 24
23 class PushMessagingService; 25 class PushMessagingService;
24 class ServiceWorkerContextWrapper; 26 class ServiceWorkerContextWrapper;
25 struct PushSubscriptionOptions; 27 struct PushSubscriptionOptions;
26 28
27 // Documented at definition. 29 // Documented at definition.
28 extern const char kPushSenderIdServiceWorkerKey[]; 30 extern const char kPushSenderIdServiceWorkerKey[];
29 extern const char kPushRegistrationIdServiceWorkerKey[]; 31 extern const char kPushRegistrationIdServiceWorkerKey[];
30 32
31 class PushMessagingMessageFilter : public BrowserMessageFilter { 33 class PushMessagingManager : public mojom::PushMessaging {
32 public: 34 public:
33 PushMessagingMessageFilter( 35 PushMessagingManager(int render_process_id,
34 int render_process_id, 36 ServiceWorkerContextWrapper* service_worker_context);
35 ServiceWorkerContextWrapper* service_worker_context); 37
38 void BindRequest(mojom::PushMessagingRequest request);
39
40 // mojom::PushMessaging impl, run on IO thread.
41 void Subscribe(int32_t render_frame_id,
42 int64_t service_worker_registration_id,
43 const PushSubscriptionOptions& options,
44 const SubscribeCallback& callback) override;
45 void Unsubscribe(int64_t service_worker_registration_id,
46 const UnsubscribeCallback& callback) override;
47 void GetSubscription(int64_t service_worker_registration_id,
48 const GetSubscriptionCallback& callback) override;
49 void GetPermissionStatus(
50 int64_t service_worker_registration_id,
51 bool user_visible,
52 const GetPermissionStatusCallback& callback) override;
36 53
37 private: 54 private:
38 struct RegisterData; 55 struct RegisterData;
39 class Core; 56 class Core;
40 57
41 friend class BrowserThread; 58 friend class BrowserThread;
42 friend class base::DeleteHelper<PushMessagingMessageFilter>; 59 friend class base::DeleteHelper<PushMessagingManager>;
60 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
43 61
44 ~PushMessagingMessageFilter() override; 62 ~PushMessagingManager() override;
45
46 // BrowserMessageFilter implementation.
47 void OnDestruct() const override;
48 bool OnMessageReceived(const IPC::Message& message) override;
49
50 // Subscribe methods on IO thread --------------------------------------------
51
52 void OnSubscribe(int render_frame_id,
53 int request_id,
54 int64_t service_worker_registration_id,
55 const PushSubscriptionOptions& options);
56 63
57 void DidCheckForExistingRegistration( 64 void DidCheckForExistingRegistration(
65 const SubscribeCallback& callback,
58 const RegisterData& data, 66 const RegisterData& data,
59 const std::vector<std::string>& push_registration_id, 67 const std::vector<std::string>& push_registration_id,
60 ServiceWorkerStatusCode service_worker_status); 68 ServiceWorkerStatusCode service_worker_status);
61 69
62 void DidGetEncryptionKeys(const RegisterData& data, 70 void DidGetEncryptionKeys(const SubscribeCallback& callback,
71 const RegisterData& data,
63 const std::string& push_registration_id, 72 const std::string& push_registration_id,
64 bool success, 73 bool success,
65 const std::vector<uint8_t>& p256dh, 74 const std::vector<uint8_t>& p256dh,
66 const std::vector<uint8_t>& auth); 75 const std::vector<uint8_t>& auth);
67 76
68 void DidGetSenderIdFromStorage(const RegisterData& data, 77 void DidGetSenderIdFromStorage(const SubscribeCallback& callback,
78 const RegisterData& data,
69 const std::vector<std::string>& sender_id, 79 const std::vector<std::string>& sender_id,
70 ServiceWorkerStatusCode service_worker_status); 80 ServiceWorkerStatusCode service_worker_status);
71 81
72 // Called via PostTask from UI thread. 82 // Called via PostTask from UI thread.
73 void PersistRegistrationOnIO(const RegisterData& data, 83 void PersistRegistrationOnIO(const SubscribeCallback& callback,
84 const RegisterData& data,
74 const std::string& push_registration_id, 85 const std::string& push_registration_id,
75 const std::vector<uint8_t>& p256dh, 86 const std::vector<uint8_t>& p256dh,
76 const std::vector<uint8_t>& auth); 87 const std::vector<uint8_t>& auth);
77 88
78 void DidPersistRegistrationOnIO( 89 void DidPersistRegistrationOnIO(
90 const SubscribeCallback& callback,
79 const RegisterData& data, 91 const RegisterData& data,
80 const std::string& push_registration_id, 92 const std::string& push_registration_id,
81 const std::vector<uint8_t>& p256dh, 93 const std::vector<uint8_t>& p256dh,
82 const std::vector<uint8_t>& auth, 94 const std::vector<uint8_t>& auth,
83 ServiceWorkerStatusCode service_worker_status); 95 ServiceWorkerStatusCode service_worker_status);
84 96
85 // Called both from IO thread, and via PostTask from UI thread. 97 // Called both from IO thread, and via PostTask from UI thread.
86 void SendSubscriptionError(const RegisterData& data, 98 void SendSubscriptionError(const SubscribeCallback& callback,
99 const RegisterData& data,
87 PushRegistrationStatus status); 100 PushRegistrationStatus status);
88 // Called both from IO thread, and via PostTask from UI thread. 101 // Called both from IO thread, and via PostTask from UI thread.
89 void SendSubscriptionSuccess(const RegisterData& data, 102 void SendSubscriptionSuccess(const SubscribeCallback& callback,
103 const RegisterData& data,
90 PushRegistrationStatus status, 104 PushRegistrationStatus status,
91 const std::string& push_subscription_id, 105 const std::string& push_subscription_id,
92 const std::vector<uint8_t>& p256dh, 106 const std::vector<uint8_t>& p256dh,
93 const std::vector<uint8_t>& auth); 107 const std::vector<uint8_t>& auth);
94 108
95 // Unsubscribe methods on IO thread ------------------------------------------
96
97 void OnUnsubscribe(int request_id, int64_t service_worker_registration_id);
98
99 void UnsubscribeHavingGottenSenderId( 109 void UnsubscribeHavingGottenSenderId(
100 int request_id, 110 const UnsubscribeCallback& callback,
101 int64_t service_worker_registration_id, 111 int64_t service_worker_registration_id,
102 const GURL& requesting_origin, 112 const GURL& requesting_origin,
103 const std::vector<std::string>& sender_id, 113 const std::vector<std::string>& sender_id,
104 ServiceWorkerStatusCode service_worker_status); 114 ServiceWorkerStatusCode service_worker_status);
105 115
106 // Called both from IO thread, and via PostTask from UI thread. 116 // Called both from IO thread, and via PostTask from UI thread.
107 void DidUnregister(int request_id, 117 void DidUnregister(const UnsubscribeCallback& callback,
108 PushUnregistrationStatus unregistration_status); 118 PushUnregistrationStatus unregistration_status);
109 119
110 // GetSubscription methods on IO thread --------------------------------------
111
112 void OnGetSubscription(int request_id,
113 int64_t service_worker_registration_id);
114
115 void DidGetSubscription( 120 void DidGetSubscription(
116 int request_id, 121 const GetSubscriptionCallback& callback,
117 int64_t service_worker_registration_id, 122 int64_t service_worker_registration_id,
118 const std::vector<std::string>& push_subscription_id_and_sender_info, 123 const std::vector<std::string>& push_subscription_id_and_sender_info,
119 ServiceWorkerStatusCode service_worker_status); 124 ServiceWorkerStatusCode service_worker_status);
120 125
121 void DidGetSubscriptionKeys(int request_id, 126 void DidGetSubscriptionKeys(const GetSubscriptionCallback& callback,
122 const GURL& endpoint, 127 const GURL& endpoint,
123 const std::string& sender_info, 128 const std::string& sender_info,
124 bool success, 129 bool success,
125 const std::vector<uint8_t>& p256dh, 130 const std::vector<uint8_t>& p256dh,
126 const std::vector<uint8_t>& auth); 131 const std::vector<uint8_t>& auth);
127 132
128 // GetPermission methods on IO thread ----------------------------------------
129
130 void OnGetPermissionStatus(int request_id,
131 int64_t service_worker_registration_id,
132 bool user_visible);
133
134 // Helper methods on IO thread -----------------------------------------------
135
136 // Called via PostTask from UI thread.
137 void SendIPC(std::unique_ptr<IPC::Message> message);
138
139 // Helper methods on either thread ------------------------------------------- 133 // Helper methods on either thread -------------------------------------------
140 134
141 // Creates an endpoint for |subscription_id| with either the default protocol, 135 // Creates an endpoint for |subscription_id| with either the default protocol,
142 // or the standardized Web Push Protocol, depending on |standard_protocol|. 136 // or the standardized Web Push Protocol, depending on |standard_protocol|.
143 GURL CreateEndpoint(bool standard_protocol, 137 GURL CreateEndpoint(bool standard_protocol,
144 const std::string& subscription_id) const; 138 const std::string& subscription_id) const;
145 139
146 // Inner core of this message filter which lives on the UI thread. 140 // Inner core of this message filter which lives on the UI thread.
147 std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_; 141 std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_;
148 142
149 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 143 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
150 144
151 // Whether the PushMessagingService was available when constructed. 145 // Whether the PushMessagingService was available when constructed.
152 bool service_available_; 146 bool service_available_;
153 147
154 GURL default_endpoint_; 148 GURL default_endpoint_;
155 GURL web_push_protocol_endpoint_; 149 GURL web_push_protocol_endpoint_;
156 150
157 base::WeakPtrFactory<PushMessagingMessageFilter> weak_factory_io_to_io_; 151 mojo::BindingSet<mojom::PushMessaging> bindings_;
158 152
159 DISALLOW_COPY_AND_ASSIGN(PushMessagingMessageFilter); 153 base::WeakPtrFactory<PushMessagingManager> weak_factory_io_to_io_;
154
155 DISALLOW_COPY_AND_ASSIGN(PushMessagingManager);
160 }; 156 };
161 157
162 } // namespace content 158 } // namespace content
163 159
164 #endif // CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ 160 #endif // CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/push_messaging/push_messaging_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698