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

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2529223002: event impl
Patch Set: Event dispatch Created 4 years 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/renderer/service_worker/service_worker_context_client.h ('k') | content/test/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h " 47 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h "
48 #include "content/renderer/service_worker/service_worker_type_util.h" 48 #include "content/renderer/service_worker/service_worker_type_util.h"
49 #include "ipc/ipc_message.h" 49 #include "ipc/ipc_message.h"
50 #include "ipc/ipc_message_macros.h" 50 #include "ipc/ipc_message_macros.h"
51 #include "third_party/WebKit/public/platform/URLConversion.h" 51 #include "third_party/WebKit/public/platform/URLConversion.h"
52 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" 52 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
53 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 53 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
54 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 54 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
55 #include "third_party/WebKit/public/platform/WebString.h" 55 #include "third_party/WebKit/public/platform/WebString.h"
56 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" 56 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h"
57 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque stData.h"
57 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" 58 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h"
58 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" 59 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h"
59 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" 60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h"
60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" 61 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h"
61 #include "third_party/WebKit/public/web/WebDataSource.h" 62 #include "third_party/WebKit/public/web/WebDataSource.h"
62 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" 63 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h"
63 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" 64 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h"
64 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h" 65 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h"
65 66
67 namespace mojo {
68
69 template <>
70 struct TypeConverter<blink::WebPaymentAppRequestData,
71 payments::mojom::PaymentAppRequestDataPtr> {
72 static blink::WebPaymentAppRequestData Convert(
73 const payments::mojom::PaymentAppRequestDataPtr& input) {
74 blink::WebPaymentAppRequestData output;
75 return output;
76 }
77 };
78 }
79
66 namespace content { 80 namespace content {
67 81
68 namespace { 82 namespace {
69 83
70 // For now client must be a per-thread instance. 84 // For now client must be a per-thread instance.
71 base::LazyInstance<base::ThreadLocalPointer<ServiceWorkerContextClient>>:: 85 base::LazyInstance<base::ThreadLocalPointer<ServiceWorkerContextClient>>::
72 Leaky g_worker_client_tls = LAZY_INSTANCE_INITIALIZER; 86 Leaky g_worker_client_tls = LAZY_INSTANCE_INITIALIZER;
73 87
74 void CallWorkerContextDestroyedOnMainThread(int embedded_worker_id) { 88 void CallWorkerContextDestroyedOnMainThread(int embedded_worker_id) {
75 if (!RenderThreadImpl::current() || 89 if (!RenderThreadImpl::current() ||
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 struct ServiceWorkerContextClient::WorkerContextData { 186 struct ServiceWorkerContextClient::WorkerContextData {
173 using ClientsCallbacksMap = 187 using ClientsCallbacksMap =
174 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; 188 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>;
175 using ClaimClientsCallbacksMap = 189 using ClaimClientsCallbacksMap =
176 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; 190 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>;
177 using ClientCallbacksMap = 191 using ClientCallbacksMap =
178 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; 192 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
179 using SkipWaitingCallbacksMap = 193 using SkipWaitingCallbacksMap =
180 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; 194 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
181 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 195 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
196 using PaymentRequestEventCallbacksMap =
197 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
182 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; 198 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
183 using ExtendableMessageEventCallbacksMap = 199 using ExtendableMessageEventCallbacksMap =
184 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; 200 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
185 using NavigationPreloadRequestsMap = IDMap< 201 using NavigationPreloadRequestsMap = IDMap<
186 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; 202 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>;
187 203
188 explicit WorkerContextData(ServiceWorkerContextClient* owner) 204 explicit WorkerContextData(ServiceWorkerContextClient* owner)
189 : event_dispatcher_binding(owner), 205 : event_dispatcher_binding(owner),
190 weak_factory(owner), 206 weak_factory(owner),
191 proxy_weak_factory(owner->proxy_) {} 207 proxy_weak_factory(owner->proxy_) {}
(...skipping 12 matching lines...) Expand all
204 220
205 // Pending callbacks for SkipWaiting(). 221 // Pending callbacks for SkipWaiting().
206 SkipWaitingCallbacksMap skip_waiting_callbacks; 222 SkipWaitingCallbacksMap skip_waiting_callbacks;
207 223
208 // Pending callbacks for ClaimClients(). 224 // Pending callbacks for ClaimClients().
209 ClaimClientsCallbacksMap claim_clients_callbacks; 225 ClaimClientsCallbacksMap claim_clients_callbacks;
210 226
211 // Pending callbacks for Background Sync Events. 227 // Pending callbacks for Background Sync Events.
212 SyncEventCallbacksMap sync_event_callbacks; 228 SyncEventCallbacksMap sync_event_callbacks;
213 229
230 // Pending callbacks for Payment Request Events.
231 PaymentRequestEventCallbacksMap payment_request_event_callbacks;
232
214 // Pending callbacks for Fetch Events. 233 // Pending callbacks for Fetch Events.
215 FetchEventCallbacksMap fetch_event_callbacks; 234 FetchEventCallbacksMap fetch_event_callbacks;
216 235
217 // Pending callbacks for Extendable Message Events. 236 // Pending callbacks for Extendable Message Events.
218 ExtendableMessageEventCallbacksMap message_event_callbacks; 237 ExtendableMessageEventCallbacksMap message_event_callbacks;
219 238
220 // Pending navigation preload requests. 239 // Pending navigation preload requests.
221 NavigationPreloadRequestsMap preload_requests; 240 NavigationPreloadRequestsMap preload_requests;
222 241
223 base::ThreadChecker thread_checker; 242 base::ThreadChecker thread_checker;
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance = 914 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance =
896 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( 915 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>(
897 last_chance); 916 last_chance);
898 917
899 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once 918 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once
900 // https://crrev.com/1768063002/ lands. 919 // https://crrev.com/1768063002/ lands.
901 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), 920 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag),
902 web_last_chance); 921 web_last_chance);
903 } 922 }
904 923
924 void ServiceWorkerContextClient::DispatchPaymentRequestEvent(
925 payments::mojom::PaymentAppRequestDataPtr data,
926 const DispatchPaymentRequestEventCallback& callback) {
927 TRACE_EVENT0("ServiceWorker",
928 "ServiceWorkerContextClient::DispatchPaymentRequestEvent");
929 int request_id = context_->payment_request_event_callbacks.Add(
930 base::MakeUnique<PaymentRequestEventCallback>(callback));
931
932 // TODO(zino): Use typemap when this is moved to blink-side.
933 blink::WebPaymentAppRequestData webData =
934 mojo::ConvertTo<blink::WebPaymentAppRequestData>(std::move(data));
935
936 proxy_->dispatchPaymentRequestEvent(request_id, webData);
937 }
938
905 void ServiceWorkerContextClient::Send(IPC::Message* message) { 939 void ServiceWorkerContextClient::Send(IPC::Message* message) {
906 sender_->Send(message); 940 sender_->Send(message);
907 } 941 }
908 942
909 void ServiceWorkerContextClient::SendWorkerStarted() { 943 void ServiceWorkerContextClient::SendWorkerStarted() {
910 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 944 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
911 TRACE_EVENT_ASYNC_END0("ServiceWorker", 945 TRACE_EVENT_ASYNC_END0("ServiceWorker",
912 "ServiceWorkerContextClient::StartingWorkerContext", 946 "ServiceWorkerContextClient::StartingWorkerContext",
913 this); 947 this);
914 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); 948 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_));
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 } 1310 }
1277 1311
1278 base::WeakPtr<ServiceWorkerContextClient> 1312 base::WeakPtr<ServiceWorkerContextClient>
1279 ServiceWorkerContextClient::GetWeakPtr() { 1313 ServiceWorkerContextClient::GetWeakPtr() {
1280 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1314 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1281 DCHECK(context_); 1315 DCHECK(context_);
1282 return context_->weak_factory.GetWeakPtr(); 1316 return context_->weak_factory.GetWeakPtr();
1283 } 1317 }
1284 1318
1285 } // namespace content 1319 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698