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/debug/trace_event.h" | 7 #include "base/debug/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 15 matching lines...) Expand all Loading... | |
| 26 ResourceType resource_type, | 26 ResourceType resource_type, |
| 27 scoped_refptr<ResourceRequestBody> body) | 27 scoped_refptr<ResourceRequestBody> body) |
| 28 : ServiceWorkerRequestHandler(context, | 28 : ServiceWorkerRequestHandler(context, |
| 29 provider_host, | 29 provider_host, |
| 30 blob_storage_context, | 30 blob_storage_context, |
| 31 resource_type), | 31 resource_type), |
| 32 is_main_resource_load_( | 32 is_main_resource_load_( |
| 33 ServiceWorkerUtils::IsMainResourceType(resource_type)), | 33 ServiceWorkerUtils::IsMainResourceType(resource_type)), |
| 34 body_(body), | 34 body_(body), |
| 35 weak_factory_(this) { | 35 weak_factory_(this) { |
| 36 if (is_main_resource_load_ && provider_host_) | |
| 37 provider_host_->SetAllowAssociation(false); | |
| 36 } | 38 } |
| 37 | 39 |
| 38 ServiceWorkerControlleeRequestHandler:: | 40 ServiceWorkerControlleeRequestHandler:: |
| 39 ~ServiceWorkerControlleeRequestHandler() { | 41 ~ServiceWorkerControlleeRequestHandler() { |
| 40 // Navigation triggers an update to occur shortly after the page and | 42 // Navigation triggers an update to occur shortly after the page and |
| 41 // its initial subresources load. | 43 // its initial subresources load. |
| 42 if (provider_host_ && provider_host_->active_version()) { | 44 if (provider_host_ && provider_host_->active_version()) { |
| 43 if (is_main_resource_load_) | 45 if (is_main_resource_load_) |
| 44 provider_host_->active_version()->ScheduleUpdate(); | 46 provider_host_->active_version()->ScheduleUpdate(); |
| 45 else | 47 else |
| 46 provider_host_->active_version()->DeferScheduledUpdate(); | 48 provider_host_->active_version()->DeferScheduledUpdate(); |
| 47 } | 49 } |
| 50 | |
| 51 if (is_main_resource_load_ && provider_host_) | |
| 52 provider_host_->SetAllowAssociation(true); | |
| 48 } | 53 } |
| 49 | 54 |
| 50 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( | 55 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( |
| 51 net::URLRequest* request, | 56 net::URLRequest* request, |
| 52 net::NetworkDelegate* network_delegate) { | 57 net::NetworkDelegate* network_delegate) { |
| 53 if (!context_ || !provider_host_) { | 58 if (!context_ || !provider_host_) { |
| 54 // We can't do anything other than to fall back to network. | 59 // We can't do anything other than to fall back to network. |
| 55 job_ = NULL; | 60 job_ = NULL; |
| 56 return NULL; | 61 return NULL; |
| 57 } | 62 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 TRACE_EVENT_ASYNC_END2( | 180 TRACE_EVENT_ASYNC_END2( |
| 176 "ServiceWorker", | 181 "ServiceWorker", |
| 177 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 182 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 178 job_.get(), | 183 job_.get(), |
| 179 "Status", status, | 184 "Status", status, |
| 180 "Info", | 185 "Info", |
| 181 "ServiceWorkerVersion is not available, so falling back to network"); | 186 "ServiceWorkerVersion is not available, so falling back to network"); |
| 182 return; | 187 return; |
| 183 } | 188 } |
| 184 | 189 |
| 190 | |
|
nhiroki
2014/09/10 02:04:11
nit: there is an extra empty line
michaeln
2014/09/10 22:40:40
Done.
| |
| 191 provider_host_->SetAllowAssociation(true); | |
| 185 provider_host_->AssociateRegistration(registration.get()); | 192 provider_host_->AssociateRegistration(registration.get()); |
| 193 provider_host_->SetAllowAssociation(false); | |
| 194 | |
| 186 job_->ForwardToServiceWorker(); | 195 job_->ForwardToServiceWorker(); |
| 187 TRACE_EVENT_ASYNC_END2( | 196 TRACE_EVENT_ASYNC_END2( |
| 188 "ServiceWorker", | 197 "ServiceWorker", |
| 189 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 198 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 190 job_.get(), | 199 job_.get(), |
| 191 "Status", status, | 200 "Status", status, |
| 192 "Info", | 201 "Info", |
| 193 "Forwarded to the ServiceWorker"); | 202 "Forwarded to the ServiceWorker"); |
| 194 } | 203 } |
| 195 | 204 |
| 196 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 205 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
| 197 ServiceWorkerRegistration* registration, | 206 ServiceWorkerRegistration* registration, |
| 198 ServiceWorkerVersion* version) { | 207 ServiceWorkerVersion* version) { |
| 199 if (version != registration->active_version() || | 208 if (version != registration->active_version() || |
| 200 version->status() != ServiceWorkerVersion::ACTIVATED) { | 209 version->status() != ServiceWorkerVersion::ACTIVATED) { |
| 201 job_->FallbackToNetwork(); | 210 job_->FallbackToNetwork(); |
| 202 return; | 211 return; |
| 203 } | 212 } |
| 204 | 213 |
| 214 provider_host_->SetAllowAssociation(true); | |
| 205 provider_host_->AssociateRegistration(registration); | 215 provider_host_->AssociateRegistration(registration); |
| 216 provider_host_->SetAllowAssociation(false); | |
| 217 | |
| 206 job_->ForwardToServiceWorker(); | 218 job_->ForwardToServiceWorker(); |
| 207 } | 219 } |
| 208 | 220 |
| 209 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 221 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 210 DCHECK(job_.get()); | 222 DCHECK(job_.get()); |
| 211 DCHECK(context_); | 223 DCHECK(context_); |
| 212 DCHECK(provider_host_->active_version()); | 224 DCHECK(provider_host_->active_version()); |
| 213 job_->ForwardToServiceWorker(); | 225 job_->ForwardToServiceWorker(); |
| 214 } | 226 } |
| 215 | 227 |
| 216 } // namespace content | 228 } // namespace content |
| OLD | NEW |