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 25 matching lines...) Expand all Loading... | |
| 36 provider_host, | 36 provider_host, |
| 37 blob_storage_context, | 37 blob_storage_context, |
| 38 resource_type), | 38 resource_type), |
| 39 is_main_resource_load_( | 39 is_main_resource_load_( |
| 40 ServiceWorkerUtils::IsMainResourceType(resource_type)), | 40 ServiceWorkerUtils::IsMainResourceType(resource_type)), |
| 41 request_mode_(request_mode), | 41 request_mode_(request_mode), |
| 42 credentials_mode_(credentials_mode), | 42 credentials_mode_(credentials_mode), |
| 43 request_context_type_(request_context_type), | 43 request_context_type_(request_context_type), |
| 44 frame_type_(frame_type), | 44 frame_type_(frame_type), |
| 45 body_(body), | 45 body_(body), |
| 46 weak_factory_(this) { | 46 skip_service_worker_(false), |
| 47 } | 47 weak_factory_(this) {} |
| 48 | 48 |
| 49 ServiceWorkerControlleeRequestHandler:: | 49 ServiceWorkerControlleeRequestHandler:: |
| 50 ~ServiceWorkerControlleeRequestHandler() { | 50 ~ServiceWorkerControlleeRequestHandler() { |
| 51 // Navigation triggers an update to occur shortly after the page and | 51 // Navigation triggers an update to occur shortly after the page and |
| 52 // its initial subresources load. | 52 // its initial subresources load. |
| 53 if (provider_host_ && provider_host_->active_version()) { | 53 if (provider_host_ && provider_host_->active_version()) { |
| 54 if (is_main_resource_load_) | 54 if (is_main_resource_load_) |
| 55 provider_host_->active_version()->ScheduleUpdate(); | 55 provider_host_->active_version()->ScheduleUpdate(); |
| 56 else | 56 else |
| 57 provider_host_->active_version()->DeferScheduledUpdate(); | 57 provider_host_->active_version()->DeferScheduledUpdate(); |
| (...skipping 21 matching lines...) Expand all 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 if (job_.get() && job_->ShouldFallbackToNetwork()) { | 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. | |
|
michaeln
2015/08/07 19:40:23
Whoa, this can't be right?
User clicks link to bi
horo
2015/08/08 09:00:44
Yes you are right!
Navigation request's redirect
| |
| 91 if ((job_.get() && job_->ShouldFallbackToNetwork()) || skip_service_worker_) { | |
| 92 skip_service_worker_ = true; | |
| 90 job_ = NULL; | 93 job_ = NULL; |
| 91 return NULL; | 94 return NULL; |
| 92 } | 95 } |
| 93 | 96 |
| 94 // It's for original request (A) or redirect case (B-a or B-b). | 97 // It's for original request (A) or redirect case (B-a or B-b). |
| 95 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); | 98 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); |
| 96 | 99 |
| 97 job_ = new ServiceWorkerURLRequestJob( | 100 job_ = new ServiceWorkerURLRequestJob( |
| 98 request, network_delegate, provider_host_, blob_storage_context_, | 101 request, network_delegate, provider_host_, blob_storage_context_, |
| 99 resource_context, request_mode_, credentials_mode_, | 102 resource_context, request_mode_, credentials_mode_, |
| 100 is_main_resource_load_, request_context_type_, frame_type_, body_); | 103 is_main_resource_load_, request_context_type_, frame_type_, body_); |
| 101 resource_context_ = resource_context; | 104 resource_context_ = resource_context; |
| 102 | 105 |
| 103 if (is_main_resource_load_) | 106 if (is_main_resource_load_) |
| 104 PrepareForMainResource(request); | 107 PrepareForMainResource(request); |
| 105 else | 108 else |
| 106 PrepareForSubResource(); | 109 PrepareForSubResource(); |
| 107 | 110 |
| 108 if (job_->ShouldFallbackToNetwork()) { | 111 if (job_->ShouldFallbackToNetwork()) { |
|
michaeln
2015/08/07 19:40:23
Also, is the difference in behavior for this fallb
horo
2015/08/08 09:00:44
No. We should also set here.
If the original requ
| |
| 109 // If we know we can fallback to network at this point (in case | 112 // If we know we can fallback to network at this point (in case |
| 110 // the storage lookup returned immediately), just return NULL here to | 113 // the storage lookup returned immediately), just return NULL here to |
| 111 // fallback to network. | 114 // fallback to network. |
| 112 job_ = NULL; | 115 job_ = NULL; |
| 113 return NULL; | 116 return NULL; |
| 114 } | 117 } |
| 115 | 118 |
| 116 return job_.get(); | 119 return job_.get(); |
| 117 } | 120 } |
| 118 | 121 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 270 } |
| 268 | 271 |
| 269 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 272 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 270 DCHECK(job_.get()); | 273 DCHECK(job_.get()); |
| 271 DCHECK(context_); | 274 DCHECK(context_); |
| 272 DCHECK(provider_host_->active_version()); | 275 DCHECK(provider_host_->active_version()); |
| 273 job_->ForwardToServiceWorker(); | 276 job_->ForwardToServiceWorker(); |
| 274 } | 277 } |
| 275 | 278 |
| 276 } // namespace content | 279 } // namespace content |
| OLD | NEW |