OLD | NEW |
---|---|
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 Loading... | |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 void ResourceLoader::CancelAndIgnore() { | 134 void ResourceLoader::CancelAndIgnore() { |
132 ResourceRequestInfoImpl* info = GetRequestInfo(); | 135 ResourceRequestInfoImpl* info = GetRequestInfo(); |
133 info->set_was_ignored_by_handler(true); | 136 info->set_was_ignored_by_handler(true); |
134 CancelRequest(false); | 137 CancelRequest(false); |
135 } | 138 } |
136 | 139 |
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() { |
mmenke
2015/05/21 15:41:57
DCHECK(info->is_upload_progress_enabled());?
Andre
2015/05/21 20:59:31
Done.
| |
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. |
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 Loading... | |
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(); |
347 return; | 349 return; |
348 } | 350 } |
349 | 351 |
350 if (!request_->status().is_success()) { | 352 if (!request_->status().is_success()) { |
351 ResponseCompleted(); | 353 ResponseCompleted(); |
352 return; | 354 return; |
353 } | 355 } |
354 | 356 |
355 // We want to send a final upload progress message prior to sending the | 357 // We want to send a final upload progress message prior to sending the |
356 // response complete message even if we're waiting for an ack to to a | 358 // response complete message even if we're waiting for an ack to to a |
357 // previous upload progress message. | 359 // previous upload progress message. |
358 waiting_for_upload_progress_ack_ = false; | 360 if (info->is_upload_progress_enabled()) { |
Andre
2015/05/20 22:36:10
I think we need to add this check.
| |
359 ReportUploadProgress(); | 361 waiting_for_upload_progress_ack_ = false; |
362 ReportUploadProgress(); | |
363 } | |
360 | 364 |
361 CompleteResponseStarted(); | 365 CompleteResponseStarted(); |
362 | 366 |
363 if (is_deferred()) | 367 if (is_deferred()) |
364 return; | 368 return; |
365 | 369 |
366 if (request_->status().is_success()) | 370 if (request_->status().is_success()) |
367 StartReading(false); // Read the first chunk. | 371 StartReading(false); // Read the first chunk. |
368 else | 372 else |
369 ResponseCompleted(); | 373 ResponseCompleted(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 void ResourceLoader::StartRequestInternal() { | 493 void ResourceLoader::StartRequestInternal() { |
490 DCHECK(!request_->is_pending()); | 494 DCHECK(!request_->is_pending()); |
491 | 495 |
492 if (!request_->status().is_success()) { | 496 if (!request_->status().is_success()) { |
493 return; | 497 return; |
494 } | 498 } |
495 | 499 |
496 request_->Start(); | 500 request_->Start(); |
497 | 501 |
498 delegate_->DidStartRequest(this); | 502 delegate_->DidStartRequest(this); |
503 | |
504 if (GetRequestInfo()->is_upload_progress_enabled()) { | |
mmenke
2015/05/21 15:41:57
I'm paranoid. Maybe add "&& request_->get_upload(
Andre
2015/05/21 20:59:31
Done.
| |
505 progress_timer_.Start( | |
506 FROM_HERE, | |
507 base::TimeDelta::FromMilliseconds(kUploadProgressIntervalMsec), | |
508 this, | |
509 &ResourceLoader::ReportUploadProgress); | |
510 } | |
499 } | 511 } |
500 | 512 |
501 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { | 513 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { |
502 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); | 514 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); |
503 | 515 |
504 ResourceRequestInfoImpl* info = GetRequestInfo(); | 516 ResourceRequestInfoImpl* info = GetRequestInfo(); |
505 | 517 |
506 // WebKit will send us a cancel for downloads since it no longer handles | 518 // 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 | 519 // them. In this case, ignore the cancel since we handle downloads in the |
508 // browser. | 520 // browser. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 case net::URLRequestStatus::FAILED: | 765 case net::URLRequestStatus::FAILED: |
754 status = STATUS_UNDEFINED; | 766 status = STATUS_UNDEFINED; |
755 break; | 767 break; |
756 } | 768 } |
757 | 769 |
758 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 770 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
759 } | 771 } |
760 } | 772 } |
761 | 773 |
762 } // namespace content | 774 } // namespace content |
OLD | NEW |