Chromium Code Reviews| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 245 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 246 job_.get(), | 246 job_.get(), |
| 247 "Status", status, | 247 "Status", status, |
| 248 "Info", | 248 "Info", |
| 249 "ServiceWorkerVersion is not available, so falling back to network"); | 249 "ServiceWorkerVersion is not available, so falling back to network"); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 | 252 |
| 253 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); | 253 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); |
| 254 | 254 |
| 255 job_->ForwardToServiceWorker(); | 255 if (!active_version->has_fetch_handler()) |
| 256 job_->FallbackToNetwork(); | |
| 257 else | |
| 258 job_->ForwardToServiceWorker(); | |
| 259 | |
| 256 TRACE_EVENT_ASYNC_END2( | 260 TRACE_EVENT_ASYNC_END2( |
| 257 "ServiceWorker", | 261 "ServiceWorker", |
| 258 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 262 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 259 job_.get(), | 263 job_.get(), |
| 260 "Status", status, | 264 "Status", status, |
| 261 "Info", | 265 "Info", |
| 262 "Forwarded to the ServiceWorker"); | 266 "Forwarded to the ServiceWorker"); |
| 263 } | 267 } |
| 264 | 268 |
| 265 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 269 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
| 266 ServiceWorkerRegistration* registration, | 270 ServiceWorkerRegistration* registration, |
| 267 ServiceWorkerVersion* version) { | 271 ServiceWorkerVersion* version) { |
| 268 // The job may have been canceled and then destroyed before this was invoked. | 272 // The job may have been canceled and then destroyed before this was invoked. |
| 269 if (!job_) | 273 if (!job_) |
| 270 return; | 274 return; |
| 271 | 275 |
| 272 if (provider_host_) | 276 if (provider_host_) |
| 273 provider_host_->SetAllowAssociation(true); | 277 provider_host_->SetAllowAssociation(true); |
| 274 if (version != registration->active_version() || | 278 if (version != registration->active_version() || |
| 275 version->status() != ServiceWorkerVersion::ACTIVATED || | 279 version->status() != ServiceWorkerVersion::ACTIVATED || |
| 276 !provider_host_) { | 280 !provider_host_) { |
| 277 job_->FallbackToNetwork(); | 281 job_->FallbackToNetwork(); |
| 278 return; | 282 return; |
| 279 } | 283 } |
| 280 | 284 |
| 281 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); | 285 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_); |
| 282 | 286 |
| 283 provider_host_->AssociateRegistration(registration, | 287 provider_host_->AssociateRegistration(registration, |
| 284 false /* notify_controllerchange */); | 288 false /* notify_controllerchange */); |
| 285 job_->ForwardToServiceWorker(); | 289 |
| 290 if (!version->has_fetch_handler()) | |
| 291 job_->FallbackToNetwork(); | |
| 292 else | |
| 293 job_->ForwardToServiceWorker(); | |
| 286 } | 294 } |
| 287 | 295 |
| 288 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( | 296 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( |
| 289 const scoped_refptr<ServiceWorkerRegistration>& original_registration, | 297 const scoped_refptr<ServiceWorkerRegistration>& original_registration, |
| 290 ServiceWorkerStatusCode status, | 298 ServiceWorkerStatusCode status, |
| 291 const std::string& status_message, | 299 const std::string& status_message, |
| 292 int64_t registration_id) { | 300 int64_t registration_id) { |
| 293 DCHECK(force_update_started_); | 301 DCHECK(force_update_started_); |
| 294 | 302 |
| 295 // The job may have been canceled and then destroyed before this was invoked. | 303 // The job may have been canceled and then destroyed before this was invoked. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 } | 353 } |
| 346 version->RegisterStatusChangeCallback( | 354 version->RegisterStatusChangeCallback( |
| 347 base::Bind(&self::OnUpdatedVersionStatusChanged, | 355 base::Bind(&self::OnUpdatedVersionStatusChanged, |
| 348 weak_factory_.GetWeakPtr(), registration, version)); | 356 weak_factory_.GetWeakPtr(), registration, version)); |
| 349 } | 357 } |
| 350 | 358 |
| 351 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 359 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 352 DCHECK(job_.get()); | 360 DCHECK(job_.get()); |
| 353 DCHECK(context_); | 361 DCHECK(context_); |
| 354 DCHECK(provider_host_->active_version()); | 362 DCHECK(provider_host_->active_version()); |
| 355 job_->ForwardToServiceWorker(); | 363 if (!provider_host_->active_version()->has_fetch_handler()) |
| 364 job_->FallbackToNetwork(); | |
| 365 else | |
| 366 job_->ForwardToServiceWorker(); | |
|
falken
2016/05/27 09:53:34
Can you factor out these three blocks into a helpe
shimazu
2016/05/30 05:41:59
I roughly checked the performance improvements by
| |
| 356 } | 367 } |
| 357 | 368 |
| 358 void ServiceWorkerControlleeRequestHandler::OnPrepareToRestart() { | 369 void ServiceWorkerControlleeRequestHandler::OnPrepareToRestart() { |
| 359 use_network_ = true; | 370 use_network_ = true; |
| 360 ClearJob(); | 371 ClearJob(); |
| 361 } | 372 } |
| 362 | 373 |
| 363 ServiceWorkerVersion* | 374 ServiceWorkerVersion* |
| 364 ServiceWorkerControlleeRequestHandler::GetServiceWorkerVersion( | 375 ServiceWorkerControlleeRequestHandler::GetServiceWorkerVersion( |
| 365 ServiceWorkerMetrics::URLRequestJobResult* result) { | 376 ServiceWorkerMetrics::URLRequestJobResult* result) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 389 DCHECK(provider_host_); | 400 DCHECK(provider_host_); |
| 390 // Detach the controller so subresource requests also skip the worker. | 401 // Detach the controller so subresource requests also skip the worker. |
| 391 provider_host_->NotifyControllerLost(); | 402 provider_host_->NotifyControllerLost(); |
| 392 } | 403 } |
| 393 | 404 |
| 394 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 405 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
| 395 job_.reset(); | 406 job_.reset(); |
| 396 } | 407 } |
| 397 | 408 |
| 398 } // namespace content | 409 } // namespace content |
| OLD | NEW |