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

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

Issue 1130343006: Don't share ResourceDispatcherHostImpl's timer for reporting upload progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@safari-backend
Patch Set: Created 5 years, 7 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 (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/profiler/scoped_tracker.h"
(...skipping 22 matching lines...) Expand all
33 #include "net/ssl/client_cert_store.h" 33 #include "net/ssl/client_cert_store.h"
34 #include "net/url_request/redirect_info.h" 34 #include "net/url_request/redirect_info.h"
35 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
36 36
37 using base::TimeDelta; 37 using base::TimeDelta;
38 using base::TimeTicks; 38 using base::TimeTicks;
39 39
40 namespace content { 40 namespace content {
41 namespace { 41 namespace {
42 42
43 // The interval for calls to ResourceLoader::ReportUploadProgress.
44 const int kUploadProgressIntervalMsec = 100;
45
43 void PopulateResourceResponse(ResourceRequestInfoImpl* info, 46 void PopulateResourceResponse(ResourceRequestInfoImpl* info,
44 net::URLRequest* request, 47 net::URLRequest* request,
45 ResourceResponse* response) { 48 ResourceResponse* response) {
46 response->head.request_time = request->request_time(); 49 response->head.request_time = request->request_time();
47 response->head.response_time = request->response_time(); 50 response->head.response_time = request->response_time();
48 response->head.headers = request->response_headers(); 51 response->head.headers = request->response_headers();
49 request->GetCharset(&response->head.charset); 52 request->GetCharset(&response->head.charset);
50 response->head.content_length = request->GetExpectedContentSize(); 53 response->head.content_length = request->GetExpectedContentSize();
51 request->GetMimeType(&response->head.mime_type); 54 request->GetMimeType(&response->head.mime_type);
52 net::HttpResponseInfo response_info = request->response_info(); 55 net::HttpResponseInfo response_info = request->response_info();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void ResourceLoader::CancelWithError(int error_code) { 140 void ResourceLoader::CancelWithError(int error_code) {
138 CancelRequestInternal(error_code, false); 141 CancelRequestInternal(error_code, false);
139 } 142 }
140 143
141 void ResourceLoader::ReportUploadProgress() { 144 void ResourceLoader::ReportUploadProgress() {
142 if (waiting_for_upload_progress_ack_) 145 if (waiting_for_upload_progress_ack_)
143 return; // Send one progress event at a time. 146 return; // Send one progress event at a time.
144 147
145 net::UploadProgress progress = request_->GetUploadProgress(); 148 net::UploadProgress progress = request_->GetUploadProgress();
146 if (!progress.size()) 149 if (!progress.size())
147 return; // Nothing to upload. 150 return; // Nothing to upload.
Andre 2015/05/20 21:05:12 Do we send upload progress messages for chunked up
mmenke 2015/05/20 21:07:58 Ahh, very good point! ResourceLoader isn't normal
148 151
149 if (progress.position() == last_upload_position_) 152 if (progress.position() == last_upload_position_)
150 return; // No progress made since last time. 153 return; // No progress made since last time.
151 154
152 const uint64 kHalfPercentIncrements = 200; 155 const uint64 kHalfPercentIncrements = 200;
153 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); 156 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000);
154 157
155 uint64 amt_since_last = progress.position() - last_upload_position_; 158 uint64 amt_since_last = progress.position() - last_upload_position_;
156 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; 159 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_;
157 160
158 bool is_finished = (progress.size() == progress.position()); 161 bool is_finished = (progress.size() == progress.position());
159 bool enough_new_progress = 162 bool enough_new_progress =
160 (amt_since_last > (progress.size() / kHalfPercentIncrements)); 163 (amt_since_last > (progress.size() / kHalfPercentIncrements));
161 bool too_much_time_passed = time_since_last > kOneSecond; 164 bool too_much_time_passed = time_since_last > kOneSecond;
162 165
163 if (is_finished || enough_new_progress || too_much_time_passed) { 166 if (is_finished || enough_new_progress || too_much_time_passed) {
164 ResourceRequestInfoImpl* info = GetRequestInfo(); 167 handler_->OnUploadProgress(progress.position(), progress.size());
165 if (info->is_upload_progress_enabled()) { 168 waiting_for_upload_progress_ack_ = true;
166 handler_->OnUploadProgress(progress.position(), progress.size());
167 waiting_for_upload_progress_ack_ = true;
168 }
169 last_upload_ticks_ = TimeTicks::Now(); 169 last_upload_ticks_ = TimeTicks::Now();
170 last_upload_position_ = progress.position(); 170 last_upload_position_ = progress.position();
171 } 171 }
172 } 172 }
173 173
174 void ResourceLoader::MarkAsTransferring() { 174 void ResourceLoader::MarkAsTransferring() {
175 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType())) 175 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType()))
176 << "Can only transfer for navigations"; 176 << "Can only transfer for navigations";
177 is_transferring_ = true; 177 is_transferring_ = true;
178 178
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } else if (*defer) { 327 } else if (*defer) {
328 deferred_stage_ = DEFERRED_NETWORK_START; 328 deferred_stage_ = DEFERRED_NETWORK_START;
329 } 329 }
330 } 330 }
331 331
332 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { 332 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) {
333 DCHECK_EQ(request_.get(), unused); 333 DCHECK_EQ(request_.get(), unused);
334 334
335 VLOG(1) << "OnResponseStarted: " << request_->url().spec(); 335 VLOG(1) << "OnResponseStarted: " << request_->url().spec();
336 336
337 progress_timer_.Stop();
338
337 // The CanLoadPage check should take place after any server redirects have 339 // The CanLoadPage check should take place after any server redirects have
338 // finished, at the point in time that we know a page will commit in the 340 // finished, at the point in time that we know a page will commit in the
339 // renderer process. 341 // renderer process.
340 ResourceRequestInfoImpl* info = GetRequestInfo(); 342 ResourceRequestInfoImpl* info = GetRequestInfo();
341 ChildProcessSecurityPolicyImpl* policy = 343 ChildProcessSecurityPolicyImpl* policy =
342 ChildProcessSecurityPolicyImpl::GetInstance(); 344 ChildProcessSecurityPolicyImpl::GetInstance();
343 if (!policy->CanLoadPage(info->GetChildID(), 345 if (!policy->CanLoadPage(info->GetChildID(),
344 request_->url(), 346 request_->url(),
345 info->GetResourceType())) { 347 info->GetResourceType())) {
346 Cancel(); 348 Cancel();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void ResourceLoader::StartRequestInternal() { 491 void ResourceLoader::StartRequestInternal() {
490 DCHECK(!request_->is_pending()); 492 DCHECK(!request_->is_pending());
491 493
492 if (!request_->status().is_success()) { 494 if (!request_->status().is_success()) {
493 return; 495 return;
494 } 496 }
495 497
496 request_->Start(); 498 request_->Start();
497 499
498 delegate_->DidStartRequest(this); 500 delegate_->DidStartRequest(this);
501
502 if (GetRequestInfo()->is_upload_progress_enabled()) {
503 progress_timer_.Start(
504 FROM_HERE,
505 base::TimeDelta::FromMilliseconds(kUploadProgressIntervalMsec),
506 this,
507 &ResourceLoader::ReportUploadProgress);
508 }
499 } 509 }
500 510
501 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { 511 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) {
502 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); 512 VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
503 513
504 ResourceRequestInfoImpl* info = GetRequestInfo(); 514 ResourceRequestInfoImpl* info = GetRequestInfo();
505 515
506 // WebKit will send us a cancel for downloads since it no longer handles 516 // WebKit will send us a cancel for downloads since it no longer handles
507 // them. In this case, ignore the cancel since we handle downloads in the 517 // them. In this case, ignore the cancel since we handle downloads in the
508 // browser. 518 // browser.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 case net::URLRequestStatus::FAILED: 763 case net::URLRequestStatus::FAILED:
754 status = STATUS_UNDEFINED; 764 status = STATUS_UNDEFINED;
755 break; 765 break;
756 } 766 }
757 767
758 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 768 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
759 } 769 }
760 } 770 }
761 771
762 } // namespace content 772 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698