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

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

Issue 354643003: ServiceWorker: Support navigator.serviceWorker.active (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 return job_.get(); 88 return job_.get();
89 } 89 }
90 90
91 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( 91 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource(
92 const GURL& url) { 92 const GURL& url) {
93 DCHECK(job_.get()); 93 DCHECK(job_.get());
94 DCHECK(context_); 94 DCHECK(context_);
95 // The corresponding provider_host may already have associate version in 95 // The corresponding provider_host may already have associate version in
96 // redirect case, unassociate it now. 96 // redirect case, unassociate it now.
97 provider_host_->SetActiveVersion(NULL); 97 provider_host_->UnsetVersion(NULL);
98 provider_host_->SetWaitingVersion(NULL);
99 98
100 GURL stripped_url = net::SimplifyUrlForRequest(url); 99 GURL stripped_url = net::SimplifyUrlForRequest(url);
101 provider_host_->SetDocumentUrl(stripped_url); 100 provider_host_->SetDocumentUrl(stripped_url);
102 context_->storage()->FindRegistrationForDocument( 101 context_->storage()->FindRegistrationForDocument(
103 stripped_url, 102 stripped_url,
104 base::Bind(&self::DidLookupRegistrationForMainResource, 103 base::Bind(&self::DidLookupRegistrationForMainResource,
105 weak_factory_.GetWeakPtr())); 104 weak_factory_.GetWeakPtr()));
106 } 105 }
107 106
108 void 107 void
109 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( 108 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource(
110 ServiceWorkerStatusCode status, 109 ServiceWorkerStatusCode status,
111 const scoped_refptr<ServiceWorkerRegistration>& registration) { 110 const scoped_refptr<ServiceWorkerRegistration>& registration) {
112 DCHECK(job_.get()); 111 DCHECK(job_.get());
113 if (status != SERVICE_WORKER_OK || !registration->active_version()) { 112 if (status != SERVICE_WORKER_OK || !registration->active_version()) {
114 // No registration, or no active version for the registration is available. 113 // No registration, or no active version for the registration is available.
115 job_->FallbackToNetwork(); 114 job_->FallbackToNetwork();
116 return; 115 return;
117 } 116 }
118 117
119 ServiceWorkerMetrics::CountControlledPageLoad(); 118 ServiceWorkerMetrics::CountControlledPageLoad();
120 119
121 // TODO(michaeln): should SetWaitingVersion() even if no active version so 120 // TODO(michaeln): should SetWaitingVersion() even if no active version so
122 // so the versions in the pipeline (.installing, .waiting) show up in the 121 // so the versions in the pipeline (.installing, .waiting) show up in the
123 // attribute values. 122 // attribute values.
124 DCHECK(registration); 123 DCHECK(registration);
124 provider_host_->SetControllerVersion(registration->active_version());
125 provider_host_->SetActiveVersion(registration->active_version()); 125 provider_host_->SetActiveVersion(registration->active_version());
126 provider_host_->SetWaitingVersion(registration->waiting_version()); 126 provider_host_->SetWaitingVersion(registration->waiting_version());
127 job_->ForwardToServiceWorker(); 127 job_->ForwardToServiceWorker();
128 } 128 }
129 129
130 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { 130 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() {
131 DCHECK(job_.get()); 131 DCHECK(job_.get());
132 DCHECK(context_); 132 DCHECK(context_);
133 DCHECK(provider_host_->active_version()); 133 DCHECK(provider_host_->active_version());
134 job_->ForwardToServiceWorker(); 134 job_->ForwardToServiceWorker();
135 } 135 }
136 136
137 } // namespace content 137 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_provider_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698