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

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

Issue 558873003: Better coordinate what's responsible for associating a registration to a document. During navigatio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« 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 "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 27 matching lines...) Expand all
38 ServiceWorkerControlleeRequestHandler:: 38 ServiceWorkerControlleeRequestHandler::
39 ~ServiceWorkerControlleeRequestHandler() { 39 ~ServiceWorkerControlleeRequestHandler() {
40 // Navigation triggers an update to occur shortly after the page and 40 // Navigation triggers an update to occur shortly after the page and
41 // its initial subresources load. 41 // its initial subresources load.
42 if (provider_host_ && provider_host_->active_version()) { 42 if (provider_host_ && provider_host_->active_version()) {
43 if (is_main_resource_load_) 43 if (is_main_resource_load_)
44 provider_host_->active_version()->ScheduleUpdate(); 44 provider_host_->active_version()->ScheduleUpdate();
45 else 45 else
46 provider_host_->active_version()->DeferScheduledUpdate(); 46 provider_host_->active_version()->DeferScheduledUpdate();
47 } 47 }
48
49 if (is_main_resource_load_ && provider_host_)
50 provider_host_->SetAllowAssociation(true);
48 } 51 }
49 52
50 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( 53 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob(
51 net::URLRequest* request, 54 net::URLRequest* request,
52 net::NetworkDelegate* network_delegate) { 55 net::NetworkDelegate* network_delegate) {
53 if (!context_ || !provider_host_) { 56 if (!context_ || !provider_host_) {
54 // We can't do anything other than to fall back to network. 57 // We can't do anything other than to fall back to network.
55 job_ = NULL; 58 job_ = NULL;
56 return NULL; 59 return NULL;
57 } 60 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 DCHECK(context_); 112 DCHECK(context_);
110 TRACE_EVENT_ASYNC_BEGIN1( 113 TRACE_EVENT_ASYNC_BEGIN1(
111 "ServiceWorker", 114 "ServiceWorker",
112 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 115 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
113 job_.get(), 116 job_.get(),
114 "URL", url.spec()); 117 "URL", url.spec());
115 // The corresponding provider_host may already have associated a registration 118 // The corresponding provider_host may already have associated a registration
116 // in redirect case, unassociate it now. 119 // in redirect case, unassociate it now.
117 provider_host_->DisassociateRegistration(); 120 provider_host_->DisassociateRegistration();
118 121
122 // Also prevent a registrater job for establishing an association to a new
123 // registration while we're finding an existing registration.
124 provider_host_->SetAllowAssociation(false);
125
119 GURL stripped_url = net::SimplifyUrlForRequest(url); 126 GURL stripped_url = net::SimplifyUrlForRequest(url);
120 provider_host_->SetDocumentUrl(stripped_url); 127 provider_host_->SetDocumentUrl(stripped_url);
121 context_->storage()->FindRegistrationForDocument( 128 context_->storage()->FindRegistrationForDocument(
122 stripped_url, 129 stripped_url,
123 base::Bind(&self::DidLookupRegistrationForMainResource, 130 base::Bind(&self::DidLookupRegistrationForMainResource,
124 weak_factory_.GetWeakPtr())); 131 weak_factory_.GetWeakPtr()));
125 } 132 }
126 133
127 void 134 void
128 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( 135 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource(
129 ServiceWorkerStatusCode status, 136 ServiceWorkerStatusCode status,
130 const scoped_refptr<ServiceWorkerRegistration>& registration) { 137 const scoped_refptr<ServiceWorkerRegistration>& registration) {
131 DCHECK(job_.get()); 138 DCHECK(job_.get());
139 provider_host_->SetAllowAssociation(true);
132 if (status != SERVICE_WORKER_OK) { 140 if (status != SERVICE_WORKER_OK) {
133 job_->FallbackToNetwork(); 141 job_->FallbackToNetwork();
134 TRACE_EVENT_ASYNC_END1( 142 TRACE_EVENT_ASYNC_END1(
135 "ServiceWorker", 143 "ServiceWorker",
136 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 144 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
137 job_.get(), 145 job_.get(),
138 "Status", status); 146 "Status", status);
139 return; 147 return;
140 } 148 }
141 DCHECK(registration.get()); 149 DCHECK(registration.get());
142 150
143 ServiceWorkerMetrics::CountControlledPageLoad(); 151 ServiceWorkerMetrics::CountControlledPageLoad();
144 152
145 // Initiate activation of a waiting version. 153 // Initiate activation of a waiting version.
146 // Usually a register job initiates activation but that 154 // Usually a register job initiates activation but that
147 // doesn't happen if the browser exits prior to activation 155 // doesn't happen if the browser exits prior to activation
148 // having occurred. This check handles that case. 156 // having occurred. This check handles that case.
149 if (registration->waiting_version()) 157 if (registration->waiting_version())
150 registration->ActivateWaitingVersionWhenReady(); 158 registration->ActivateWaitingVersionWhenReady();
151 159
152 scoped_refptr<ServiceWorkerVersion> active_version = 160 scoped_refptr<ServiceWorkerVersion> active_version =
153 registration->active_version(); 161 registration->active_version();
154 162
155 // Wait until it's activated before firing fetch events. 163 // Wait until it's activated before firing fetch events.
156 if (active_version.get() && 164 if (active_version.get() &&
157 active_version->status() == ServiceWorkerVersion::ACTIVATING) { 165 active_version->status() == ServiceWorkerVersion::ACTIVATING) {
166 provider_host_->SetAllowAssociation(false);
158 registration->active_version()->RegisterStatusChangeCallback( 167 registration->active_version()->RegisterStatusChangeCallback(
159 base::Bind(&self::OnVersionStatusChanged, 168 base::Bind(&self::OnVersionStatusChanged,
160 weak_factory_.GetWeakPtr(), 169 weak_factory_.GetWeakPtr(),
161 registration, 170 registration,
162 active_version)); 171 active_version));
163 TRACE_EVENT_ASYNC_END2( 172 TRACE_EVENT_ASYNC_END2(
164 "ServiceWorker", 173 "ServiceWorker",
165 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 174 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
166 job_.get(), 175 job_.get(),
167 "Status", status, 176 "Status", status,
(...skipping 21 matching lines...) Expand all
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) {
208 provider_host_->SetAllowAssociation(true);
199 if (version != registration->active_version() || 209 if (version != registration->active_version() ||
200 version->status() != ServiceWorkerVersion::ACTIVATED) { 210 version->status() != ServiceWorkerVersion::ACTIVATED) {
201 job_->FallbackToNetwork(); 211 job_->FallbackToNetwork();
202 return; 212 return;
203 } 213 }
204
205 provider_host_->AssociateRegistration(registration); 214 provider_host_->AssociateRegistration(registration);
206 job_->ForwardToServiceWorker(); 215 job_->ForwardToServiceWorker();
207 } 216 }
208 217
209 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { 218 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() {
210 DCHECK(job_.get()); 219 DCHECK(job_.get());
211 DCHECK(context_); 220 DCHECK(context_);
212 DCHECK(provider_host_->active_version()); 221 DCHECK(provider_host_->active_version());
213 job_->ForwardToServiceWorker(); 222 job_->ForwardToServiceWorker();
214 } 223 }
215 224
216 } // namespace content 225 } // 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