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

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

Issue 515753003: Add ServiceWorker timing information on the popup panel in DevTools's Network tab (2/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set send_start/send_end 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
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_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/time/time.h"
14 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 15 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
15 #include "content/browser/service_worker/service_worker_provider_host.h" 16 #include "content/browser/service_worker/service_worker_provider_host.h"
16 #include "content/common/resource_request_body.h" 17 #include "content/common/resource_request_body.h"
17 #include "content/common/service_worker/service_worker_types.h" 18 #include "content/common/service_worker/service_worker_types.h"
18 #include "content/public/browser/blob_handle.h" 19 #include "content/public/browser/blob_handle.h"
19 #include "content/public/browser/resource_request_info.h" 20 #include "content/public/browser/resource_request_info.h"
20 #include "content/public/common/page_transition_types.h" 21 #include "content/public/common/page_transition_types.h"
21 #include "net/http/http_request_headers.h" 22 #include "net/http/http_request_headers.h"
22 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 24 #include "net/http/http_response_info.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 bool ServiceWorkerURLRequestJob::GetMimeType(std::string* mime_type) const { 82 bool ServiceWorkerURLRequestJob::GetMimeType(std::string* mime_type) const {
82 if (!http_info()) 83 if (!http_info())
83 return false; 84 return false;
84 return http_info()->headers->GetMimeType(mime_type); 85 return http_info()->headers->GetMimeType(mime_type);
85 } 86 }
86 87
87 void ServiceWorkerURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { 88 void ServiceWorkerURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
88 if (!http_info()) 89 if (!http_info())
89 return; 90 return;
90 *info = *http_info(); 91 *info = *http_info();
92 info->response_time = response_time_;
93 }
94
95 void ServiceWorkerURLRequestJob::GetLoadTimingInfo(
96 net::LoadTimingInfo* load_timing_info) const {
97 *load_timing_info = load_timing_info_;
91 } 98 }
92 99
93 int ServiceWorkerURLRequestJob::GetResponseCode() const { 100 int ServiceWorkerURLRequestJob::GetResponseCode() const {
94 if (!http_info()) 101 if (!http_info())
95 return -1; 102 return -1;
96 return http_info()->headers->response_code(); 103 return http_info()->headers->response_code();
97 } 104 }
98 105
99 void ServiceWorkerURLRequestJob::SetExtraRequestHeaders( 106 void ServiceWorkerURLRequestJob::SetExtraRequestHeaders(
100 const net::HttpRequestHeaders& headers) { 107 const net::HttpRequestHeaders& headers) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 159 }
153 160
154 void ServiceWorkerURLRequestJob::OnBeforeNetworkStart(net::URLRequest* request, 161 void ServiceWorkerURLRequestJob::OnBeforeNetworkStart(net::URLRequest* request,
155 bool* defer) { 162 bool* defer) {
156 NOTREACHED(); 163 NOTREACHED();
157 } 164 }
158 165
159 void ServiceWorkerURLRequestJob::OnResponseStarted(net::URLRequest* request) { 166 void ServiceWorkerURLRequestJob::OnResponseStarted(net::URLRequest* request) {
160 // TODO(falken): Add Content-Length, Content-Type if they were not provided in 167 // TODO(falken): Add Content-Length, Content-Type if they were not provided in
161 // the ServiceWorkerResponse. 168 // the ServiceWorkerResponse.
169 response_time_ = base::Time::Now();
162 CommitResponseHeader(); 170 CommitResponseHeader();
163 } 171 }
164 172
165 void ServiceWorkerURLRequestJob::OnReadCompleted(net::URLRequest* request, 173 void ServiceWorkerURLRequestJob::OnReadCompleted(net::URLRequest* request,
166 int bytes_read) { 174 int bytes_read) {
167 SetStatus(request->status()); 175 SetStatus(request->status());
168 if (!request->status().is_success()) { 176 if (!request->status().is_success()) {
169 NotifyDone(request->status()); 177 NotifyDone(request->status());
170 return; 178 return;
171 } 179 }
172 NotifyReadComplete(bytes_read); 180 NotifyReadComplete(bytes_read);
173 if (bytes_read == 0) 181 if (bytes_read == 0)
174 NotifyDone(request->status()); 182 NotifyDone(request->status());
175 } 183 }
176 184
177 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { 185 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const {
178 if (!http_response_info_) 186 if (!http_response_info_)
179 return NULL; 187 return NULL;
180 if (range_response_info_) 188 if (range_response_info_)
181 return range_response_info_.get(); 189 return range_response_info_.get();
182 return http_response_info_.get(); 190 return http_response_info_.get();
183 } 191 }
184 192
185 void ServiceWorkerURLRequestJob::GetExtraResponseInfo( 193 void ServiceWorkerURLRequestJob::GetExtraResponseInfo(
186 bool* was_fetched_via_service_worker, 194 bool* was_fetched_via_service_worker,
187 GURL* original_url_via_service_worker) const { 195 GURL* original_url_via_service_worker,
196 base::TimeTicks* fetch_start_time,
197 base::TimeTicks* fetch_ready_time,
198 base::TimeTicks* fetch_end_time) const {
188 if (response_type_ != FORWARD_TO_SERVICE_WORKER) { 199 if (response_type_ != FORWARD_TO_SERVICE_WORKER) {
189 *was_fetched_via_service_worker = false; 200 *was_fetched_via_service_worker = false;
190 *original_url_via_service_worker = GURL(); 201 *original_url_via_service_worker = GURL();
191 return; 202 return;
192 } 203 }
193 *was_fetched_via_service_worker = true; 204 *was_fetched_via_service_worker = true;
194 *original_url_via_service_worker = response_url_; 205 *original_url_via_service_worker = response_url_;
206 *fetch_start_time = fetch_start_time_;
207 *fetch_ready_time = fetch_ready_time_;
208 *fetch_end_time = fetch_end_time_;
195 } 209 }
196 210
197 211
198 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { 212 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() {
199 } 213 }
200 214
201 void ServiceWorkerURLRequestJob::MaybeStartRequest() { 215 void ServiceWorkerURLRequestJob::MaybeStartRequest() {
202 if (is_started_ && response_type_ != NOT_DETERMINED) { 216 if (is_started_ && response_type_ != NOT_DETERMINED) {
203 // Start asynchronously. 217 // Start asynchronously.
204 base::MessageLoop::current()->PostTask( 218 base::MessageLoop::current()->PostTask(
(...skipping 21 matching lines...) Expand all
226 DCHECK(!fetch_dispatcher_); 240 DCHECK(!fetch_dispatcher_);
227 // Send a fetch event to the ServiceWorker associated to the 241 // Send a fetch event to the ServiceWorker associated to the
228 // provider_host. 242 // provider_host.
229 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher( 243 fetch_dispatcher_.reset(new ServiceWorkerFetchDispatcher(
230 CreateFetchRequest(), 244 CreateFetchRequest(),
231 provider_host_->active_version(), 245 provider_host_->active_version(),
232 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, 246 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent,
233 weak_factory_.GetWeakPtr()), 247 weak_factory_.GetWeakPtr()),
234 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, 248 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent,
235 weak_factory_.GetWeakPtr()))); 249 weak_factory_.GetWeakPtr())));
250 fetch_start_time_ = base::TimeTicks::Now();
251 load_timing_info_.send_start = fetch_start_time_;
236 fetch_dispatcher_->Run(); 252 fetch_dispatcher_->Run();
237 return; 253 return;
238 } 254 }
239 255
240 NOTREACHED(); 256 NOTREACHED();
241 } 257 }
242 258
243 scoped_ptr<ServiceWorkerFetchRequest> 259 scoped_ptr<ServiceWorkerFetchRequest>
244 ServiceWorkerURLRequestJob::CreateFetchRequest() { 260 ServiceWorkerURLRequestJob::CreateFetchRequest() {
245 std::string blob_uuid; 261 std::string blob_uuid;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 338 }
323 339
324 request_body_blob_data_handle_ = 340 request_body_blob_data_handle_ =
325 blob_storage_context_->AddFinishedBlob(blob_data.get()); 341 blob_storage_context_->AddFinishedBlob(blob_data.get());
326 *blob_uuid = uuid; 342 *blob_uuid = uuid;
327 *blob_size = total_size; 343 *blob_size = total_size;
328 return true; 344 return true;
329 } 345 }
330 346
331 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { 347 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() {
332 // TODO(shimazu): Set the timestamp to measure the time to launch SW 348 fetch_ready_time_ = base::TimeTicks::Now();
michaeln 2014/09/05 21:23:52 lgtm 2 fetch_ready_time might be more analogous
333 // This is related to this (http://crbug.com/401389)
334 } 349 }
335 350
336 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( 351 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent(
337 ServiceWorkerStatusCode status, 352 ServiceWorkerStatusCode status,
338 ServiceWorkerFetchEventResult fetch_result, 353 ServiceWorkerFetchEventResult fetch_result,
339 const ServiceWorkerResponse& response) { 354 const ServiceWorkerResponse& response) {
340 fetch_dispatcher_.reset(); 355 fetch_dispatcher_.reset();
341 356
342 // Check if we're not orphaned. 357 // Check if we're not orphaned.
343 if (!request()) 358 if (!request())
(...skipping 13 matching lines...) Expand all
357 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) { 372 if (fetch_result == SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK) {
358 // Change the response type and restart the request to fallback to 373 // Change the response type and restart the request to fallback to
359 // the network. 374 // the network.
360 response_type_ = FALLBACK_TO_NETWORK; 375 response_type_ = FALLBACK_TO_NETWORK;
361 NotifyRestartRequired(); 376 NotifyRestartRequired();
362 return; 377 return;
363 } 378 }
364 379
365 // We should have a response now. 380 // We should have a response now.
366 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result); 381 DCHECK_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, fetch_result);
367 382 fetch_end_time_ = base::TimeTicks::Now();
383 load_timing_info_.send_end = fetch_end_time_;
mmenke 2014/09/05 14:22:34 Will fetch_end_time_ always be send_end, or might
368 // Set up a request for reading the blob. 384 // Set up a request for reading the blob.
369 if (!response.blob_uuid.empty() && blob_storage_context_) { 385 if (!response.blob_uuid.empty() && blob_storage_context_) {
370 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 386 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
371 blob_storage_context_->GetBlobDataFromUUID(response.blob_uuid); 387 blob_storage_context_->GetBlobDataFromUUID(response.blob_uuid);
372 if (!blob_data_handle) { 388 if (!blob_data_handle) {
373 // The renderer gave us a bad blob UUID. 389 // The renderer gave us a bad blob UUID.
374 DeliverErrorResponse(); 390 DeliverErrorResponse();
375 return; 391 return;
376 } 392 }
377 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( 393 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest(
378 blob_data_handle.Pass(), request()->context(), this); 394 blob_data_handle.Pass(), request()->context(), this);
379 blob_request_->Start(); 395 blob_request_->Start();
380 } 396 }
381 397
382 response_url_ = response.url; 398 response_url_ = response.url;
383 CreateResponseHeader( 399 CreateResponseHeader(
384 response.status_code, response.status_text, response.headers); 400 response.status_code, response.status_text, response.headers);
401 load_timing_info_.receive_headers_end = base::TimeTicks::Now();
mmenke 2014/09/05 14:22:34 Not exactly a huge cost in terms of performance or
385 if (!blob_request_) 402 if (!blob_request_)
386 CommitResponseHeader(); 403 CommitResponseHeader();
387 } 404 }
388 405
389 void ServiceWorkerURLRequestJob::CreateResponseHeader( 406 void ServiceWorkerURLRequestJob::CreateResponseHeader(
390 int status_code, 407 int status_code,
391 const std::string& status_text, 408 const std::string& status_text,
392 const std::map<std::string, std::string>& headers) { 409 const std::map<std::string, std::string>& headers) {
393 // TODO(kinuko): If the response has an identifier to on-disk cache entry, 410 // TODO(kinuko): If the response has an identifier to on-disk cache entry,
394 // pull response header from the disk. 411 // pull response header from the disk.
(...skipping 22 matching lines...) Expand all
417 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { 434 void ServiceWorkerURLRequestJob::DeliverErrorResponse() {
418 // TODO(falken): Print an error to the console of the ServiceWorker and of 435 // TODO(falken): Print an error to the console of the ServiceWorker and of
419 // the requesting page. 436 // the requesting page.
420 CreateResponseHeader(500, 437 CreateResponseHeader(500,
421 "Service Worker Response Error", 438 "Service Worker Response Error",
422 std::map<std::string, std::string>()); 439 std::map<std::string, std::string>());
423 CommitResponseHeader(); 440 CommitResponseHeader();
424 } 441 }
425 442
426 } // namespace content 443 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_url_request_job.h ('k') | content/child/resource_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698