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 <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
13 #include "content/browser/service_worker/service_worker_metrics.h" | 13 #include "content/browser/service_worker/service_worker_metrics.h" |
14 #include "content/browser/service_worker/service_worker_provider_host.h" | 14 #include "content/browser/service_worker/service_worker_provider_host.h" |
15 #include "content/browser/service_worker/service_worker_registration.h" | 15 #include "content/browser/service_worker/service_worker_registration.h" |
16 #include "content/browser/service_worker/service_worker_response_info.h" | 16 #include "content/browser/service_worker/service_worker_response_info.h" |
17 #include "content/browser/service_worker/service_worker_url_request_job.h" | 17 #include "content/browser/service_worker/service_worker_url_request_job.h" |
18 #include "content/common/resource_request_body_impl.h" | 18 #include "content/common/resource_request_body_impl.h" |
19 #include "content/common/service_worker/service_worker_types.h" | 19 #include "content/common/service_worker/service_worker_types.h" |
20 #include "content/common/service_worker/service_worker_utils.h" | 20 #include "content/common/service_worker/service_worker_utils.h" |
21 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/resource_request_info.h" | 23 #include "content/public/browser/resource_request_info.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/common/browser_side_navigation_policy.h" | 25 #include "content/public/common/browser_side_navigation_policy.h" |
26 #include "content/public/common/content_client.h" | 26 #include "content/public/common/content_client.h" |
27 #include "content/public/common/resource_response_info.h" | 27 #include "content/public/common/resource_response_info.h" |
28 #include "mojo/public/cpp/bindings/strong_binding.h" | |
28 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
29 #include "net/base/url_util.h" | 30 #include "net/base/url_util.h" |
30 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
31 #include "ui/base/page_transition_types.h" | 32 #include "ui/base/page_transition_types.h" |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
36 // Helper to support both a URLRequestJob and a URLLoaderFactory to support | |
37 // running with and without --enable-network-service. | |
38 class JobWrapper { | |
kinuko
2017/05/08 14:55:47
nit: make it an inner class of SWControlleeRequest
scottmg
2017/05/08 20:12:31
Done.
| |
39 public: | |
40 explicit JobWrapper(base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job) | |
41 : url_request_job_(std::move(url_request_job)), factory_(nullptr) {} | |
42 | |
43 // --enable-network-service. | |
44 explicit JobWrapper(ServiceWorkerControlleeURLLoaderFactory* factory) | |
45 : factory_(factory) {} | |
46 | |
47 void FallbackToNetwork() { | |
48 if (factory_) { | |
49 factory_->FallbackToNetwork(); | |
50 } else { | |
51 url_request_job_->FallbackToNetwork(); | |
52 } | |
53 } | |
54 | |
55 bool ShouldFallbackToNetwork() { | |
56 if (factory_) { | |
57 return factory_->ShouldFallbackToNetwork(); | |
58 } else { | |
59 return url_request_job_->ShouldFallbackToNetwork(); | |
60 } | |
61 } | |
62 | |
63 ui::PageTransition GetPageTransition() { | |
64 if (factory_) { | |
65 return factory_->GetPageTransition(); | |
66 } else { | |
67 const ResourceRequestInfo* info = | |
68 ResourceRequestInfo::ForRequest(url_request_job_->request()); | |
69 // ResourceRequestInfo may not be set in some tests. | |
70 if (!info) | |
71 return ui::PAGE_TRANSITION_LINK; | |
72 return info->GetPageTransition(); | |
73 } | |
74 } | |
75 | |
76 size_t GetURLChainSize() const { | |
77 if (factory_) { | |
78 return factory_->GetURLChainSize(); | |
79 } else { | |
80 return url_request_job_->request()->url_chain().size(); | |
81 } | |
82 } | |
83 | |
84 void ForwardToServiceWorker() { | |
85 if (factory_) { | |
86 factory_->ForwardToServiceWorker(); | |
87 } else { | |
88 url_request_job_->ForwardToServiceWorker(); | |
89 } | |
90 } | |
91 | |
92 void FallbackToNetworkOrRenderer() { | |
93 if (factory_) { | |
94 factory_->FallbackToNetworkOrRenderer(); | |
95 } else { | |
96 url_request_job_->FallbackToNetworkOrRenderer(); | |
97 } | |
98 } | |
99 | |
100 void FailDueToLostController() { | |
101 if (factory_) { | |
102 factory_->FailDueToLostController(); | |
103 } else { | |
104 url_request_job_->FailDueToLostController(); | |
105 } | |
106 } | |
107 | |
108 bool WasCanceled() const { | |
109 if (factory_) { | |
110 return factory_->WasCanceled(); | |
111 } else { | |
112 return !url_request_job_; | |
113 } | |
114 } | |
115 | |
116 private: | |
117 base::WeakPtr<ServiceWorkerURLRequestJob> url_request_job_; | |
118 ServiceWorkerControlleeURLLoaderFactory* factory_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(JobWrapper); | |
121 }; | |
122 | |
35 namespace { | 123 namespace { |
36 | 124 |
37 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job, | 125 bool MaybeForwardToServiceWorker(JobWrapper* job, |
38 const ServiceWorkerVersion* version) { | 126 const ServiceWorkerVersion* version) { |
39 DCHECK(job); | 127 DCHECK(job); |
40 DCHECK(version); | 128 DCHECK(version); |
41 DCHECK_NE(version->fetch_handler_existence(), | 129 DCHECK_NE(version->fetch_handler_existence(), |
42 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); | 130 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
43 if (version->fetch_handler_existence() == | 131 if (version->fetch_handler_existence() == |
44 ServiceWorkerVersion::FetchHandlerExistence::EXISTS) { | 132 ServiceWorkerVersion::FetchHandlerExistence::EXISTS) { |
45 job->ForwardToServiceWorker(); | 133 job->ForwardToServiceWorker(); |
46 return true; | 134 return true; |
47 } | 135 } |
48 | 136 |
49 job->FallbackToNetworkOrRenderer(); | 137 job->FallbackToNetworkOrRenderer(); |
50 return false; | 138 return false; |
51 } | 139 } |
52 | 140 |
53 ui::PageTransition GetPageTransition(net::URLRequest* request) { | |
54 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | |
55 // ResourceRequestInfo may not be set in some tests. | |
56 if (!info) | |
57 return ui::PAGE_TRANSITION_LINK; | |
58 return info->GetPageTransition(); | |
59 } | |
60 | |
61 } // namespace | 141 } // namespace |
62 | 142 |
63 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( | 143 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( |
64 base::WeakPtr<ServiceWorkerContextCore> context, | 144 base::WeakPtr<ServiceWorkerContextCore> context, |
65 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 145 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
66 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 146 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
67 FetchRequestMode request_mode, | 147 FetchRequestMode request_mode, |
68 FetchCredentialsMode credentials_mode, | 148 FetchCredentialsMode credentials_mode, |
69 FetchRedirectMode redirect_mode, | 149 FetchRedirectMode redirect_mode, |
70 ResourceType resource_type, | 150 ResourceType resource_type, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 213 } |
134 | 214 |
135 // It's for original request (A) or redirect case (B-a or B-b). | 215 // It's for original request (A) or redirect case (B-a or B-b). |
136 std::unique_ptr<ServiceWorkerURLRequestJob> job( | 216 std::unique_ptr<ServiceWorkerURLRequestJob> job( |
137 new ServiceWorkerURLRequestJob( | 217 new ServiceWorkerURLRequestJob( |
138 request, network_delegate, provider_host_->client_uuid(), | 218 request, network_delegate, provider_host_->client_uuid(), |
139 blob_storage_context_, resource_context, request_mode_, | 219 blob_storage_context_, resource_context, request_mode_, |
140 credentials_mode_, redirect_mode_, resource_type_, | 220 credentials_mode_, redirect_mode_, resource_type_, |
141 request_context_type_, frame_type_, body_, | 221 request_context_type_, frame_type_, body_, |
142 ServiceWorkerFetchType::FETCH, base::nullopt, this)); | 222 ServiceWorkerFetchType::FETCH, base::nullopt, this)); |
143 job_ = job->GetWeakPtr(); | 223 job_ = base::MakeUnique<JobWrapper>(job->GetWeakPtr()); |
144 | 224 |
145 resource_context_ = resource_context; | 225 resource_context_ = resource_context; |
146 | 226 |
147 if (is_main_resource_load_) | 227 if (is_main_resource_load_) |
148 PrepareForMainResource(request); | 228 PrepareForMainResource(request->url(), request->first_party_for_cookies()); |
149 else | 229 else |
150 PrepareForSubResource(); | 230 PrepareForSubResource(); |
151 | 231 |
152 if (job_->ShouldFallbackToNetwork()) { | 232 if (job_->ShouldFallbackToNetwork()) { |
153 // If we know we can fallback to network at this point (in case | 233 // If we know we can fallback to network at this point (in case |
154 // the storage lookup returned immediately), just destroy the job and return | 234 // the storage lookup returned immediately), just destroy the job and return |
155 // NULL here to fallback to network. | 235 // NULL here to fallback to network. |
156 | 236 |
157 // If this is a subresource request, all subsequent requests should also use | 237 // If this is a subresource request, all subsequent requests should also use |
158 // the network. | 238 // the network. |
159 if (!is_main_resource_load_) | 239 if (!is_main_resource_load_) |
160 use_network_ = true; | 240 use_network_ = true; |
161 | 241 |
162 job.reset(); | 242 job.reset(); |
163 ClearJob(); | 243 ClearJob(); |
164 } | 244 } |
165 | 245 |
166 return job.release(); | 246 return job.release(); |
167 } | 247 } |
168 | 248 |
249 mojom::URLLoaderFactoryPtrInfo | |
250 ServiceWorkerControlleeRequestHandler::MaybeCreateURLLoader( | |
kinuko
2017/05/08 14:55:47
MaybeGetURLLoaderFactory ...from what it does?
scottmg
2017/05/08 20:12:31
Done.
| |
251 const ResourceRequest& request, | |
252 ResourceContext* resource_context, | |
253 std::unique_ptr<ServiceWorkerRequestHandler> request_handler) { | |
254 ClearJob(); | |
255 // TODO(scottmg): | |
256 // ServiceWorkerResponseInfo::ResetDataForRequest(request); | |
257 | |
258 if (!context_ || !provider_host_) { | |
259 // We can't do anything other than to fall back to network. | |
260 return mojom::URLLoaderFactoryPtrInfo(); | |
261 } | |
262 | |
263 // This may get called multiple times for original and redirect requests: | |
264 // A. original request case: use_network_ is false, no previous location info. | |
265 // B. redirect or restarted request case: | |
266 // a) use_network_ is false if the previous location was forwarded to SW. | |
267 // b) use_network_ is false if the previous location was fallback. | |
268 // c) use_network_ is true if additional restart was required to fall back. | |
269 | |
270 // Fall back to network. (Case B-c) | |
271 if (use_network_) { | |
272 // Once a subresource request has fallen back to the network once, it will | |
273 // never be handled by a service worker. This is not true of main frame | |
274 // requests. | |
275 if (is_main_resource_load_) | |
276 use_network_ = false; | |
277 return mojom::URLLoaderFactoryPtrInfo(); | |
278 } | |
279 | |
280 mojom::URLLoaderFactoryPtr url_loader_factory; | |
281 auto factory_impl = base::MakeUnique<ServiceWorkerControlleeURLLoaderFactory>( | |
282 std::move(request_handler), provider_host_->client_uuid(), | |
283 blob_storage_context_, resource_context, request_mode_, credentials_mode_, | |
284 redirect_mode_, resource_type_, request_context_type_, frame_type_, body_, | |
285 ServiceWorkerFetchType::FETCH, base::nullopt, this); | |
286 auto* factory = factory_impl.get(); | |
287 mojo::MakeStrongBinding(std::move(factory_impl), | |
288 mojo::MakeRequest(&url_loader_factory)); | |
289 | |
290 // It's for original request (A) or redirect case (B-a or B-b). | |
291 job_ = base::MakeUnique<JobWrapper>(factory); | |
292 | |
293 resource_context_ = resource_context; | |
294 | |
295 if (is_main_resource_load_) | |
296 PrepareForMainResource(request.url, request.first_party_for_cookies); | |
297 else | |
298 PrepareForSubResource(); | |
299 | |
300 if (job_->ShouldFallbackToNetwork()) { | |
301 // If we know we can fallback to network at this point (in case | |
302 // the storage lookup returned immediately), just destroy the job and return | |
303 // NULL here to fallback to network. | |
304 | |
305 // If this is a subresource request, all subsequent requests should also use | |
306 // the network. | |
307 if (!is_main_resource_load_) | |
308 use_network_ = true; | |
309 | |
310 ClearJob(); | |
311 return mojom::URLLoaderFactoryPtrInfo(); | |
312 } | |
313 | |
314 return url_loader_factory.PassInterface(); | |
315 } | |
316 | |
169 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 317 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
170 const net::URLRequest* request) { | 318 const GURL& url, |
319 const GURL& first_party_for_cookies) { | |
171 DCHECK(job_.get()); | 320 DCHECK(job_.get()); |
172 DCHECK(context_); | 321 DCHECK(context_); |
173 DCHECK(provider_host_); | 322 DCHECK(provider_host_); |
174 TRACE_EVENT_ASYNC_BEGIN1( | 323 TRACE_EVENT_ASYNC_BEGIN1( |
175 "ServiceWorker", | 324 "ServiceWorker", |
176 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 325 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
177 job_.get(), | 326 job_.get(), "URL", url.spec()); |
178 "URL", request->url().spec()); | |
179 // The corresponding provider_host may already have associated a registration | 327 // The corresponding provider_host may already have associated a registration |
180 // in redirect case, unassociate it now. | 328 // in redirect case, unassociate it now. |
181 provider_host_->DisassociateRegistration(); | 329 provider_host_->DisassociateRegistration(); |
182 | 330 |
183 // Also prevent a registrater job for establishing an association to a new | 331 // Also prevent a registrater job for establishing an association to a new |
184 // registration while we're finding an existing registration. | 332 // registration while we're finding an existing registration. |
185 provider_host_->SetAllowAssociation(false); | 333 provider_host_->SetAllowAssociation(false); |
186 | 334 |
187 stripped_url_ = net::SimplifyUrlForRequest(request->url()); | 335 stripped_url_ = net::SimplifyUrlForRequest(url); |
188 provider_host_->SetDocumentUrl(stripped_url_); | 336 provider_host_->SetDocumentUrl(stripped_url_); |
189 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); | 337 provider_host_->SetTopmostFrameUrl(first_party_for_cookies); |
190 context_->storage()->FindRegistrationForDocument( | 338 context_->storage()->FindRegistrationForDocument( |
191 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, | 339 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, |
192 weak_factory_.GetWeakPtr())); | 340 weak_factory_.GetWeakPtr())); |
193 } | 341 } |
194 | 342 |
195 void ServiceWorkerControlleeRequestHandler:: | 343 void ServiceWorkerControlleeRequestHandler:: |
196 DidLookupRegistrationForMainResource( | 344 DidLookupRegistrationForMainResource( |
197 ServiceWorkerStatusCode status, | 345 ServiceWorkerStatusCode status, |
198 scoped_refptr<ServiceWorkerRegistration> registration) { | 346 scoped_refptr<ServiceWorkerRegistration> registration) { |
199 // The job may have been canceled and then destroyed before this was invoked. | 347 // The job may have been canceled and then destroyed before this was invoked. |
200 if (!job_) | 348 if (job_->WasCanceled()) |
201 return; | 349 return; |
202 | 350 |
203 const bool need_to_update = !force_update_started_ && registration && | 351 const bool need_to_update = !force_update_started_ && registration && |
204 context_->force_update_on_page_load(); | 352 context_->force_update_on_page_load(); |
205 | 353 |
206 if (provider_host_ && !need_to_update) | 354 if (provider_host_ && !need_to_update) |
207 provider_host_->SetAllowAssociation(true); | 355 provider_host_->SetAllowAssociation(true); |
208 if (status != SERVICE_WORKER_OK || !provider_host_ || !context_) { | 356 if (status != SERVICE_WORKER_OK || !provider_host_ || !context_) { |
209 job_->FallbackToNetwork(); | 357 job_->FallbackToNetwork(); |
210 TRACE_EVENT_ASYNC_END1( | 358 TRACE_EVENT_ASYNC_END1( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 "Status", status, | 453 "Status", status, |
306 "Info", | 454 "Info", |
307 "ServiceWorkerVersion is not available, so falling back to network"); | 455 "ServiceWorkerVersion is not available, so falling back to network"); |
308 return; | 456 return; |
309 } | 457 } |
310 | 458 |
311 DCHECK_NE(active_version->fetch_handler_existence(), | 459 DCHECK_NE(active_version->fetch_handler_existence(), |
312 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); | 460 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
313 ServiceWorkerMetrics::CountControlledPageLoad( | 461 ServiceWorkerMetrics::CountControlledPageLoad( |
314 active_version->site_for_uma(), stripped_url_, is_main_frame_load_, | 462 active_version->site_for_uma(), stripped_url_, is_main_frame_load_, |
315 GetPageTransition(job_->request()), job_->request()->url_chain().size()); | 463 job_->GetPageTransition(), job_->GetURLChainSize()); |
316 | 464 |
317 bool is_forwarded = | 465 bool is_forwarded = |
318 MaybeForwardToServiceWorker(job_.get(), active_version.get()); | 466 MaybeForwardToServiceWorker(job_.get(), active_version.get()); |
319 | 467 |
320 TRACE_EVENT_ASYNC_END2( | 468 TRACE_EVENT_ASYNC_END2( |
321 "ServiceWorker", | 469 "ServiceWorker", |
322 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 470 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
323 job_.get(), "Status", status, "Info", | 471 job_.get(), "Status", status, "Info", |
324 (is_forwarded) ? "Forwarded to the ServiceWorker" | 472 (is_forwarded) ? "Forwarded to the ServiceWorker" |
325 : "Skipped the ServiceWorker which has no fetch handler"); | 473 : "Skipped the ServiceWorker which has no fetch handler"); |
326 } | 474 } |
327 | 475 |
328 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( | 476 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( |
329 ServiceWorkerRegistration* registration, | 477 ServiceWorkerRegistration* registration, |
330 ServiceWorkerVersion* version) { | 478 ServiceWorkerVersion* version) { |
331 // The job may have been canceled and then destroyed before this was invoked. | 479 // The job may have been canceled and then destroyed before this was invoked. |
332 if (!job_) | 480 if (job_->WasCanceled()) |
333 return; | 481 return; |
334 | 482 |
335 if (provider_host_) | 483 if (provider_host_) |
336 provider_host_->SetAllowAssociation(true); | 484 provider_host_->SetAllowAssociation(true); |
337 if (version != registration->active_version() || | 485 if (version != registration->active_version() || |
338 version->status() != ServiceWorkerVersion::ACTIVATED || | 486 version->status() != ServiceWorkerVersion::ACTIVATED || |
339 !provider_host_) { | 487 !provider_host_) { |
340 job_->FallbackToNetwork(); | 488 job_->FallbackToNetwork(); |
341 return; | 489 return; |
342 } | 490 } |
343 | 491 |
344 DCHECK_NE(version->fetch_handler_existence(), | 492 DCHECK_NE(version->fetch_handler_existence(), |
345 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); | 493 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
346 ServiceWorkerMetrics::CountControlledPageLoad( | 494 ServiceWorkerMetrics::CountControlledPageLoad( |
347 version->site_for_uma(), stripped_url_, is_main_frame_load_, | 495 version->site_for_uma(), stripped_url_, is_main_frame_load_, |
348 GetPageTransition(job_->request()), job_->request()->url_chain().size()); | 496 job_->GetPageTransition(), job_->GetURLChainSize()); |
349 | 497 |
350 provider_host_->AssociateRegistration(registration, | 498 provider_host_->AssociateRegistration(registration, |
351 false /* notify_controllerchange */); | 499 false /* notify_controllerchange */); |
352 | 500 |
353 MaybeForwardToServiceWorker(job_.get(), version); | 501 MaybeForwardToServiceWorker(job_.get(), version); |
354 } | 502 } |
355 | 503 |
356 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( | 504 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( |
357 const scoped_refptr<ServiceWorkerRegistration>& original_registration, | 505 const scoped_refptr<ServiceWorkerRegistration>& original_registration, |
358 ServiceWorkerStatusCode status, | 506 ServiceWorkerStatusCode status, |
359 const std::string& status_message, | 507 const std::string& status_message, |
360 int64_t registration_id) { | 508 int64_t registration_id) { |
361 DCHECK(force_update_started_); | 509 DCHECK(force_update_started_); |
362 | 510 |
363 // The job may have been canceled and then destroyed before this was invoked. | 511 // The job may have been canceled and then destroyed before this was invoked. |
364 if (!job_) | 512 if (job_->WasCanceled()) |
365 return; | 513 return; |
366 | 514 |
367 if (!context_) { | 515 if (!context_) { |
368 job_->FallbackToNetwork(); | 516 job_->FallbackToNetwork(); |
369 return; | 517 return; |
370 } | 518 } |
371 if (status != SERVICE_WORKER_OK || | 519 if (status != SERVICE_WORKER_OK || |
372 !original_registration->installing_version()) { | 520 !original_registration->installing_version()) { |
373 // Update failed. Look up the registration again since the original | 521 // Update failed. Look up the registration again since the original |
374 // registration was possibly unregistered in the meantime. | 522 // registration was possibly unregistered in the meantime. |
375 context_->storage()->FindRegistrationForDocument( | 523 context_->storage()->FindRegistrationForDocument( |
376 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, | 524 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource, |
377 weak_factory_.GetWeakPtr())); | 525 weak_factory_.GetWeakPtr())); |
378 return; | 526 return; |
379 } | 527 } |
380 DCHECK_EQ(original_registration->id(), registration_id); | 528 DCHECK_EQ(original_registration->id(), registration_id); |
381 scoped_refptr<ServiceWorkerVersion> new_version = | 529 scoped_refptr<ServiceWorkerVersion> new_version = |
382 original_registration->installing_version(); | 530 original_registration->installing_version(); |
383 new_version->ReportForceUpdateToDevTools(); | 531 new_version->ReportForceUpdateToDevTools(); |
384 new_version->set_skip_waiting(true); | 532 new_version->set_skip_waiting(true); |
385 new_version->RegisterStatusChangeCallback(base::Bind( | 533 new_version->RegisterStatusChangeCallback(base::Bind( |
386 &self::OnUpdatedVersionStatusChanged, weak_factory_.GetWeakPtr(), | 534 &self::OnUpdatedVersionStatusChanged, weak_factory_.GetWeakPtr(), |
387 original_registration, new_version)); | 535 original_registration, new_version)); |
388 } | 536 } |
389 | 537 |
390 void ServiceWorkerControlleeRequestHandler::OnUpdatedVersionStatusChanged( | 538 void ServiceWorkerControlleeRequestHandler::OnUpdatedVersionStatusChanged( |
391 const scoped_refptr<ServiceWorkerRegistration>& registration, | 539 const scoped_refptr<ServiceWorkerRegistration>& registration, |
392 const scoped_refptr<ServiceWorkerVersion>& version) { | 540 const scoped_refptr<ServiceWorkerVersion>& version) { |
393 // The job may have been canceled and then destroyed before this was invoked. | 541 // The job may have been canceled and then destroyed before this was invoked. |
394 if (!job_) | 542 if (job_->WasCanceled()) |
395 return; | 543 return; |
396 | 544 |
397 if (!context_) { | 545 if (!context_) { |
398 job_->FallbackToNetwork(); | 546 job_->FallbackToNetwork(); |
399 return; | 547 return; |
400 } | 548 } |
401 if (version->status() == ServiceWorkerVersion::ACTIVATED || | 549 if (version->status() == ServiceWorkerVersion::ACTIVATED || |
402 version->status() == ServiceWorkerVersion::REDUNDANT) { | 550 version->status() == ServiceWorkerVersion::REDUNDANT) { |
403 // When the status is REDUNDANT, the update failed (eg: script error), we | 551 // When the status is REDUNDANT, the update failed (eg: script error), we |
404 // continue with the incumbent version. | 552 // continue with the incumbent version. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 DCHECK(provider_host_); | 616 DCHECK(provider_host_); |
469 // Detach the controller so subresource requests also skip the worker. | 617 // Detach the controller so subresource requests also skip the worker. |
470 provider_host_->NotifyControllerLost(); | 618 provider_host_->NotifyControllerLost(); |
471 } | 619 } |
472 | 620 |
473 void ServiceWorkerControlleeRequestHandler::ClearJob() { | 621 void ServiceWorkerControlleeRequestHandler::ClearJob() { |
474 job_.reset(); | 622 job_.reset(); |
475 } | 623 } |
476 | 624 |
477 } // namespace content | 625 } // namespace content |
OLD | NEW |