| OLD | NEW |
| 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 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" | 5 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job, | 32 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job, |
| 33 const ServiceWorkerVersion* version) { | 33 const ServiceWorkerVersion* version) { |
| 34 DCHECK(job); | 34 DCHECK(job); |
| 35 DCHECK(version); | 35 DCHECK(version); |
| 36 if (version->has_fetch_handler()) { | 36 DCHECK_NE(version->fetch_handler_existence(), |
| 37 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
| 38 if (version->fetch_handler_existence() == |
| 39 ServiceWorkerVersion::FetchHandlerExistence::EXISTS) { |
| 37 job->ForwardToServiceWorker(); | 40 job->ForwardToServiceWorker(); |
| 38 return true; | 41 return true; |
| 39 } | 42 } |
| 40 | 43 |
| 41 job->FallbackToNetworkOrRenderer(); | 44 job->FallbackToNetworkOrRenderer(); |
| 42 return false; | 45 return false; |
| 43 } | 46 } |
| 44 | 47 |
| 45 } // namespace | 48 } // namespace |
| 46 | 49 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 TRACE_EVENT_ASYNC_END2( | 276 TRACE_EVENT_ASYNC_END2( |
| 274 "ServiceWorker", | 277 "ServiceWorker", |
| 275 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 278 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 276 job_.get(), | 279 job_.get(), |
| 277 "Status", status, | 280 "Status", status, |
| 278 "Info", | 281 "Info", |
| 279 "ServiceWorkerVersion is not available, so falling back to network"); | 282 "ServiceWorkerVersion is not available, so falling back to network"); |
| 280 return; | 283 return; |
| 281 } | 284 } |
| 282 | 285 |
| 286 DCHECK_NE(active_version->fetch_handler_existence(), |
| 287 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
| 288 |
| 283 ServiceWorkerMetrics::CountControlledPageLoad( | 289 ServiceWorkerMetrics::CountControlledPageLoad( |
| 284 stripped_url_, active_version->has_fetch_handler(), is_main_frame_load_); | 290 stripped_url_, active_version->fetch_handler_existence() == |
| 291 ServiceWorkerVersion::FetchHandlerExistence::EXISTS, |
| 292 is_main_frame_load_); |
| 285 | 293 |
| 286 bool is_forwarded = | 294 bool is_forwarded = |
| 287 MaybeForwardToServiceWorker(job_.get(), active_version.get()); | 295 MaybeForwardToServiceWorker(job_.get(), active_version.get()); |
| 288 | 296 |
| 289 TRACE_EVENT_ASYNC_END2( | 297 TRACE_EVENT_ASYNC_END2( |
| 290 "ServiceWorker", | 298 "ServiceWorker", |
| 291 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 299 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 292 job_.get(), "Status", status, "Info", | 300 job_.get(), "Status", status, "Info", |
| 293 (is_forwarded) ? "Forwarded to the ServiceWorker" | 301 (is_forwarded) ? "Forwarded to the ServiceWorker" |
| 294 : "Skipped the ServiceWorker which has no fetch handler"); | 302 : "Skipped the ServiceWorker which has no fetch handler"); |
| 295 } | 303 } |
| 296 | 304 |
| 297 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 305 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
| 298 ServiceWorkerRegistration* registration, | 306 ServiceWorkerRegistration* registration, |
| 299 ServiceWorkerVersion* version) { | 307 ServiceWorkerVersion* version) { |
| 300 // The job may have been canceled and then destroyed before this was invoked. | 308 // The job may have been canceled and then destroyed before this was invoked. |
| 301 if (!job_) | 309 if (!job_) |
| 302 return; | 310 return; |
| 303 | 311 |
| 304 if (provider_host_) | 312 if (provider_host_) |
| 305 provider_host_->SetAllowAssociation(true); | 313 provider_host_->SetAllowAssociation(true); |
| 306 if (version != registration->active_version() || | 314 if (version != registration->active_version() || |
| 307 version->status() != ServiceWorkerVersion::ACTIVATED || | 315 version->status() != ServiceWorkerVersion::ACTIVATED || |
| 308 !provider_host_) { | 316 !provider_host_) { |
| 309 job_->FallbackToNetwork(); | 317 job_->FallbackToNetwork(); |
| 310 return; | 318 return; |
| 311 } | 319 } |
| 312 | 320 |
| 321 DCHECK_NE(version->fetch_handler_existence(), |
| 322 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
| 313 ServiceWorkerMetrics::CountControlledPageLoad( | 323 ServiceWorkerMetrics::CountControlledPageLoad( |
| 314 stripped_url_, version->has_fetch_handler(), is_main_frame_load_); | 324 stripped_url_, version->fetch_handler_existence() == |
| 325 ServiceWorkerVersion::FetchHandlerExistence::EXISTS, |
| 326 is_main_frame_load_); |
| 315 | 327 |
| 316 provider_host_->AssociateRegistration(registration, | 328 provider_host_->AssociateRegistration(registration, |
| 317 false /* notify_controllerchange */); | 329 false /* notify_controllerchange */); |
| 318 | 330 |
| 319 MaybeForwardToServiceWorker(job_.get(), version); | 331 MaybeForwardToServiceWorker(job_.get(), version); |
| 320 } | 332 } |
| 321 | 333 |
| 322 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( | 334 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( |
| 323 const scoped_refptr<ServiceWorkerRegistration>& original_registration, | 335 const scoped_refptr<ServiceWorkerRegistration>& original_registration, |
| 324 ServiceWorkerStatusCode status, | 336 ServiceWorkerStatusCode status, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 DCHECK(provider_host_); | 435 DCHECK(provider_host_); |
| 424 // Detach the controller so subresource requests also skip the worker. | 436 // Detach the controller so subresource requests also skip the worker. |
| 425 provider_host_->NotifyControllerLost(); | 437 provider_host_->NotifyControllerLost(); |
| 426 } | 438 } |
| 427 | 439 |
| 428 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 440 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
| 429 job_.reset(); | 441 job_.reset(); |
| 430 } | 442 } |
| 431 | 443 |
| 432 } // namespace content | 444 } // namespace content |
| OLD | NEW |