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 "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_provider_host.h" | 8 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 9 #include "content/browser/service_worker/service_worker_registration.h" | 9 #include "content/browser/service_worker/service_worker_registration.h" |
| 10 #include "content/browser/service_worker/service_worker_url_request_job.h" | 10 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 11 #include "content/browser/service_worker/service_worker_utils.h" | 11 #include "content/browser/service_worker/service_worker_utils.h" |
| 12 #include "content/common/service_worker/service_worker_types.h" | 12 #include "content/common/service_worker/service_worker_types.h" |
| 13 #include "net/base/net_util.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) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 45 // We've come here by restart, we already have original request and it | 46 // We've come here by restart, we already have original request and it |
| 46 // tells we should fallback to network. (Case B-c) | 47 // tells we should fallback to network. (Case B-c) |
| 47 if (job_.get() && job_->ShouldFallbackToNetwork()) { | 48 if (job_.get() && job_->ShouldFallbackToNetwork()) { |
| 48 job_ = NULL; | 49 job_ = NULL; |
| 49 return NULL; | 50 return NULL; |
| 50 } | 51 } |
| 51 | 52 |
| 52 // It's for original request (A) or redirect case (B-a or B-b). | 53 // It's for original request (A) or redirect case (B-a or B-b). |
| 53 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); | 54 DCHECK(!job_.get() || job_->ShouldForwardToServiceWorker()); |
| 54 | 55 |
| 56 // Strip away reference fragments. | |
| 57 const GURL& stripped_url(net::SimplifyUrlForRequest(request->url())); | |
|
michaeln
2014/05/30 23:38:47
const GURL&, doesn't look right here
i'd put this
nhiroki
2014/06/02 06:26:08
Ah, it's a slip of the finger. Good catch!
| |
| 58 | |
| 55 job_ = new ServiceWorkerURLRequestJob(request, network_delegate, | 59 job_ = new ServiceWorkerURLRequestJob(request, network_delegate, |
| 56 provider_host_); | 60 provider_host_); |
| 57 if (ServiceWorkerUtils::IsMainResourceType(resource_type_)) | 61 if (ServiceWorkerUtils::IsMainResourceType(resource_type_)) |
| 58 PrepareForMainResource(request->url()); | 62 PrepareForMainResource(stripped_url); |
| 59 else | 63 else |
| 60 PrepareForSubResource(); | 64 PrepareForSubResource(); |
| 61 | 65 |
| 62 if (job_->ShouldFallbackToNetwork()) { | 66 if (job_->ShouldFallbackToNetwork()) { |
| 63 // If we know we can fallback to network at this point (in case | 67 // If we know we can fallback to network at this point (in case |
| 64 // the storage lookup returned immediately), just return NULL here to | 68 // the storage lookup returned immediately), just return NULL here to |
| 65 // fallback to network. | 69 // fallback to network. |
| 66 job_ = NULL; | 70 job_ = NULL; |
| 67 return NULL; | 71 return NULL; |
| 68 } | 72 } |
| 69 | 73 |
| 70 return job_.get(); | 74 return job_.get(); |
| 71 } | 75 } |
| 72 | 76 |
| 73 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 77 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
| 74 const GURL& url) { | 78 const GURL& url) { |
| 75 DCHECK(job_.get()); | 79 DCHECK(job_.get()); |
| 76 DCHECK(context_); | 80 DCHECK(context_); |
| 77 // The corresponding provider_host may already have associate version in | 81 // The corresponding provider_host may already have associate version in |
| 78 // redirect case, unassociate it now. | 82 // redirect case, unassociate it now. |
| 79 provider_host_->SetActiveVersion(NULL); | 83 provider_host_->SetActiveVersion(NULL); |
| 80 provider_host_->SetPendingVersion(NULL); | 84 provider_host_->SetPendingVersion(NULL); |
| 81 provider_host_->set_document_url(url); | 85 provider_host_->set_document_url(url); |
| 82 context_->storage()->FindRegistrationForDocument( | 86 context_->storage()->FindRegistrationForDocument( |
|
michaeln
2014/05/30 23:38:47
maybe add some DCHECKs to set_document_url(url) an
nhiroki
2014/06/02 06:26:08
Added.
| |
| 83 url, | 87 url, |
| 84 base::Bind(&self::DidLookupRegistrationForMainResource, | 88 base::Bind(&self::DidLookupRegistrationForMainResource, |
| 85 weak_factory_.GetWeakPtr())); | 89 weak_factory_.GetWeakPtr())); |
| 86 } | 90 } |
| 87 | 91 |
| 88 void | 92 void |
| 89 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( | 93 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( |
| 90 ServiceWorkerStatusCode status, | 94 ServiceWorkerStatusCode status, |
| 91 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 95 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 92 DCHECK(job_.get()); | 96 DCHECK(job_.get()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 105 } | 109 } |
| 106 | 110 |
| 107 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 111 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 108 DCHECK(job_.get()); | 112 DCHECK(job_.get()); |
| 109 DCHECK(context_); | 113 DCHECK(context_); |
| 110 DCHECK(provider_host_->active_version()); | 114 DCHECK(provider_host_->active_version()); |
| 111 job_->ForwardToServiceWorker(); | 115 job_->ForwardToServiceWorker(); |
| 112 } | 116 } |
| 113 | 117 |
| 114 } // namespace content | 118 } // namespace content |
| OLD | NEW |