Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/browser/service_worker/service_worker_controllee_request_handler.cc

Issue 2251633002: Use tri-state enum for the existence of Fetch Handler in ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 15 matching lines...) Expand all
26 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
27 27
28 namespace content { 28 namespace content {
29 29
30 namespace { 30 namespace {
31 31
32 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job, 32 bool MaybeForwardToServiceWorker(ServiceWorkerURLRequestJob* job,
33 const ServiceWorkerVersion* version) { 33 const ServiceWorkerVersion* version) {
34 DCHECK(job); 34 DCHECK(job);
35 DCHECK(version); 35 DCHECK(version);
36 if (version->has_fetch_handler()) { 36 if (version->has_fetch_handler().value()) {
37 job->ForwardToServiceWorker(); 37 job->ForwardToServiceWorker();
38 return true; 38 return true;
39 } 39 }
40 40
41 job->FallbackToNetworkOrRenderer(); 41 job->FallbackToNetworkOrRenderer();
42 return false; 42 return false;
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 "ServiceWorker", 274 "ServiceWorker",
275 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 275 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
276 job_.get(), 276 job_.get(),
277 "Status", status, 277 "Status", status,
278 "Info", 278 "Info",
279 "ServiceWorkerVersion is not available, so falling back to network"); 279 "ServiceWorkerVersion is not available, so falling back to network");
280 return; 280 return;
281 } 281 }
282 282
283 ServiceWorkerMetrics::CountControlledPageLoad( 283 ServiceWorkerMetrics::CountControlledPageLoad(
284 stripped_url_, active_version->has_fetch_handler(), is_main_frame_load_); 284 stripped_url_, active_version->has_fetch_handler().value(),
285 is_main_frame_load_);
285 286
286 bool is_forwarded = 287 bool is_forwarded =
287 MaybeForwardToServiceWorker(job_.get(), active_version.get()); 288 MaybeForwardToServiceWorker(job_.get(), active_version.get());
288 289
289 TRACE_EVENT_ASYNC_END2( 290 TRACE_EVENT_ASYNC_END2(
290 "ServiceWorker", 291 "ServiceWorker",
291 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 292 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
292 job_.get(), "Status", status, "Info", 293 job_.get(), "Status", status, "Info",
293 (is_forwarded) ? "Forwarded to the ServiceWorker" 294 (is_forwarded) ? "Forwarded to the ServiceWorker"
294 : "Skipped the ServiceWorker which has no fetch handler"); 295 : "Skipped the ServiceWorker which has no fetch handler");
295 } 296 }
296 297
297 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( 298 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
298 ServiceWorkerRegistration* registration, 299 ServiceWorkerRegistration* registration,
299 ServiceWorkerVersion* version) { 300 ServiceWorkerVersion* version) {
300 // The job may have been canceled and then destroyed before this was invoked. 301 // The job may have been canceled and then destroyed before this was invoked.
301 if (!job_) 302 if (!job_)
302 return; 303 return;
303 304
304 if (provider_host_) 305 if (provider_host_)
305 provider_host_->SetAllowAssociation(true); 306 provider_host_->SetAllowAssociation(true);
306 if (version != registration->active_version() || 307 if (version != registration->active_version() ||
307 version->status() != ServiceWorkerVersion::ACTIVATED || 308 version->status() != ServiceWorkerVersion::ACTIVATED ||
308 !provider_host_) { 309 !provider_host_) {
309 job_->FallbackToNetwork(); 310 job_->FallbackToNetwork();
310 return; 311 return;
311 } 312 }
312 313
313 ServiceWorkerMetrics::CountControlledPageLoad( 314 ServiceWorkerMetrics::CountControlledPageLoad(
314 stripped_url_, version->has_fetch_handler(), is_main_frame_load_); 315 stripped_url_, version->has_fetch_handler().value(), is_main_frame_load_);
315 316
316 provider_host_->AssociateRegistration(registration, 317 provider_host_->AssociateRegistration(registration,
317 false /* notify_controllerchange */); 318 false /* notify_controllerchange */);
318 319
319 MaybeForwardToServiceWorker(job_.get(), version); 320 MaybeForwardToServiceWorker(job_.get(), version);
320 } 321 }
321 322
322 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration( 323 void ServiceWorkerControlleeRequestHandler::DidUpdateRegistration(
323 const scoped_refptr<ServiceWorkerRegistration>& original_registration, 324 const scoped_refptr<ServiceWorkerRegistration>& original_registration,
324 ServiceWorkerStatusCode status, 325 ServiceWorkerStatusCode status,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 DCHECK(provider_host_); 424 DCHECK(provider_host_);
424 // Detach the controller so subresource requests also skip the worker. 425 // Detach the controller so subresource requests also skip the worker.
425 provider_host_->NotifyControllerLost(); 426 provider_host_->NotifyControllerLost();
426 } 427 }
427 428
428 void ServiceWorkerControlleeRequestHandler::ClearJob() { 429 void ServiceWorkerControlleeRequestHandler::ClearJob() {
429 job_.reset(); 430 job_.reset();
430 } 431 }
431 432
432 } // namespace content 433 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698