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

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 732633002: Adding instrumentation to locate the source of jankiness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke@ comments Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/profiler/scoped_tracker.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "content/browser/appcache/appcache_interceptor.h" 12 #include "content/browser/appcache/appcache_interceptor.h"
12 #include "content/browser/child_process_security_policy_impl.h" 13 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/loader/cross_site_resource_handler.h" 14 #include "content/browser/loader/cross_site_resource_handler.h"
14 #include "content/browser/loader/detachable_resource_handler.h" 15 #include "content/browser/loader/detachable_resource_handler.h"
15 #include "content/browser/loader/resource_loader_delegate.h" 16 #include "content/browser/loader/resource_loader_delegate.h"
16 #include "content/browser/loader/resource_request_info_impl.h" 17 #include "content/browser/loader/resource_request_info_impl.h"
17 #include "content/browser/service_worker/service_worker_request_handler.h" 18 #include "content/browser/service_worker/service_worker_request_handler.h"
18 #include "content/browser/ssl/ssl_client_auth_handler.h" 19 #include "content/browser/ssl/ssl_client_auth_handler.h"
19 #include "content/browser/ssl/ssl_manager.h" 20 #include "content/browser/ssl/ssl_manager.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 105 }
105 106
106 void ResourceLoader::StartRequest() { 107 void ResourceLoader::StartRequest() {
107 if (delegate_->HandleExternalProtocol(this, request_->url())) { 108 if (delegate_->HandleExternalProtocol(this, request_->url())) {
108 CancelAndIgnore(); 109 CancelAndIgnore();
109 return; 110 return;
110 } 111 }
111 112
112 // Give the handler a chance to delay the URLRequest from being started. 113 // Give the handler a chance to delay the URLRequest from being started.
113 bool defer_start = false; 114 bool defer_start = false;
114 if (!handler_->OnWillStart(request_->url(), &defer_start)) { 115 {
115 Cancel(); 116 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
116 return; 117 tracked_objects::ScopedTracker tracking_profile(
118 FROM_HERE_WITH_EXPLICIT_FUNCTION(
119 "423948 ResourceLoader::StartRequest"));
120
121 if (!handler_->OnWillStart(request_->url(), &defer_start)) {
122 Cancel();
123 return;
124 }
117 } 125 }
118 126
119 if (defer_start) { 127 if (defer_start) {
120 deferred_stage_ = DEFERRED_START; 128 deferred_stage_ = DEFERRED_START;
121 } else { 129 } else {
122 StartRequestInternal(); 130 StartRequestInternal();
123 } 131 }
124 } 132 }
125 133
126 void ResourceLoader::CancelRequest(bool from_renderer) { 134 void ResourceLoader::CancelRequest(bool from_renderer) {
(...skipping 28 matching lines...) Expand all
155 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; 163 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_;
156 164
157 bool is_finished = (progress.size() == progress.position()); 165 bool is_finished = (progress.size() == progress.position());
158 bool enough_new_progress = 166 bool enough_new_progress =
159 (amt_since_last > (progress.size() / kHalfPercentIncrements)); 167 (amt_since_last > (progress.size() / kHalfPercentIncrements));
160 bool too_much_time_passed = time_since_last > kOneSecond; 168 bool too_much_time_passed = time_since_last > kOneSecond;
161 169
162 if (is_finished || enough_new_progress || too_much_time_passed) { 170 if (is_finished || enough_new_progress || too_much_time_passed) {
163 ResourceRequestInfoImpl* info = GetRequestInfo(); 171 ResourceRequestInfoImpl* info = GetRequestInfo();
164 if (info->is_upload_progress_enabled()) { 172 if (info->is_upload_progress_enabled()) {
173 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is
174 // fixed.
175 tracked_objects::ScopedTracker tracking_profile(
176 FROM_HERE_WITH_EXPLICIT_FUNCTION(
177 "423948 ResourceLoader::ReportUploadProgress"));
178
165 handler_->OnUploadProgress(progress.position(), progress.size()); 179 handler_->OnUploadProgress(progress.position(), progress.size());
166 waiting_for_upload_progress_ack_ = true; 180 waiting_for_upload_progress_ack_ = true;
167 } 181 }
168 last_upload_ticks_ = TimeTicks::Now(); 182 last_upload_ticks_ = TimeTicks::Now();
169 last_upload_position_ = progress.position(); 183 last_upload_position_ = progress.position();
170 } 184 }
171 } 185 }
172 186
173 void ResourceLoader::MarkAsTransferring() { 187 void ResourceLoader::MarkAsTransferring() {
174 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType())) 188 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType()))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 239
226 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) { 240 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
227 // The request is complete so we can remove it. 241 // The request is complete so we can remove it.
228 CancelAndIgnore(); 242 CancelAndIgnore();
229 return; 243 return;
230 } 244 }
231 245
232 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 246 scoped_refptr<ResourceResponse> response(new ResourceResponse());
233 PopulateResourceResponse(info, request_.get(), response.get()); 247 PopulateResourceResponse(info, request_.get(), response.get());
234 248
249 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
250 tracked_objects::ScopedTracker tracking_profile(
251 FROM_HERE_WITH_EXPLICIT_FUNCTION(
252 "423948 ResourceLoader::OnReceivedRedirect"));
253
235 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) { 254 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) {
236 Cancel(); 255 Cancel();
237 } else if (*defer) { 256 } else if (*defer) {
238 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed. 257 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed.
239 } 258 }
240 } 259 }
241 260
242 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, 261 void ResourceLoader::OnAuthRequired(net::URLRequest* unused,
243 net::AuthChallengeInfo* auth_info) { 262 net::AuthChallengeInfo* auth_info) {
244 DCHECK_EQ(request_.get(), unused); 263 DCHECK_EQ(request_.get(), unused);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 render_process_id, 315 render_process_id,
297 render_frame_id, 316 render_frame_id,
298 ssl_info, 317 ssl_info,
299 fatal); 318 fatal);
300 } 319 }
301 320
302 void ResourceLoader::OnBeforeNetworkStart(net::URLRequest* unused, 321 void ResourceLoader::OnBeforeNetworkStart(net::URLRequest* unused,
303 bool* defer) { 322 bool* defer) {
304 DCHECK_EQ(request_.get(), unused); 323 DCHECK_EQ(request_.get(), unused);
305 324
325 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
326 tracked_objects::ScopedTracker tracking_profile(
327 FROM_HERE_WITH_EXPLICIT_FUNCTION(
328 "423948 ResourceLoader::OnBeforeNetworkStart"));
329
306 // Give the handler a chance to delay the URLRequest from using the network. 330 // Give the handler a chance to delay the URLRequest from using the network.
307 if (!handler_->OnBeforeNetworkStart(request_->url(), defer)) { 331 if (!handler_->OnBeforeNetworkStart(request_->url(), defer)) {
308 Cancel(); 332 Cancel();
309 return; 333 return;
310 } else if (*defer) { 334 } else if (*defer) {
311 deferred_stage_ = DEFERRED_NETWORK_START; 335 deferred_stage_ = DEFERRED_NETWORK_START;
312 } 336 }
313 } 337 }
314 338
315 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { 339 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) {
340 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
341 tracked_objects::ScopedTracker tracking_profile(
342 FROM_HERE_WITH_EXPLICIT_FUNCTION(
343 "423948 ResourceLoader::OnResponseStarted"));
344
316 DCHECK_EQ(request_.get(), unused); 345 DCHECK_EQ(request_.get(), unused);
317 346
318 VLOG(1) << "OnResponseStarted: " << request_->url().spec(); 347 VLOG(1) << "OnResponseStarted: " << request_->url().spec();
319 348
320 // The CanLoadPage check should take place after any server redirects have 349 // The CanLoadPage check should take place after any server redirects have
321 // finished, at the point in time that we know a page will commit in the 350 // finished, at the point in time that we know a page will commit in the
322 // renderer process. 351 // renderer process.
323 ResourceRequestInfoImpl* info = GetRequestInfo(); 352 ResourceRequestInfoImpl* info = GetRequestInfo();
324 ChildProcessSecurityPolicyImpl* policy = 353 ChildProcessSecurityPolicyImpl* policy =
325 ChildProcessSecurityPolicyImpl::GetInstance(); 354 ChildProcessSecurityPolicyImpl::GetInstance();
(...skipping 21 matching lines...) Expand all
347 return; 376 return;
348 377
349 if (request_->status().is_success()) { 378 if (request_->status().is_success()) {
350 StartReading(false); // Read the first chunk. 379 StartReading(false); // Read the first chunk.
351 } else { 380 } else {
352 ResponseCompleted(); 381 ResponseCompleted();
353 } 382 }
354 } 383 }
355 384
356 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { 385 void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) {
386 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
387 tracked_objects::ScopedTracker tracking_profile(
388 FROM_HERE_WITH_EXPLICIT_FUNCTION(
389 "423948 ResourceLoader::OnReadCompleted"));
390
357 DCHECK_EQ(request_.get(), unused); 391 DCHECK_EQ(request_.get(), unused);
358 VLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\"" 392 VLOG(1) << "OnReadCompleted: \"" << request_->url().spec() << "\""
359 << " bytes_read = " << bytes_read; 393 << " bytes_read = " << bytes_read;
360 394
361 // bytes_read == -1 always implies an error. 395 // bytes_read == -1 always implies an error.
362 if (bytes_read == -1 || !request_->status().is_success()) { 396 if (bytes_read == -1 || !request_->status().is_success()) {
363 ResponseCompleted(); 397 ResponseCompleted();
364 return; 398 return;
365 } 399 }
366 400
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 signed_certificate_timestamp_ids); 580 signed_certificate_timestamp_ids);
547 } else { 581 } else {
548 // We should not have any SSL state. 582 // We should not have any SSL state.
549 DCHECK(!request_->ssl_info().cert_status && 583 DCHECK(!request_->ssl_info().cert_status &&
550 request_->ssl_info().security_bits == -1 && 584 request_->ssl_info().security_bits == -1 &&
551 !request_->ssl_info().connection_status); 585 !request_->ssl_info().connection_status);
552 } 586 }
553 587
554 delegate_->DidReceiveResponse(this); 588 delegate_->DidReceiveResponse(this);
555 589
590 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
591 tracked_objects::ScopedTracker tracking_profile(
592 FROM_HERE_WITH_EXPLICIT_FUNCTION(
593 "423948 ResourceLoader::CompleteResponseStarted"));
594
556 bool defer = false; 595 bool defer = false;
557 if (!handler_->OnResponseStarted(response.get(), &defer)) { 596 if (!handler_->OnResponseStarted(response.get(), &defer)) {
558 Cancel(); 597 Cancel();
559 } else if (defer) { 598 } else if (defer) {
560 read_deferral_start_time_ = base::TimeTicks::Now(); 599 read_deferral_start_time_ = base::TimeTicks::Now();
561 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed. 600 deferred_stage_ = DEFERRED_READ; // Read first chunk when resumed.
562 } 601 }
563 } 602 }
564 603
565 void ResourceLoader::StartReading(bool is_continuation) { 604 void ResourceLoader::StartReading(bool is_continuation) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 639 }
601 640
602 void ResourceLoader::ReadMore(int* bytes_read) { 641 void ResourceLoader::ReadMore(int* bytes_read) {
603 DCHECK(!is_deferred()); 642 DCHECK(!is_deferred());
604 643
605 // Make sure we track the buffer in at least one place. This ensures it gets 644 // Make sure we track the buffer in at least one place. This ensures it gets
606 // deleted even in the case the request has already finished its job and 645 // deleted even in the case the request has already finished its job and
607 // doesn't use the buffer. 646 // doesn't use the buffer.
608 scoped_refptr<net::IOBuffer> buf; 647 scoped_refptr<net::IOBuffer> buf;
609 int buf_size; 648 int buf_size;
610 if (!handler_->OnWillRead(&buf, &buf_size, -1)) { 649 {
611 Cancel(); 650 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
612 return; 651 tracked_objects::ScopedTracker tracking_profile(
652 FROM_HERE_WITH_EXPLICIT_FUNCTION("423948 ResourceLoader::ReadMore"));
653
654 if (!handler_->OnWillRead(&buf, &buf_size, -1)) {
655 Cancel();
656 return;
657 }
613 } 658 }
614 659
615 DCHECK(buf.get()); 660 DCHECK(buf.get());
616 DCHECK(buf_size > 0); 661 DCHECK(buf_size > 0);
617 662
618 request_->Read(buf.get(), buf_size, bytes_read); 663 request_->Read(buf.get(), buf_size, bytes_read);
619 664
620 // No need to check the return value here as we'll detect errors by 665 // No need to check the return value here as we'll detect errors by
621 // inspecting the URLRequest's status. 666 // inspecting the URLRequest's status.
622 } 667 }
623 668
624 void ResourceLoader::CompleteRead(int bytes_read) { 669 void ResourceLoader::CompleteRead(int bytes_read) {
625 DCHECK(bytes_read >= 0); 670 DCHECK(bytes_read >= 0);
626 DCHECK(request_->status().is_success()); 671 DCHECK(request_->status().is_success());
627 672
673 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
674 tracked_objects::ScopedTracker tracking_profile(
675 FROM_HERE_WITH_EXPLICIT_FUNCTION("423948 ResourceLoader::CompleteRead"));
676
628 bool defer = false; 677 bool defer = false;
629 if (!handler_->OnReadCompleted(bytes_read, &defer)) { 678 if (!handler_->OnReadCompleted(bytes_read, &defer)) {
630 Cancel(); 679 Cancel();
631 } else if (defer) { 680 } else if (defer) {
632 deferred_stage_ = 681 deferred_stage_ =
633 bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE; 682 bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE;
634 } 683 }
635 684
636 // Note: the request may still have been cancelled while OnReadCompleted 685 // Note: the request may still have been cancelled while OnReadCompleted
637 // returns true if OnReadCompleted caused request to get cancelled 686 // returns true if OnReadCompleted caused request to get cancelled
(...skipping 15 matching lines...) Expand all
653 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps, 702 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps,
654 info->GetChildID(), 703 info->GetChildID(),
655 &signed_certificate_timestamp_ids); 704 &signed_certificate_timestamp_ids);
656 705
657 security_info = SerializeSecurityInfo( 706 security_info = SerializeSecurityInfo(
658 cert_id, ssl_info.cert_status, ssl_info.security_bits, 707 cert_id, ssl_info.cert_status, ssl_info.security_bits,
659 ssl_info.connection_status, signed_certificate_timestamp_ids); 708 ssl_info.connection_status, signed_certificate_timestamp_ids);
660 } 709 }
661 710
662 bool defer = false; 711 bool defer = false;
663 handler_->OnResponseCompleted(request_->status(), security_info, &defer); 712 {
713 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
714 tracked_objects::ScopedTracker tracking_profile(
715 FROM_HERE_WITH_EXPLICIT_FUNCTION(
716 "423948 ResourceLoader::ResponseCompleted"));
717
718 handler_->OnResponseCompleted(request_->status(), security_info, &defer);
719 }
664 if (defer) { 720 if (defer) {
665 // The handler is not ready to die yet. We will call DidFinishLoading when 721 // The handler is not ready to die yet. We will call DidFinishLoading when
666 // we resume. 722 // we resume.
667 deferred_stage_ = DEFERRED_FINISH; 723 deferred_stage_ = DEFERRED_FINISH;
668 } else { 724 } else {
669 // This will result in our destruction. 725 // This will result in our destruction.
670 CallDidFinishLoading(); 726 CallDidFinishLoading();
671 } 727 }
672 } 728 }
673 729
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 763 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
708 } 764 }
709 } 765 }
710 766
711 void ResourceLoader::ContinueWithCertificate(net::X509Certificate* cert) { 767 void ResourceLoader::ContinueWithCertificate(net::X509Certificate* cert) {
712 ssl_client_auth_handler_.reset(); 768 ssl_client_auth_handler_.reset();
713 request_->ContinueWithCertificate(cert); 769 request_->ContinueWithCertificate(cert);
714 } 770 }
715 771
716 } // namespace content 772 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/power_save_block_resource_throttle.cc ('k') | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698