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 "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_metrics.h" | 9 #include "content/browser/service_worker/service_worker_metrics.h" |
| 10 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 |
| 80 // This may get called multiple times for original and redirect requests: | 80 // This may get called multiple times for original and redirect requests: |
| 81 // A. original request case: job_ is null, no previous location info. | 81 // A. original request case: job_ is null, no previous location info. |
| 82 // B. redirect or restarted request case: | 82 // B. redirect or restarted request case: |
| 83 // a) job_ is non-null if the previous location was forwarded to SW. | 83 // a) job_ is non-null if the previous location was forwarded to SW. |
| 84 // b) job_ is null if the previous location was fallback. | 84 // b) job_ is null if the previous location was fallback. |
| 85 // c) job_ is non-null if additional restart was required to fall back. | 85 // c) job_ is non-null if additional restart was required to fall back. |
| 86 | 86 |
| 87 // We've come here by restart, we already have original request and it | 87 // We've come here by restart, we already have original request and it |
| 88 // tells we should fallback to network. (Case B-c) | 88 // tells we should fallback to network. (Case B-c) |
| 89 // Once the request was fallbacked to the network, skip-service-worker flag | |
| 90 // must be set and the request shoud not go to the service worker. | |
| 91 if ((job_.get() && job_->ShouldFallbackToNetwork()) || skip_service_worker_) { | 89 if ((job_.get() && job_->ShouldFallbackToNetwork()) || skip_service_worker_) { |
| 92 skip_service_worker_ = true; | 90 // Once a subresource request was fallbacked to the network, we set |
| 91 // |skip_service_worker_| and the request shoud not go to the service | |
| 92 // worker. | |
| 93 if (!is_main_resource_load_) | |
| 94 skip_service_worker_ = true; | |
| 93 job_ = NULL; | 95 job_ = NULL; |
| 94 return NULL; | 96 return NULL; |
| 95 } | 97 } |
| 96 | 98 |
| 97 // It's for original request (A) or redirect case (B-a or B-b). | 99 // It's for original request (A) or redirect case (B-a or B-b). |
| 98 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); | 100 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); |
| 99 | 101 |
| 100 job_ = new ServiceWorkerURLRequestJob( | 102 job_ = new ServiceWorkerURLRequestJob( |
| 101 request, network_delegate, provider_host_, blob_storage_context_, | 103 request, network_delegate, provider_host_, blob_storage_context_, |
| 102 resource_context, request_mode_, credentials_mode_, | 104 resource_context, request_mode_, credentials_mode_, |
| 103 is_main_resource_load_, request_context_type_, frame_type_, body_); | 105 is_main_resource_load_, request_context_type_, frame_type_, body_); |
| 104 resource_context_ = resource_context; | 106 resource_context_ = resource_context; |
| 105 | 107 |
| 106 if (is_main_resource_load_) | 108 if (is_main_resource_load_) |
| 107 PrepareForMainResource(request); | 109 PrepareForMainResource(request); |
| 108 else | 110 else |
| 109 PrepareForSubResource(); | 111 PrepareForSubResource(); |
| 110 | 112 |
| 111 if (job_->ShouldFallbackToNetwork()) { | 113 if (job_->ShouldFallbackToNetwork()) { |
| 112 // If we know we can fallback to network at this point (in case | 114 // If we know we can fallback to network at this point (in case |
| 113 // the storage lookup returned immediately), just return NULL here to | 115 // the storage lookup returned immediately), just return NULL here to |
| 114 // fallback to network. | 116 // fallback to network. |
| 115 job_ = NULL; | 117 job_ = NULL; |
| 118 // Once a subresource request was fallbacked to the network, we set | |
| 119 // |skip_service_worker_| and the request shoud not go to the service | |
| 120 // worker. | |
| 121 if (!is_main_resource_load_) | |
| 122 skip_service_worker_ = true; | |
|
falken
2015/08/10 04:56:15
Can you factor these out to a helper function so w
horo
2015/08/10 05:43:41
Done.
| |
| 116 return NULL; | 123 return NULL; |
| 117 } | 124 } |
| 118 | 125 |
| 119 return job_.get(); | 126 return job_.get(); |
| 120 } | 127 } |
| 121 | 128 |
| 122 void ServiceWorkerControlleeRequestHandler::GetExtraResponseInfo( | 129 void ServiceWorkerControlleeRequestHandler::GetExtraResponseInfo( |
| 123 ResourceResponseInfo* response_info) const { | 130 ResourceResponseInfo* response_info) const { |
| 124 if (!job_.get()) { | 131 if (!job_.get()) { |
| 125 response_info->was_fetched_via_service_worker = false; | 132 response_info->was_fetched_via_service_worker = false; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 } | 277 } |
| 271 | 278 |
| 272 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 279 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 273 DCHECK(job_.get()); | 280 DCHECK(job_.get()); |
| 274 DCHECK(context_); | 281 DCHECK(context_); |
| 275 DCHECK(provider_host_->active_version()); | 282 DCHECK(provider_host_->active_version()); |
| 276 job_->ForwardToServiceWorker(); | 283 job_->ForwardToServiceWorker(); |
| 277 } | 284 } |
| 278 | 285 |
| 279 } // namespace content | 286 } // namespace content |
| OLD | NEW |