| 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_metrics.h" | 8 #include "content/browser/service_worker/service_worker_metrics.h" |
| 9 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 job_->GetExtraResponseInfo(was_fetched_via_service_worker, | 107 job_->GetExtraResponseInfo(was_fetched_via_service_worker, |
| 108 original_url_via_service_worker); | 108 original_url_via_service_worker); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 111 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
| 112 const GURL& url) { | 112 const GURL& url) { |
| 113 DCHECK(job_.get()); | 113 DCHECK(job_.get()); |
| 114 DCHECK(context_); | 114 DCHECK(context_); |
| 115 // The corresponding provider_host may already have associated a registration | 115 // The corresponding provider_host may already have associated a registration |
| 116 // in redirect case, unassociate it now. | 116 // in redirect case, unassociate it now. |
| 117 provider_host_->UnassociateRegistration(); |
| 117 provider_host_->SetControllerVersion(NULL); | 118 provider_host_->SetControllerVersion(NULL); |
| 118 provider_host_->SetActiveVersion(NULL); | |
| 119 provider_host_->SetWaitingVersion(NULL); | |
| 120 provider_host_->SetInstallingVersion(NULL); | |
| 121 | 119 |
| 122 GURL stripped_url = net::SimplifyUrlForRequest(url); | 120 GURL stripped_url = net::SimplifyUrlForRequest(url); |
| 123 provider_host_->SetDocumentUrl(stripped_url); | 121 provider_host_->SetDocumentUrl(stripped_url); |
| 124 context_->storage()->FindRegistrationForDocument( | 122 context_->storage()->FindRegistrationForDocument( |
| 125 stripped_url, | 123 stripped_url, |
| 126 base::Bind(&self::DidLookupRegistrationForMainResource, | 124 base::Bind(&self::DidLookupRegistrationForMainResource, |
| 127 weak_factory_.GetWeakPtr())); | 125 weak_factory_.GetWeakPtr())); |
| 128 } | 126 } |
| 129 | 127 |
| 130 void | 128 void |
| (...skipping 14 matching lines...) Expand all Loading... |
| 145 // doesn't happen if the browser exits prior to activation | 143 // doesn't happen if the browser exits prior to activation |
| 146 // having occurred. This check handles that case. | 144 // having occurred. This check handles that case. |
| 147 if (registration->waiting_version()) | 145 if (registration->waiting_version()) |
| 148 registration->ActivateWaitingVersionWhenReady(); | 146 registration->ActivateWaitingVersionWhenReady(); |
| 149 | 147 |
| 150 scoped_refptr<ServiceWorkerVersion> active_version = | 148 scoped_refptr<ServiceWorkerVersion> active_version = |
| 151 registration->active_version(); | 149 registration->active_version(); |
| 152 | 150 |
| 153 // Wait until it's activated before firing fetch events. | 151 // Wait until it's activated before firing fetch events. |
| 154 if (active_version && | 152 if (active_version && |
| 155 active_version->status() == ServiceWorkerVersion::ACTIVATING) { | 153 active_version->status() == ServiceWorkerVersion::ACTIVATING) { |
| 156 registration->active_version()->RegisterStatusChangeCallback( | 154 registration->active_version()->RegisterStatusChangeCallback( |
| 157 base::Bind(&self::OnVersionStatusChanged, | 155 base::Bind(&self::OnVersionStatusChanged, |
| 158 weak_factory_.GetWeakPtr(), | 156 weak_factory_.GetWeakPtr(), |
| 159 registration, | 157 registration, |
| 160 active_version)); | 158 active_version)); |
| 161 return; | 159 return; |
| 162 } | 160 } |
| 163 | 161 |
| 164 if (!active_version || | 162 if (!active_version || |
| 165 active_version->status() != ServiceWorkerVersion::ACTIVATED) { | 163 active_version->status() != ServiceWorkerVersion::ACTIVATED) { |
| 166 job_->FallbackToNetwork(); | 164 job_->FallbackToNetwork(); |
| 167 return; | 165 return; |
| 168 } | 166 } |
| 169 | 167 |
| 168 provider_host_->AssociateRegistration(registration); |
| 170 provider_host_->SetControllerVersion(registration->active_version()); | 169 provider_host_->SetControllerVersion(registration->active_version()); |
| 171 provider_host_->SetActiveVersion(registration->active_version()); | |
| 172 provider_host_->SetWaitingVersion(registration->waiting_version()); | |
| 173 provider_host_->SetInstallingVersion(registration->installing_version()); | |
| 174 | 170 |
| 175 job_->ForwardToServiceWorker(); | 171 job_->ForwardToServiceWorker(); |
| 176 } | 172 } |
| 177 | 173 |
| 178 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 174 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
| 179 ServiceWorkerRegistration* registration, | 175 ServiceWorkerRegistration* registration, |
| 180 ServiceWorkerVersion* version) { | 176 ServiceWorkerVersion* version) { |
| 181 if (version != registration->active_version() || | 177 if (version != registration->active_version() || |
| 182 version->status() != ServiceWorkerVersion::ACTIVATED) { | 178 version->status() != ServiceWorkerVersion::ACTIVATED) { |
| 183 job_->FallbackToNetwork(); | 179 job_->FallbackToNetwork(); |
| 184 return; | 180 return; |
| 185 } | 181 } |
| 182 |
| 183 provider_host_->AssociateRegistration(registration); |
| 186 provider_host_->SetControllerVersion(registration->active_version()); | 184 provider_host_->SetControllerVersion(registration->active_version()); |
| 187 provider_host_->SetActiveVersion(registration->active_version()); | |
| 188 provider_host_->SetWaitingVersion(registration->waiting_version()); | |
| 189 provider_host_->SetInstallingVersion(registration->installing_version()); | |
| 190 | 185 |
| 191 job_->ForwardToServiceWorker(); | 186 job_->ForwardToServiceWorker(); |
| 192 } | 187 } |
| 193 | 188 |
| 194 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 189 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 195 DCHECK(job_.get()); | 190 DCHECK(job_.get()); |
| 196 DCHECK(context_); | 191 DCHECK(context_); |
| 197 DCHECK(provider_host_->active_version()); | 192 DCHECK(provider_host_->active_version()); |
| 198 job_->ForwardToServiceWorker(); | 193 job_->ForwardToServiceWorker(); |
| 199 } | 194 } |
| 200 | 195 |
| 201 } // namespace content | 196 } // namespace content |
| OLD | NEW |