| 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 "content/browser/fileapi/chrome_blob_storage_context.h" |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 9 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| 10 #include "content/browser/service_worker/service_worker_url_request_job.h" | 11 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 11 #include "content/browser/service_worker/service_worker_utils.h" | 12 #include "content/browser/service_worker/service_worker_utils.h" |
| 12 #include "content/common/service_worker/service_worker_types.h" | 13 #include "content/common/service_worker/service_worker_types.h" |
| 13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( | 18 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( |
| 18 base::WeakPtr<ServiceWorkerContextCore> context, | 19 base::WeakPtr<ServiceWorkerContextCore> context, |
| 19 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 20 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 20 ResourceType::Type resource_type) | 21 ResourceType::Type resource_type) |
| 21 : ServiceWorkerRequestHandler(context, provider_host, resource_type), | 22 : ServiceWorkerRequestHandler(context, provider_host, resource_type), |
| 22 weak_factory_(this) { | 23 weak_factory_(this) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 ServiceWorkerControlleeRequestHandler:: | 26 ServiceWorkerControlleeRequestHandler:: |
| 26 ~ServiceWorkerControlleeRequestHandler() { | 27 ~ServiceWorkerControlleeRequestHandler() { |
| 27 } | 28 } |
| 28 | 29 |
| 29 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( | 30 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( |
| 30 net::URLRequest* request, | 31 net::URLRequest* request, |
| 31 net::NetworkDelegate* network_delegate) { | 32 net::NetworkDelegate* network_delegate, |
| 33 const scoped_refptr<ChromeBlobStorageContext>& blob_storage_context) { |
| 32 if (!context_ || !provider_host_) { | 34 if (!context_ || !provider_host_) { |
| 33 // We can't do anything other than to fall back to network. | 35 // We can't do anything other than to fall back to network. |
| 34 job_ = NULL; | 36 job_ = NULL; |
| 35 return NULL; | 37 return NULL; |
| 36 } | 38 } |
| 37 | 39 |
| 38 // This may get called multiple times for original and redirect requests: | 40 // This may get called multiple times for original and redirect requests: |
| 39 // A. original request case: job_ is null, no previous location info. | 41 // A. original request case: job_ is null, no previous location info. |
| 40 // B. redirect or restarted request case: | 42 // B. redirect or restarted request case: |
| 41 // a) job_ is non-null if the previous location was forwarded to SW. | 43 // a) job_ is non-null if the previous location was forwarded to SW. |
| 42 // b) job_ is null if the previous location was fallback. | 44 // b) job_ is null if the previous location was fallback. |
| 43 // c) job_ is non-null if additional restart was required to fall back. | 45 // c) job_ is non-null if additional restart was required to fall back. |
| 44 | 46 |
| 45 // We've come here by restart, we already have original request and it | 47 // We've come here by restart, we already have original request and it |
| 46 // tells we should fallback to network. (Case B-c) | 48 // tells we should fallback to network. (Case B-c) |
| 47 if (job_.get() && job_->ShouldFallbackToNetwork()) { | 49 if (job_.get() && job_->ShouldFallbackToNetwork()) { |
| 48 job_ = NULL; | 50 job_ = NULL; |
| 49 return NULL; | 51 return NULL; |
| 50 } | 52 } |
| 51 | 53 |
| 52 // It's for original request (A) or redirect case (B-a or B-b). | 54 // It's for original request (A) or redirect case (B-a or B-b). |
| 53 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); | 55 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); |
| 54 | 56 |
| 55 job_ = new ServiceWorkerURLRequestJob(request, network_delegate, | 57 job_ = new ServiceWorkerURLRequestJob( |
| 56 provider_host_); | 58 request, network_delegate, provider_host_, blob_storage_context); |
| 57 if (ServiceWorkerUtils::IsMainResourceType(resource_type_)) | 59 if (ServiceWorkerUtils::IsMainResourceType(resource_type_)) |
| 58 PrepareForMainResource(request->url()); | 60 PrepareForMainResource(request->url()); |
| 59 else | 61 else |
| 60 PrepareForSubResource(); | 62 PrepareForSubResource(); |
| 61 | 63 |
| 62 if (job_->ShouldFallbackToNetwork()) { | 64 if (job_->ShouldFallbackToNetwork()) { |
| 63 // If we know we can fallback to network at this point (in case | 65 // If we know we can fallback to network at this point (in case |
| 64 // the storage lookup returned immediately), just return NULL here to | 66 // the storage lookup returned immediately), just return NULL here to |
| 65 // fallback to network. | 67 // fallback to network. |
| 66 job_ = NULL; | 68 job_ = NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 107 } |
| 106 | 108 |
| 107 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 109 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 108 DCHECK(job_.get()); | 110 DCHECK(job_.get()); |
| 109 DCHECK(context_); | 111 DCHECK(context_); |
| 110 DCHECK(provider_host_->active_version()); | 112 DCHECK(provider_host_->active_version()); |
| 111 job_->ForwardToServiceWorker(); | 113 job_->ForwardToServiceWorker(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace content | 116 } // namespace content |
| OLD | NEW |