| OLD | NEW |
| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 391 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 392 "ServiceWorkerContextClient::StartingWorkerContext", | 392 "ServiceWorkerContextClient::StartingWorkerContext", |
| 393 this); | 393 this); |
| 394 TRACE_EVENT_ASYNC_STEP_INTO0( | 394 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 395 "ServiceWorker", | 395 "ServiceWorker", |
| 396 "ServiceWorkerContextClient::StartingWorkerContext", | 396 "ServiceWorkerContextClient::StartingWorkerContext", |
| 397 this, | 397 this, |
| 398 "PrepareWorker"); | 398 "PrepareWorker"); |
| 399 } | 399 } |
| 400 | 400 |
| 401 ServiceWorkerContextClient::ServiceWorkerContextClient( | |
| 402 int embedded_worker_id, | |
| 403 int64_t service_worker_version_id, | |
| 404 const GURL& service_worker_scope, | |
| 405 const GURL& script_url, | |
| 406 int worker_devtools_agent_route_id) | |
| 407 : ServiceWorkerContextClient::ServiceWorkerContextClient( | |
| 408 embedded_worker_id, | |
| 409 service_worker_version_id, | |
| 410 service_worker_scope, | |
| 411 script_url, | |
| 412 worker_devtools_agent_route_id, | |
| 413 mojom::ServiceWorkerEventDispatcherRequest(), | |
| 414 nullptr) {} | |
| 415 | |
| 416 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 401 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
| 417 | 402 |
| 418 void ServiceWorkerContextClient::OnMessageReceived( | 403 void ServiceWorkerContextClient::OnMessageReceived( |
| 419 int thread_id, | 404 int thread_id, |
| 420 int embedded_worker_id, | 405 int embedded_worker_id, |
| 421 const IPC::Message& message) { | 406 const IPC::Message& message) { |
| 422 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 407 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
| 423 bool handled = true; | 408 bool handled = true; |
| 424 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) | 409 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) |
| 425 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | 410 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 // willDestroyWorkerContext. | 522 // willDestroyWorkerContext. |
| 538 context_.reset(new WorkerContextData(this)); | 523 context_.reset(new WorkerContextData(this)); |
| 539 | 524 |
| 540 ServiceWorkerRegistrationObjectInfo registration_info; | 525 ServiceWorkerRegistrationObjectInfo registration_info; |
| 541 ServiceWorkerVersionAttributes version_attrs; | 526 ServiceWorkerVersionAttributes version_attrs; |
| 542 provider_context_->GetAssociatedRegistration(®istration_info, | 527 provider_context_->GetAssociatedRegistration(®istration_info, |
| 543 &version_attrs); | 528 &version_attrs); |
| 544 DCHECK_NE(registration_info.registration_id, | 529 DCHECK_NE(registration_info.registration_id, |
| 545 kInvalidServiceWorkerRegistrationId); | 530 kInvalidServiceWorkerRegistrationId); |
| 546 | 531 |
| 547 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 532 DCHECK(pending_dispatcher_request_.is_pending()); |
| 548 DCHECK(pending_dispatcher_request_.is_pending()); | 533 DCHECK(!context_->event_dispatcher_binding.is_bound()); |
| 549 BindEventDispatcher(std::move(pending_dispatcher_request_)); | 534 context_->event_dispatcher_binding.Bind( |
| 550 } | 535 std::move(pending_dispatcher_request_)); |
| 551 | 536 |
| 552 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); | 537 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); |
| 553 | 538 |
| 554 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( | 539 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( |
| 555 embedded_worker_id_, WorkerThread::GetCurrentId(), | 540 embedded_worker_id_, WorkerThread::GetCurrentId(), |
| 556 provider_context_->provider_id())); | 541 provider_context_->provider_id())); |
| 557 | 542 |
| 558 TRACE_EVENT_ASYNC_STEP_INTO0( | 543 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 559 "ServiceWorker", | 544 "ServiceWorker", |
| 560 "ServiceWorkerContextClient::StartingWorkerContext", | 545 "ServiceWorkerContextClient::StartingWorkerContext", |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), | 1253 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), |
| 1269 std::move(data_consumer_handle)); | 1254 std::move(data_consumer_handle)); |
| 1270 } | 1255 } |
| 1271 | 1256 |
| 1272 void ServiceWorkerContextClient::OnNavigationPreloadError( | 1257 void ServiceWorkerContextClient::OnNavigationPreloadError( |
| 1273 int fetch_event_id, | 1258 int fetch_event_id, |
| 1274 std::unique_ptr<blink::WebServiceWorkerError> error) { | 1259 std::unique_ptr<blink::WebServiceWorkerError> error) { |
| 1275 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); | 1260 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); |
| 1276 } | 1261 } |
| 1277 | 1262 |
| 1278 void ServiceWorkerContextClient::BindEventDispatcher( | |
| 1279 mojom::ServiceWorkerEventDispatcherRequest request) { | |
| 1280 DCHECK(context_); | |
| 1281 DCHECK(!context_->event_dispatcher_binding.is_bound()); | |
| 1282 context_->event_dispatcher_binding.Bind(std::move(request)); | |
| 1283 } | |
| 1284 | |
| 1285 base::WeakPtr<ServiceWorkerContextClient> | 1263 base::WeakPtr<ServiceWorkerContextClient> |
| 1286 ServiceWorkerContextClient::GetWeakPtr() { | 1264 ServiceWorkerContextClient::GetWeakPtr() { |
| 1287 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1265 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1288 DCHECK(context_); | 1266 DCHECK(context_); |
| 1289 return context_->weak_factory.GetWeakPtr(); | 1267 return context_->weak_factory.GetWeakPtr(); |
| 1290 } | 1268 } |
| 1291 | 1269 |
| 1292 } // namespace content | 1270 } // namespace content |
| OLD | NEW |