| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 TRACE_EVENT_ASYNC_END2( | 260 TRACE_EVENT_ASYNC_END2( |
| 261 "ServiceWorker", | 261 "ServiceWorker", |
| 262 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 262 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 263 job_.get(), | 263 job_.get(), |
| 264 "Status", status, | 264 "Status", status, |
| 265 "Info", | 265 "Info", |
| 266 "ServiceWorkerVersion is not available, so falling back to network"); | 266 "ServiceWorkerVersion is not available, so falling back to network"); |
| 267 return; | 267 return; |
| 268 } | 268 } |
| 269 | 269 |
| 270 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); | 270 ServiceWorkerMetrics::CountControlledPageLoad( |
| 271 stripped_url_, active_version->has_fetch_handler()); |
| 271 bool is_forwarded = | 272 bool is_forwarded = |
| 272 MaybeForwardToServiceWorker(job_.get(), active_version.get()); | 273 MaybeForwardToServiceWorker(job_.get(), active_version.get()); |
| 273 | 274 |
| 274 TRACE_EVENT_ASYNC_END2( | 275 TRACE_EVENT_ASYNC_END2( |
| 275 "ServiceWorker", | 276 "ServiceWorker", |
| 276 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 277 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 277 job_.get(), "Status", status, "Info", | 278 job_.get(), "Status", status, "Info", |
| 278 (is_forwarded) ? "Forwarded to the ServiceWorker" | 279 (is_forwarded) ? "Forwarded to the ServiceWorker" |
| 279 : "Skipped the ServiceWorker which has no fetch handler"); | 280 : "Skipped the ServiceWorker which has no fetch handler"); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 283 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
| 283 ServiceWorkerRegistration* registration, | 284 ServiceWorkerRegistration* registration, |
| 284 ServiceWorkerVersion* version) { | 285 ServiceWorkerVersion* version) { |
| 285 // The job may have been canceled and then destroyed before this was invoked. | 286 // The job may have been canceled and then destroyed before this was invoked. |
| 286 if (!job_) | 287 if (!job_) |
| 287 return; | 288 return; |
| 288 | 289 |
| 289 if (provider_host_) | 290 if (provider_host_) |
| 290 provider_host_->SetAllowAssociation(true); | 291 provider_host_->SetAllowAssociation(true); |
| 291 if (version != registration->active_version() || | 292 if (version != registration->active_version() || |
| 292 version->status() != ServiceWorkerVersion::ACTIVATED || | 293 version->status() != ServiceWorkerVersion::ACTIVATED || |
| 293 !provider_host_) { | 294 !provider_host_) { |
| 294 job_->FallbackToNetwork(); | 295 job_->FallbackToNetwork(); |
| 295 return; | 296 return; |
| 296 } | 297 } |
| 297 | 298 |
| 298 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); | 299 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_, |
| 300 version->has_fetch_handler()); |
| 299 | 301 |
| 300 provider_host_->AssociateRegistration(registration, | 302 provider_host_->AssociateRegistration(registration, |
| 301 false /* notify_controllerchange */); | 303 false /* notify_controllerchange */); |
| 302 | 304 |
| 303 MaybeForwardToServiceWorker(job_.get(), version); | 305 MaybeForwardToServiceWorker(job_.get(), version); |
| 304 } | 306 } |
| 305 | 307 |
| 306 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( | 308 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( |
| 307 const scoped_refptr<ServiceWorkerRegistration>& original_registration, | 309 const scoped_refptr<ServiceWorkerRegistration>& original_registration, |
| 308 ServiceWorkerStatusCode status, | 310 ServiceWorkerStatusCode status, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 DCHECK(provider_host_); | 409 DCHECK(provider_host_); |
| 408 // Detach the controller so subresource requests also skip the worker. | 410 // Detach the controller so subresource requests also skip the worker. |
| 409 provider_host_->NotifyControllerLost(); | 411 provider_host_->NotifyControllerLost(); |
| 410 } | 412 } |
| 411 | 413 |
| 412 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 414 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
| 413 job_.reset(); | 415 job_.reset(); |
| 414 } | 416 } |
| 415 | 417 |
| 416 } // namespace content | 418 } // namespace content |
| OLD | NEW |