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

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

Issue 948293002: Add RAPPOR metrics of ServiceWorker.ControlledPage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated nasko's comment Created 5 years, 9 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 "base/trace_event/trace_event.h" 7 #include "base/trace_event/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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 job_.get(), 149 job_.get(),
150 "URL", request->url().spec()); 150 "URL", request->url().spec());
151 // The corresponding provider_host may already have associated a registration 151 // The corresponding provider_host may already have associated a registration
152 // in redirect case, unassociate it now. 152 // in redirect case, unassociate it now.
153 provider_host_->DisassociateRegistration(); 153 provider_host_->DisassociateRegistration();
154 154
155 // Also prevent a registrater job for establishing an association to a new 155 // Also prevent a registrater job for establishing an association to a new
156 // registration while we're finding an existing registration. 156 // registration while we're finding an existing registration.
157 provider_host_->SetAllowAssociation(false); 157 provider_host_->SetAllowAssociation(false);
158 158
159 GURL stripped_url = net::SimplifyUrlForRequest(request->url()); 159 stripped_url_ = net::SimplifyUrlForRequest(request->url());
160 provider_host_->SetDocumentUrl(stripped_url); 160 provider_host_->SetDocumentUrl(stripped_url_);
161 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); 161 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies());
162 context_->storage()->FindRegistrationForDocument( 162 context_->storage()->FindRegistrationForDocument(
163 stripped_url, 163 stripped_url_, base::Bind(&self::DidLookupRegistrationForMainResource,
164 base::Bind(&self::DidLookupRegistrationForMainResource, 164 weak_factory_.GetWeakPtr()));
165 weak_factory_.GetWeakPtr()));
166 } 165 }
167 166
168 void 167 void
169 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( 168 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource(
170 ServiceWorkerStatusCode status, 169 ServiceWorkerStatusCode status,
171 const scoped_refptr<ServiceWorkerRegistration>& registration) { 170 const scoped_refptr<ServiceWorkerRegistration>& registration) {
172 DCHECK(job_.get()); 171 DCHECK(job_.get());
173 if (provider_host_) 172 if (provider_host_)
174 provider_host_->SetAllowAssociation(true); 173 provider_host_->SetAllowAssociation(true);
175 if (status != SERVICE_WORKER_OK || !provider_host_) { 174 if (status != SERVICE_WORKER_OK || !provider_host_) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 TRACE_EVENT_ASYNC_END2( 230 TRACE_EVENT_ASYNC_END2(
232 "ServiceWorker", 231 "ServiceWorker",
233 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 232 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
234 job_.get(), 233 job_.get(),
235 "Status", status, 234 "Status", status,
236 "Info", 235 "Info",
237 "ServiceWorkerVersion is not available, so falling back to network"); 236 "ServiceWorkerVersion is not available, so falling back to network");
238 return; 237 return;
239 } 238 }
240 239
241 ServiceWorkerMetrics::CountControlledPageLoad(); 240 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_);
242 241
243 provider_host_->AssociateRegistration(registration.get()); 242 provider_host_->AssociateRegistration(registration.get());
244 job_->ForwardToServiceWorker(); 243 job_->ForwardToServiceWorker();
245 TRACE_EVENT_ASYNC_END2( 244 TRACE_EVENT_ASYNC_END2(
246 "ServiceWorker", 245 "ServiceWorker",
247 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", 246 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource",
248 job_.get(), 247 job_.get(),
249 "Status", status, 248 "Status", status,
250 "Info", 249 "Info",
251 "Forwarded to the ServiceWorker"); 250 "Forwarded to the ServiceWorker");
252 } 251 }
253 252
254 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged( 253 void ServiceWorkerControlleeRequestHandler::OnVersionStatusChanged(
255 ServiceWorkerRegistration* registration, 254 ServiceWorkerRegistration* registration,
256 ServiceWorkerVersion* version) { 255 ServiceWorkerVersion* version) {
257 if (provider_host_) 256 if (provider_host_)
258 provider_host_->SetAllowAssociation(true); 257 provider_host_->SetAllowAssociation(true);
259 if (version != registration->active_version() || 258 if (version != registration->active_version() ||
260 version->status() != ServiceWorkerVersion::ACTIVATED || 259 version->status() != ServiceWorkerVersion::ACTIVATED ||
261 !provider_host_) { 260 !provider_host_) {
262 job_->FallbackToNetwork(); 261 job_->FallbackToNetwork();
263 return; 262 return;
264 } 263 }
265 264
266 ServiceWorkerMetrics::CountControlledPageLoad(); 265 ServiceWorkerMetrics::CountControlledPageLoad(stripped_url_);
267 266
268 provider_host_->AssociateRegistration(registration); 267 provider_host_->AssociateRegistration(registration);
269 job_->ForwardToServiceWorker(); 268 job_->ForwardToServiceWorker();
270 } 269 }
271 270
272 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { 271 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() {
273 DCHECK(job_.get()); 272 DCHECK(job_.get());
274 DCHECK(context_); 273 DCHECK(context_);
275 DCHECK(provider_host_->active_version()); 274 DCHECK(provider_host_->active_version());
276 job_->ForwardToServiceWorker(); 275 job_->ForwardToServiceWorker();
277 } 276 }
278 277
279 } // namespace content 278 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698