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

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

Issue 569423002: Fix a ServiceWorker crasher (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_controllee_request_handler_unittest.cc » ('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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return; 103 return;
104 } 104 }
105 job_->GetExtraResponseInfo(was_fetched_via_service_worker, 105 job_->GetExtraResponseInfo(was_fetched_via_service_worker,
106 original_url_via_service_worker); 106 original_url_via_service_worker);
107 } 107 }
108 108
109 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( 109 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource(
110 const GURL& url) { 110 const GURL& url) {
111 DCHECK(job_.get()); 111 DCHECK(job_.get());
112 DCHECK(context_); 112 DCHECK(context_);
113 DCHECK(provider_host_);
113 TRACE_EVENT_ASYNC_BEGIN1( 114 TRACE_EVENT_ASYNC_BEGIN1(
114 "ServiceWorker", 115 "ServiceWorker",
115 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 116 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
116 job_.get(), 117 job_.get(),
117 "URL", url.spec()); 118 "URL", url.spec());
118 // The corresponding provider_host may already have associated a registration 119 // The corresponding provider_host may already have associated a registration
119 // in redirect case, unassociate it now. 120 // in redirect case, unassociate it now.
120 provider_host_->DisassociateRegistration(); 121 provider_host_->DisassociateRegistration();
121 122
122 // Also prevent a registrater job for establishing an association to a new 123 // Also prevent a registrater job for establishing an association to a new
123 // registration while we're finding an existing registration. 124 // registration while we're finding an existing registration.
124 provider_host_->SetAllowAssociation(false); 125 provider_host_->SetAllowAssociation(false);
125 126
126 GURL stripped_url = net::SimplifyUrlForRequest(url); 127 GURL stripped_url = net::SimplifyUrlForRequest(url);
127 provider_host_->SetDocumentUrl(stripped_url); 128 provider_host_->SetDocumentUrl(stripped_url);
128 context_->storage()->FindRegistrationForDocument( 129 context_->storage()->FindRegistrationForDocument(
129 stripped_url, 130 stripped_url,
130 base::Bind(&self::DidLookupRegistrationForMainResource, 131 base::Bind(&self::DidLookupRegistrationForMainResource,
131 weak_factory_.GetWeakPtr())); 132 weak_factory_.GetWeakPtr()));
132 } 133 }
133 134
134 void 135 void
135 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( 136 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource(
136 ServiceWorkerStatusCode status, 137 ServiceWorkerStatusCode status,
137 const scoped_refptr<ServiceWorkerRegistration>& registration) { 138 const scoped_refptr<ServiceWorkerRegistration>& registration) {
138 DCHECK(job_.get()); 139 DCHECK(job_.get());
139 provider_host_->SetAllowAssociation(true); 140 if (provider_host_)
140 if (status != SERVICE_WORKER_OK) { 141 provider_host_->SetAllowAssociation(true);
142 if (status != SERVICE_WORKER_OK || !provider_host_) {
141 job_->FallbackToNetwork(); 143 job_->FallbackToNetwork();
142 TRACE_EVENT_ASYNC_END1( 144 TRACE_EVENT_ASYNC_END1(
143 "ServiceWorker", 145 "ServiceWorker",
144 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 146 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
145 job_.get(), 147 job_.get(),
146 "Status", status); 148 "Status", status);
147 return; 149 return;
148 } 150 }
149 DCHECK(registration.get()); 151 DCHECK(registration.get());
150 152
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 200 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
199 job_.get(), 201 job_.get(),
200 "Status", status, 202 "Status", status,
201 "Info", 203 "Info",
202 "Forwarded to the ServiceWorker"); 204 "Forwarded to the ServiceWorker");
203 } 205 }
204 206
205 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( 207 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
206 ServiceWorkerRegistration* registration, 208 ServiceWorkerRegistration* registration,
207 ServiceWorkerVersion* version) { 209 ServiceWorkerVersion* version) {
208 provider_host_->SetAllowAssociation(true); 210 if (provider_host_)
211 provider_host_->SetAllowAssociation(true);
209 if (version != registration->active_version() || 212 if (version != registration->active_version() ||
210 version->status() != ServiceWorkerVersion::ACTIVATED) { 213 version->status() != ServiceWorkerVersion::ACTIVATED ||
214 !provider_host_) {
211 job_->FallbackToNetwork(); 215 job_->FallbackToNetwork();
212 return; 216 return;
213 } 217 }
214 218
215 ServiceWorkerMetrics::CountControlledPageLoad(); 219 ServiceWorkerMetrics::CountControlledPageLoad();
216 220
217 provider_host_->AssociateRegistration(registration); 221 provider_host_->AssociateRegistration(registration);
218 job_->ForwardToServiceWorker(); 222 job_->ForwardToServiceWorker();
219 } 223 }
220 224
221 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { 225 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() {
222 DCHECK(job_.get()); 226 DCHECK(job_.get());
223 DCHECK(context_); 227 DCHECK(context_);
224 DCHECK(provider_host_->active_version()); 228 DCHECK(provider_host_->active_version());
225 job_->ForwardToServiceWorker(); 229 job_->ForwardToServiceWorker();
226 } 230 }
227 231
228 } // namespace content 232 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_controllee_request_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698