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

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

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: rebase/fix comment 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
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/threading/thread_local.h" 15 #include "base/threading/thread_local.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "content/child/background_sync/background_sync_type_converters.h"
19 #include "content/child/notifications/notification_data_conversions.h" 20 #include "content/child/notifications/notification_data_conversions.h"
20 #include "content/child/request_extra_data.h" 21 #include "content/child/request_extra_data.h"
21 #include "content/child/service_worker/service_worker_dispatcher.h" 22 #include "content/child/service_worker/service_worker_dispatcher.h"
22 #include "content/child/service_worker/service_worker_handle_reference.h" 23 #include "content/child/service_worker/service_worker_handle_reference.h"
23 #include "content/child/service_worker/service_worker_network_provider.h" 24 #include "content/child/service_worker/service_worker_network_provider.h"
24 #include "content/child/service_worker/service_worker_provider_context.h" 25 #include "content/child/service_worker/service_worker_provider_context.h"
25 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" 26 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
26 #include "content/child/service_worker/web_service_worker_impl.h" 27 #include "content/child/service_worker/web_service_worker_impl.h"
27 #include "content/child/service_worker/web_service_worker_provider_impl.h" 28 #include "content/child/service_worker/web_service_worker_provider_impl.h"
28 #include "content/child/service_worker/web_service_worker_registration_impl.h" 29 #include "content/child/service_worker/web_service_worker_registration_impl.h"
29 #include "content/child/thread_safe_sender.h" 30 #include "content/child/thread_safe_sender.h"
30 #include "content/child/web_data_consumer_handle_impl.h" 31 #include "content/child/web_data_consumer_handle_impl.h"
31 #include "content/child/webmessageportchannel_impl.h" 32 #include "content/child/webmessageportchannel_impl.h"
32 #include "content/common/devtools_messages.h" 33 #include "content/common/devtools_messages.h"
33 #include "content/common/message_port_messages.h" 34 #include "content/common/message_port_messages.h"
34 #include "content/common/service_worker/embedded_worker_messages.h" 35 #include "content/common/service_worker/embedded_worker_messages.h"
35 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" 36 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
36 #include "content/common/service_worker/service_worker_messages.h" 37 #include "content/common/service_worker/service_worker_messages.h"
37 #include "content/common/service_worker/service_worker_status_code.h" 38 #include "content/common/service_worker/service_worker_status_code.h"
38 #include "content/common/service_worker/service_worker_utils.h" 39 #include "content/common/service_worker/service_worker_utils.h"
39 #include "content/public/common/push_event_payload.h" 40 #include "content/public/common/push_event_payload.h"
40 #include "content/public/common/referrer.h" 41 #include "content/public/common/referrer.h"
41 #include "content/public/renderer/content_renderer_client.h" 42 #include "content/public/renderer/content_renderer_client.h"
42 #include "content/public/renderer/document_state.h" 43 #include "content/public/renderer/document_state.h"
43 #include "content/renderer/background_sync/background_sync_client_impl.h"
44 #include "content/renderer/devtools/devtools_agent.h" 44 #include "content/renderer/devtools/devtools_agent.h"
45 #include "content/renderer/render_thread_impl.h" 45 #include "content/renderer/render_thread_impl.h"
46 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" 46 #include "content/renderer/service_worker/embedded_worker_dispatcher.h"
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 "mojo/public/cpp/bindings/interface_request.h"
52 #include "mojo/public/cpp/bindings/strong_binding.h"
53 #include "services/service_manager/public/cpp/interface_provider.h"
54 #include "services/service_manager/public/cpp/interface_registry.h"
55 #include "third_party/WebKit/public/platform/URLConversion.h" 51 #include "third_party/WebKit/public/platform/URLConversion.h"
56 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" 52 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
57 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 53 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
58 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 54 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
59 #include "third_party/WebKit/public/platform/WebString.h" 55 #include "third_party/WebKit/public/platform/WebString.h"
60 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" 56 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h"
61 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" 57 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h"
62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" 58 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h"
63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" 59 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h"
64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" 60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // worker thread. 171 // worker thread.
176 struct ServiceWorkerContextClient::WorkerContextData { 172 struct ServiceWorkerContextClient::WorkerContextData {
177 using ClientsCallbacksMap = 173 using ClientsCallbacksMap =
178 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; 174 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>;
179 using ClaimClientsCallbacksMap = 175 using ClaimClientsCallbacksMap =
180 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; 176 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>;
181 using ClientCallbacksMap = 177 using ClientCallbacksMap =
182 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; 178 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>;
183 using SkipWaitingCallbacksMap = 179 using SkipWaitingCallbacksMap =
184 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; 180 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>;
185 using SyncEventCallbacksMap = 181 using SyncEventCallbacksMap = IDMap<const SyncCallback, IDMapOwnPointer>;
186 IDMap<const base::Callback<void(blink::mojom::ServiceWorkerEventStatus, 182 using FetchEventCallbacksMap = IDMap<const FetchCallback, IDMapOwnPointer>;
187 base::Time /* dispatch_event_time */)>,
188 IDMapOwnPointer>;
189 using FetchEventCallbacksMap =
190 IDMap<const base::Callback<void(ServiceWorkerStatusCode,
191 base::Time /* dispatch_event_time */)>,
192 IDMapOwnPointer>;
193 using NavigationPreloadRequestsMap = 183 using NavigationPreloadRequestsMap =
194 IDMap<ServiceWorkerContextClient::NavigationPreloadRequest, 184 IDMap<ServiceWorkerContextClient::NavigationPreloadRequest,
195 IDMapOwnPointer>; 185 IDMapOwnPointer>;
196 186
197 explicit WorkerContextData(ServiceWorkerContextClient* owner) 187 explicit WorkerContextData(ServiceWorkerContextClient* owner)
198 : interface_registry(std::string()), 188 : event_dispatcher_binding(owner),
199 weak_factory(owner), 189 weak_factory(owner),
200 proxy_weak_factory(owner->proxy_) {} 190 proxy_weak_factory(owner->proxy_) {}
201 191
202 ~WorkerContextData() { 192 ~WorkerContextData() {
203 DCHECK(thread_checker.CalledOnValidThread()); 193 DCHECK(thread_checker.CalledOnValidThread());
204 } 194 }
205 195
196 mojo::Binding<mojom::ServiceWorkerEventDispatcher> event_dispatcher_binding;
197
206 // Pending callbacks for GetClientDocuments(). 198 // Pending callbacks for GetClientDocuments().
207 ClientsCallbacksMap clients_callbacks; 199 ClientsCallbacksMap clients_callbacks;
208 200
209 // Pending callbacks for OpenWindow() and FocusClient(). 201 // Pending callbacks for OpenWindow() and FocusClient().
210 ClientCallbacksMap client_callbacks; 202 ClientCallbacksMap client_callbacks;
211 203
212 // Pending callbacks for SkipWaiting(). 204 // Pending callbacks for SkipWaiting().
213 SkipWaitingCallbacksMap skip_waiting_callbacks; 205 SkipWaitingCallbacksMap skip_waiting_callbacks;
214 206
215 // Pending callbacks for ClaimClients(). 207 // Pending callbacks for ClaimClients().
216 ClaimClientsCallbacksMap claim_clients_callbacks; 208 ClaimClientsCallbacksMap claim_clients_callbacks;
217 209
218 // Pending callbacks for Background Sync Events. 210 // Pending callbacks for Background Sync Events.
219 SyncEventCallbacksMap sync_event_callbacks; 211 SyncEventCallbacksMap sync_event_callbacks;
220 212
221 // Pending callbacks for Fetch Events. 213 // Pending callbacks for Fetch Events.
222 FetchEventCallbacksMap fetch_event_callbacks; 214 FetchEventCallbacksMap fetch_event_callbacks;
223 215
224 // Pending navigation preload requests. 216 // Pending navigation preload requests.
225 NavigationPreloadRequestsMap preload_requests; 217 NavigationPreloadRequestsMap preload_requests;
226 218
227 service_manager::InterfaceRegistry interface_registry;
228 // This is not used when mojo for the service workers is enabled. At that
229 // time, remote interfaces are stored in EmbeddedWorkerInstanceClientImpl.
230 service_manager::InterfaceProvider remote_interfaces;
231
232 base::ThreadChecker thread_checker; 219 base::ThreadChecker thread_checker;
233 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; 220 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory;
234 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; 221 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory;
235 }; 222 };
236 223
237 class ServiceWorkerContextClient::NavigationPreloadRequest final 224 class ServiceWorkerContextClient::NavigationPreloadRequest final
238 : public mojom::URLLoaderClient { 225 : public mojom::URLLoaderClient {
239 public: 226 public:
240 NavigationPreloadRequest(int fetch_event_id, 227 NavigationPreloadRequest(int fetch_event_id,
241 const GURL& url, 228 const GURL& url,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 const int fetch_event_id_; 329 const int fetch_event_id_;
343 const GURL url_; 330 const GURL url_;
344 mojom::URLLoaderPtr url_loader_; 331 mojom::URLLoaderPtr url_loader_;
345 mojo::Binding<mojom::URLLoaderClient> binding_; 332 mojo::Binding<mojom::URLLoaderClient> binding_;
346 333
347 std::unique_ptr<blink::WebServiceWorkerResponse> response_; 334 std::unique_ptr<blink::WebServiceWorkerResponse> response_;
348 mojo::ScopedDataPipeConsumerHandle body_; 335 mojo::ScopedDataPipeConsumerHandle body_;
349 bool result_reported_ = false; 336 bool result_reported_ = false;
350 }; 337 };
351 338
352 class ServiceWorkerContextClient::FetchEventDispatcherImpl
353 : public NON_EXPORTED_BASE(mojom::FetchEventDispatcher) {
354 public:
355 static void Create(mojom::FetchEventDispatcherRequest request) {
356 mojo::MakeStrongBinding(base::MakeUnique<FetchEventDispatcherImpl>(),
357 std::move(request));
358 }
359
360 FetchEventDispatcherImpl() {}
361
362 ~FetchEventDispatcherImpl() override {}
363
364 void DispatchFetchEvent(int fetch_event_id,
365 const ServiceWorkerFetchRequest& request,
366 mojom::FetchEventPreloadHandlePtr preload_handle,
367 const DispatchFetchEventCallback& callback) override {
368 ServiceWorkerContextClient* client =
369 ServiceWorkerContextClient::ThreadSpecificInstance();
370 if (!client) {
371 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
372 return;
373 }
374 client->DispatchFetchEvent(
375 fetch_event_id, request,
376 preload_handle
377 ? base::MakeUnique<NavigationPreloadRequest>(
378 fetch_event_id, request.url, std::move(preload_handle))
379 : nullptr,
380 callback);
381 }
382
383 private:
384 DISALLOW_COPY_AND_ASSIGN(FetchEventDispatcherImpl);
385 };
386
387 ServiceWorkerContextClient* 339 ServiceWorkerContextClient*
388 ServiceWorkerContextClient::ThreadSpecificInstance() { 340 ServiceWorkerContextClient::ThreadSpecificInstance() {
389 return g_worker_client_tls.Pointer()->Get(); 341 return g_worker_client_tls.Pointer()->Get();
390 } 342 }
391 343
392 ServiceWorkerContextClient::ServiceWorkerContextClient( 344 ServiceWorkerContextClient::ServiceWorkerContextClient(
393 int embedded_worker_id, 345 int embedded_worker_id,
394 int64_t service_worker_version_id, 346 int64_t service_worker_version_id,
395 const GURL& service_worker_scope, 347 const GURL& service_worker_scope,
396 const GURL& script_url, 348 const GURL& script_url,
397 int worker_devtools_agent_route_id, 349 int worker_devtools_agent_route_id,
350 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
398 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) 351 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client)
399 : embedded_worker_id_(embedded_worker_id), 352 : embedded_worker_id_(embedded_worker_id),
400 service_worker_version_id_(service_worker_version_id), 353 service_worker_version_id_(service_worker_version_id),
401 service_worker_scope_(service_worker_scope), 354 service_worker_scope_(service_worker_scope),
402 script_url_(script_url), 355 script_url_(script_url),
403 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), 356 worker_devtools_agent_route_id_(worker_devtools_agent_route_id),
404 sender_(ChildThreadImpl::current()->thread_safe_sender()), 357 sender_(ChildThreadImpl::current()->thread_safe_sender()),
405 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 358 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
406 proxy_(nullptr), 359 proxy_(nullptr),
360 pending_dispatcher_request_(std::move(dispatcher_request)),
407 embedded_worker_client_(std::move(embedded_worker_client)) { 361 embedded_worker_client_(std::move(embedded_worker_client)) {
408 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", 362 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
409 "ServiceWorkerContextClient::StartingWorkerContext", 363 "ServiceWorkerContextClient::StartingWorkerContext",
410 this); 364 this);
411 TRACE_EVENT_ASYNC_STEP_INTO0( 365 TRACE_EVENT_ASYNC_STEP_INTO0(
412 "ServiceWorker", 366 "ServiceWorker",
413 "ServiceWorkerContextClient::StartingWorkerContext", 367 "ServiceWorkerContextClient::StartingWorkerContext",
414 this, 368 this,
415 "PrepareWorker"); 369 "PrepareWorker");
416 } 370 }
417 371
372 ServiceWorkerContextClient::ServiceWorkerContextClient(
373 int embedded_worker_id,
374 int64_t service_worker_version_id,
375 const GURL& service_worker_scope,
376 const GURL& script_url,
377 int worker_devtools_agent_route_id)
378 : ServiceWorkerContextClient::ServiceWorkerContextClient(
379 embedded_worker_id,
380 service_worker_version_id,
381 service_worker_scope,
382 script_url,
383 worker_devtools_agent_route_id,
384 mojom::ServiceWorkerEventDispatcherRequest(),
385 nullptr) {}
386
418 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} 387 ServiceWorkerContextClient::~ServiceWorkerContextClient() {}
419 388
420 void ServiceWorkerContextClient::OnMessageReceived( 389 void ServiceWorkerContextClient::OnMessageReceived(
421 int thread_id, 390 int thread_id,
422 int embedded_worker_id, 391 int embedded_worker_id,
423 const IPC::Message& message) { 392 const IPC::Message& message) {
424 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 393 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
425 bool handled = true; 394 bool handled = true;
426 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) 395 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
427 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) 396 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
(...skipping 19 matching lines...) Expand all
447 OnNavigateClientError) 416 OnNavigateClientError)
448 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) 417 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting)
449 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) 418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients)
450 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) 419 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError)
451 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); 420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing);
452 IPC_MESSAGE_UNHANDLED(handled = false) 421 IPC_MESSAGE_UNHANDLED(handled = false)
453 IPC_END_MESSAGE_MAP() 422 IPC_END_MESSAGE_MAP()
454 DCHECK(handled); 423 DCHECK(handled);
455 } 424 }
456 425
457 void ServiceWorkerContextClient::BindInterfaceProviders(
458 service_manager::mojom::InterfaceProviderRequest request,
459 service_manager::mojom::InterfaceProviderPtr remote_interfaces) {
460 context_->interface_registry.Bind(
461 std::move(request), service_manager::Identity(),
462 service_manager::InterfaceProviderSpec(), service_manager::Identity(),
463 service_manager::InterfaceProviderSpec());
464 context_->remote_interfaces.Bind(std::move(remote_interfaces));
465 }
466
467 blink::WebURL ServiceWorkerContextClient::scope() const { 426 blink::WebURL ServiceWorkerContextClient::scope() const {
468 return service_worker_scope_; 427 return service_worker_scope_;
469 } 428 }
470 429
471 void ServiceWorkerContextClient::getClient( 430 void ServiceWorkerContextClient::getClient(
472 const blink::WebString& id, 431 const blink::WebString& id,
473 blink::WebServiceWorkerClientCallbacks* callbacks) { 432 blink::WebServiceWorkerClientCallbacks* callbacks) {
474 DCHECK(callbacks); 433 DCHECK(callbacks);
475 int request_id = context_->client_callbacks.Add(callbacks); 434 int request_id = context_->client_callbacks.Add(callbacks);
476 Send(new ServiceWorkerHostMsg_GetClient( 435 Send(new ServiceWorkerHostMsg_GetClient(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 // willDestroyWorkerContext. 511 // willDestroyWorkerContext.
553 context_.reset(new WorkerContextData(this)); 512 context_.reset(new WorkerContextData(this));
554 513
555 ServiceWorkerRegistrationObjectInfo registration_info; 514 ServiceWorkerRegistrationObjectInfo registration_info;
556 ServiceWorkerVersionAttributes version_attrs; 515 ServiceWorkerVersionAttributes version_attrs;
557 provider_context_->GetAssociatedRegistration(&registration_info, 516 provider_context_->GetAssociatedRegistration(&registration_info,
558 &version_attrs); 517 &version_attrs);
559 DCHECK_NE(registration_info.registration_id, 518 DCHECK_NE(registration_info.registration_id,
560 kInvalidServiceWorkerRegistrationId); 519 kInvalidServiceWorkerRegistrationId);
561 520
562 // Register Mojo interfaces.
563 context_->interface_registry.AddInterface(
564 base::Bind(&BackgroundSyncClientImpl::Create));
565 context_->interface_registry.AddInterface(
566 base::Bind(&FetchEventDispatcherImpl::Create));
567
568 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { 521 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) {
569 DCHECK(embedded_worker_client_); 522 DCHECK(pending_dispatcher_request_.is_pending());
570 embedded_worker_client_->ExposeInterfacesToBrowser( 523 BindEventDispatcher(std::move(pending_dispatcher_request_));
571 &context_->interface_registry);
572 } 524 }
573 525
574 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); 526 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs);
575 527
576 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( 528 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted(
577 embedded_worker_id_, WorkerThread::GetCurrentId(), 529 embedded_worker_id_, WorkerThread::GetCurrentId(),
578 provider_context_->provider_id())); 530 provider_context_->provider_id()));
579 531
580 TRACE_EVENT_ASYNC_STEP_INTO0( 532 TRACE_EVENT_ASYNC_STEP_INTO0(
581 "ServiceWorker", 533 "ServiceWorker",
(...skipping 26 matching lines...) Expand all
608 v8::Local<v8::Context> context) { 560 v8::Local<v8::Context> context) {
609 // At this point WillStopCurrentWorkerThread is already called, so 561 // At this point WillStopCurrentWorkerThread is already called, so
610 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 562 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
611 // (while we're still on the worker thread). 563 // (while we're still on the worker thread).
612 proxy_ = NULL; 564 proxy_ = NULL;
613 565
614 // Aborts the all pending sync event callbacks. 566 // Aborts the all pending sync event callbacks.
615 for (WorkerContextData::SyncEventCallbacksMap::iterator it( 567 for (WorkerContextData::SyncEventCallbacksMap::iterator it(
616 &context_->sync_event_callbacks); 568 &context_->sync_event_callbacks);
617 !it.IsAtEnd(); it.Advance()) { 569 !it.IsAtEnd(); it.Advance()) {
618 it.GetCurrentValue()->Run(blink::mojom::ServiceWorkerEventStatus::ABORTED, 570 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
619 base::Time::Now());
620 } 571 }
621 // Aborts the all pending fetch event callbacks. 572 // Aborts the all pending fetch event callbacks.
622 for (WorkerContextData::FetchEventCallbacksMap::iterator it( 573 for (WorkerContextData::FetchEventCallbacksMap::iterator it(
623 &context_->fetch_event_callbacks); 574 &context_->fetch_event_callbacks);
624 !it.IsAtEnd(); it.Advance()) { 575 !it.IsAtEnd(); it.Advance()) {
625 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); 576 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
626 } 577 }
627 578
628 // We have to clear callbacks now, as they need to be freed on the 579 // We have to clear callbacks now, as they need to be freed on the
629 // same thread. 580 // same thread.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 761
811 void ServiceWorkerContextClient::didHandleSyncEvent( 762 void ServiceWorkerContextClient::didHandleSyncEvent(
812 int request_id, 763 int request_id,
813 blink::WebServiceWorkerEventResult result, 764 blink::WebServiceWorkerEventResult result,
814 double event_dispatch_time) { 765 double event_dispatch_time) {
815 const SyncCallback* callback = 766 const SyncCallback* callback =
816 context_->sync_event_callbacks.Lookup(request_id); 767 context_->sync_event_callbacks.Lookup(request_id);
817 if (!callback) 768 if (!callback)
818 return; 769 return;
819 if (result == blink::WebServiceWorkerEventResultCompleted) { 770 if (result == blink::WebServiceWorkerEventResultCompleted) {
820 callback->Run(blink::mojom::ServiceWorkerEventStatus::COMPLETED, 771 callback->Run(SERVICE_WORKER_OK,
821 base::Time::FromDoubleT(event_dispatch_time)); 772 base::Time::FromDoubleT(event_dispatch_time));
822 } else { 773 } else {
823 callback->Run(blink::mojom::ServiceWorkerEventStatus::REJECTED, 774 callback->Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
824 base::Time::FromDoubleT(event_dispatch_time)); 775 base::Time::FromDoubleT(event_dispatch_time));
825 } 776 }
826 context_->sync_event_callbacks.Remove(request_id); 777 context_->sync_event_callbacks.Remove(request_id);
827 } 778 }
828 779
829 blink::WebServiceWorkerNetworkProvider* 780 blink::WebServiceWorkerNetworkProvider*
830 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( 781 ServiceWorkerContextClient::createServiceWorkerNetworkProvider(
831 blink::WebDataSource* data_source) { 782 blink::WebDataSource* data_source) {
832 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 783 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
833 784
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 void ServiceWorkerContextClient::registerForeignFetchScopes( 877 void ServiceWorkerContextClient::registerForeignFetchScopes(
927 const blink::WebVector<blink::WebURL>& sub_scopes, 878 const blink::WebVector<blink::WebURL>& sub_scopes,
928 const blink::WebVector<blink::WebSecurityOrigin>& origins) { 879 const blink::WebVector<blink::WebSecurityOrigin>& origins) {
929 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( 880 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes(
930 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), 881 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()),
931 std::vector<url::Origin>(origins.begin(), origins.end()))); 882 std::vector<url::Origin>(origins.begin(), origins.end())));
932 } 883 }
933 884
934 void ServiceWorkerContextClient::DispatchSyncEvent( 885 void ServiceWorkerContextClient::DispatchSyncEvent(
935 const std::string& tag, 886 const std::string& tag,
936 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, 887 blink::mojom::BackgroundSyncEventLastChance last_chance,
937 const SyncCallback& callback) { 888 const DispatchSyncEventCallback& callback) {
938 TRACE_EVENT0("ServiceWorker", 889 TRACE_EVENT0("ServiceWorker",
939 "ServiceWorkerContextClient::DispatchSyncEvent"); 890 "ServiceWorkerContextClient::DispatchSyncEvent");
940 int request_id = 891 int request_id =
941 context_->sync_event_callbacks.Add(new SyncCallback(callback)); 892 context_->sync_event_callbacks.Add(new SyncCallback(callback));
942 893
894 // TODO(shimazu): Use typemap when this is moved to blink-side.
895 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance =
896 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>(
897 last_chance);
898
943 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once 899 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once
944 // https://crrev.com/1768063002/ lands. 900 // https://crrev.com/1768063002/ lands.
945 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), 901 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag),
946 last_chance); 902 web_last_chance);
947 } 903 }
948 904
949 void ServiceWorkerContextClient::Send(IPC::Message* message) { 905 void ServiceWorkerContextClient::Send(IPC::Message* message) {
950 sender_->Send(message); 906 sender_->Send(message);
951 } 907 }
952 908
953 void ServiceWorkerContextClient::SendWorkerStarted() { 909 void ServiceWorkerContextClient::SendWorkerStarted() {
954 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 910 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
955 TRACE_EVENT_ASYNC_END0("ServiceWorker", 911 TRACE_EVENT_ASYNC_END0("ServiceWorker",
956 "ServiceWorkerContextClient::StartingWorkerContext", 912 "ServiceWorkerContextClient::StartingWorkerContext",
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 970
1015 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { 971 void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
1016 TRACE_EVENT0("ServiceWorker", 972 TRACE_EVENT0("ServiceWorker",
1017 "ServiceWorkerContextClient::OnInstallEvent"); 973 "ServiceWorkerContextClient::OnInstallEvent");
1018 proxy_->dispatchInstallEvent(request_id); 974 proxy_->dispatchInstallEvent(request_id);
1019 } 975 }
1020 976
1021 void ServiceWorkerContextClient::DispatchFetchEvent( 977 void ServiceWorkerContextClient::DispatchFetchEvent(
1022 int fetch_event_id, 978 int fetch_event_id,
1023 const ServiceWorkerFetchRequest& request, 979 const ServiceWorkerFetchRequest& request,
1024 std::unique_ptr<NavigationPreloadRequest> preload_request, 980 mojom::FetchEventPreloadHandlePtr preload_handle,
1025 const FetchCallback& callback) { 981 const DispatchFetchEventCallback& callback) {
982 std::unique_ptr<NavigationPreloadRequest> preload_request =
983 preload_handle
984 ? base::MakeUnique<NavigationPreloadRequest>(
985 fetch_event_id, request.url, std::move(preload_handle))
986 : nullptr;
1026 const bool navigation_preload_sent = !!preload_request; 987 const bool navigation_preload_sent = !!preload_request;
1027 blink::WebServiceWorkerRequest webRequest; 988 blink::WebServiceWorkerRequest webRequest;
1028 TRACE_EVENT0("ServiceWorker", 989 TRACE_EVENT0("ServiceWorker",
1029 "ServiceWorkerContextClient::DispatchFetchEvent"); 990 "ServiceWorkerContextClient::DispatchFetchEvent");
1030 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), 991 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback),
1031 fetch_event_id); 992 fetch_event_id);
1032 if (preload_request) { 993 if (preload_request) {
1033 context_->preload_requests.AddWithID(std::move(preload_request), 994 context_->preload_requests.AddWithID(std::move(preload_request),
1034 fetch_event_id); 995 fetch_event_id);
1035 } 996 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), 1258 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response),
1298 std::move(data_consumer_handle)); 1259 std::move(data_consumer_handle));
1299 } 1260 }
1300 1261
1301 void ServiceWorkerContextClient::OnNavigationPreloadError( 1262 void ServiceWorkerContextClient::OnNavigationPreloadError(
1302 int fetch_event_id, 1263 int fetch_event_id,
1303 std::unique_ptr<blink::WebServiceWorkerError> error) { 1264 std::unique_ptr<blink::WebServiceWorkerError> error) {
1304 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); 1265 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error));
1305 } 1266 }
1306 1267
1268 void ServiceWorkerContextClient::BindEventDispatcher(
1269 mojom::ServiceWorkerEventDispatcherRequest request) {
1270 DCHECK(context_);
1271 DCHECK(!context_->event_dispatcher_binding.is_bound());
1272 context_->event_dispatcher_binding.Bind(std::move(request));
1273 }
1274
1307 base::WeakPtr<ServiceWorkerContextClient> 1275 base::WeakPtr<ServiceWorkerContextClient>
1308 ServiceWorkerContextClient::GetWeakPtr() { 1276 ServiceWorkerContextClient::GetWeakPtr() {
1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1277 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1310 DCHECK(context_); 1278 DCHECK(context_);
1311 return context_->weak_factory.GetWeakPtr(); 1279 return context_->weak_factory.GetWeakPtr();
1312 } 1280 }
1313 1281
1314 } // namespace content 1282 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698