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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 job_ = NULL; | 95 job_ = NULL; |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 return job_.get(); | 99 return job_.get(); |
100 } | 100 } |
101 | 101 |
102 void ServiceWorkerControlleeRequestHandler::GetExtraResponseInfo( | 102 void ServiceWorkerControlleeRequestHandler::GetExtraResponseInfo( |
103 bool* was_fetched_via_service_worker, | 103 bool* was_fetched_via_service_worker, |
104 GURL* original_url_via_service_worker) const { | 104 GURL* original_url_via_service_worker) const { |
105 if (!job_) { | 105 if (!job_.get()) { |
106 *was_fetched_via_service_worker = false; | 106 *was_fetched_via_service_worker = false; |
107 *original_url_via_service_worker = GURL(); | 107 *original_url_via_service_worker = GURL(); |
108 return; | 108 return; |
109 } | 109 } |
110 job_->GetExtraResponseInfo(was_fetched_via_service_worker, | 110 job_->GetExtraResponseInfo(was_fetched_via_service_worker, |
111 original_url_via_service_worker); | 111 original_url_via_service_worker); |
112 } | 112 } |
113 | 113 |
114 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 114 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
115 const GURL& url) { | 115 const GURL& url) { |
(...skipping 13 matching lines...) Expand all Loading... |
129 | 129 |
130 void | 130 void |
131 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( | 131 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( |
132 ServiceWorkerStatusCode status, | 132 ServiceWorkerStatusCode status, |
133 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 133 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
134 DCHECK(job_.get()); | 134 DCHECK(job_.get()); |
135 if (status != SERVICE_WORKER_OK) { | 135 if (status != SERVICE_WORKER_OK) { |
136 job_->FallbackToNetwork(); | 136 job_->FallbackToNetwork(); |
137 return; | 137 return; |
138 } | 138 } |
139 DCHECK(registration); | 139 DCHECK(registration.get()); |
140 | 140 |
141 ServiceWorkerMetrics::CountControlledPageLoad(); | 141 ServiceWorkerMetrics::CountControlledPageLoad(); |
142 | 142 |
143 // Initiate activation of a waiting version. | 143 // Initiate activation of a waiting version. |
144 // Usually a register job initiates activation but that | 144 // Usually a register job initiates activation but that |
145 // doesn't happen if the browser exits prior to activation | 145 // doesn't happen if the browser exits prior to activation |
146 // having occurred. This check handles that case. | 146 // having occurred. This check handles that case. |
147 if (registration->waiting_version()) | 147 if (registration->waiting_version()) |
148 registration->ActivateWaitingVersionWhenReady(); | 148 registration->ActivateWaitingVersionWhenReady(); |
149 | 149 |
150 scoped_refptr<ServiceWorkerVersion> active_version = | 150 scoped_refptr<ServiceWorkerVersion> active_version = |
151 registration->active_version(); | 151 registration->active_version(); |
152 | 152 |
153 // Wait until it's activated before firing fetch events. | 153 // Wait until it's activated before firing fetch events. |
154 if (active_version && | 154 if (active_version.get() && |
155 active_version->status() == ServiceWorkerVersion::ACTIVATING) { | 155 active_version->status() == ServiceWorkerVersion::ACTIVATING) { |
156 registration->active_version()->RegisterStatusChangeCallback( | 156 registration->active_version()->RegisterStatusChangeCallback( |
157 base::Bind(&self::OnVersionStatusChanged, | 157 base::Bind(&self::OnVersionStatusChanged, |
158 weak_factory_.GetWeakPtr(), | 158 weak_factory_.GetWeakPtr(), |
159 registration, | 159 registration, |
160 active_version)); | 160 active_version)); |
161 return; | 161 return; |
162 } | 162 } |
163 | 163 |
164 if (!active_version || | 164 if (!active_version.get() || |
165 active_version->status() != ServiceWorkerVersion::ACTIVATED) { | 165 active_version->status() != ServiceWorkerVersion::ACTIVATED) { |
166 job_->FallbackToNetwork(); | 166 job_->FallbackToNetwork(); |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
170 provider_host_->AssociateRegistration(registration); | 170 provider_host_->AssociateRegistration(registration.get()); |
171 job_->ForwardToServiceWorker(); | 171 job_->ForwardToServiceWorker(); |
172 } | 172 } |
173 | 173 |
174 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 174 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
175 ServiceWorkerRegistration* registration, | 175 ServiceWorkerRegistration* registration, |
176 ServiceWorkerVersion* version) { | 176 ServiceWorkerVersion* version) { |
177 if (version != registration->active_version() || | 177 if (version != registration->active_version() || |
178 version->status() != ServiceWorkerVersion::ACTIVATED) { | 178 version->status() != ServiceWorkerVersion::ACTIVATED) { |
179 job_->FallbackToNetwork(); | 179 job_->FallbackToNetwork(); |
180 return; | 180 return; |
181 } | 181 } |
182 | 182 |
183 provider_host_->AssociateRegistration(registration); | 183 provider_host_->AssociateRegistration(registration); |
184 job_->ForwardToServiceWorker(); | 184 job_->ForwardToServiceWorker(); |
185 } | 185 } |
186 | 186 |
187 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 187 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
188 DCHECK(job_.get()); | 188 DCHECK(job_.get()); |
189 DCHECK(context_); | 189 DCHECK(context_); |
190 DCHECK(provider_host_->active_version()); | 190 DCHECK(provider_host_->active_version()); |
191 job_->ForwardToServiceWorker(); | 191 job_->ForwardToServiceWorker(); |
192 } | 192 } |
193 | 193 |
194 } // namespace content | 194 } // namespace content |
OLD | NEW |