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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
| 145 DCHECK(GetRequestInfo()->is_upload_progress_enabled()); |
| 146 |
142 if (waiting_for_upload_progress_ack_) | 147 if (waiting_for_upload_progress_ack_) |
143 return; // Send one progress event at a time. | 148 return; // Send one progress event at a time. |
144 | 149 |
145 net::UploadProgress progress = request_->GetUploadProgress(); | 150 net::UploadProgress progress = request_->GetUploadProgress(); |
146 if (!progress.size()) | 151 if (!progress.size()) |
147 return; // Nothing to upload. | 152 return; // Nothing to upload. |
148 | 153 |
149 if (progress.position() == last_upload_position_) | 154 if (progress.position() == last_upload_position_) |
150 return; // No progress made since last time. | 155 return; // No progress made since last time. |
151 | 156 |
152 const uint64 kHalfPercentIncrements = 200; | 157 const uint64 kHalfPercentIncrements = 200; |
153 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); | 158 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); |
154 | 159 |
155 uint64 amt_since_last = progress.position() - last_upload_position_; | 160 uint64 amt_since_last = progress.position() - last_upload_position_; |
156 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; | 161 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; |
157 | 162 |
158 bool is_finished = (progress.size() == progress.position()); | 163 bool is_finished = (progress.size() == progress.position()); |
159 bool enough_new_progress = | 164 bool enough_new_progress = |
160 (amt_since_last > (progress.size() / kHalfPercentIncrements)); | 165 (amt_since_last > (progress.size() / kHalfPercentIncrements)); |
161 bool too_much_time_passed = time_since_last > kOneSecond; | 166 bool too_much_time_passed = time_since_last > kOneSecond; |
162 | 167 |
163 if (is_finished || enough_new_progress || too_much_time_passed) { | 168 if (is_finished || enough_new_progress || too_much_time_passed) { |
164 ResourceRequestInfoImpl* info = GetRequestInfo(); | 169 handler_->OnUploadProgress(progress.position(), progress.size()); |
165 if (info->is_upload_progress_enabled()) { | 170 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(); | 171 last_upload_ticks_ = TimeTicks::Now(); |
170 last_upload_position_ = progress.position(); | 172 last_upload_position_ = progress.position(); |
171 } | 173 } |
172 } | 174 } |
173 | 175 |
174 void ResourceLoader::MarkAsTransferring() { | 176 void ResourceLoader::MarkAsTransferring() { |
175 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType())) | 177 CHECK(IsResourceTypeFrame(GetRequestInfo()->GetResourceType())) |
176 << "Can only transfer for navigations"; | 178 << "Can only transfer for navigations"; |
177 is_transferring_ = true; | 179 is_transferring_ = true; |
178 | 180 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } else if (*defer) { | 329 } else if (*defer) { |
328 deferred_stage_ = DEFERRED_NETWORK_START; | 330 deferred_stage_ = DEFERRED_NETWORK_START; |
329 } | 331 } |
330 } | 332 } |
331 | 333 |
332 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { | 334 void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { |
333 DCHECK_EQ(request_.get(), unused); | 335 DCHECK_EQ(request_.get(), unused); |
334 | 336 |
335 VLOG(1) << "OnResponseStarted: " << request_->url().spec(); | 337 VLOG(1) << "OnResponseStarted: " << request_->url().spec(); |
336 | 338 |
| 339 progress_timer_.Stop(); |
| 340 |
337 // The CanLoadPage check should take place after any server redirects have | 341 // 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 | 342 // finished, at the point in time that we know a page will commit in the |
339 // renderer process. | 343 // renderer process. |
340 ResourceRequestInfoImpl* info = GetRequestInfo(); | 344 ResourceRequestInfoImpl* info = GetRequestInfo(); |
341 ChildProcessSecurityPolicyImpl* policy = | 345 ChildProcessSecurityPolicyImpl* policy = |
342 ChildProcessSecurityPolicyImpl::GetInstance(); | 346 ChildProcessSecurityPolicyImpl::GetInstance(); |
343 if (!policy->CanLoadPage(info->GetChildID(), | 347 if (!policy->CanLoadPage(info->GetChildID(), |
344 request_->url(), | 348 request_->url(), |
345 info->GetResourceType())) { | 349 info->GetResourceType())) { |
346 Cancel(); | 350 Cancel(); |
347 return; | 351 return; |
348 } | 352 } |
349 | 353 |
350 if (!request_->status().is_success()) { | 354 if (!request_->status().is_success()) { |
351 ResponseCompleted(); | 355 ResponseCompleted(); |
352 return; | 356 return; |
353 } | 357 } |
354 | 358 |
355 // We want to send a final upload progress message prior to sending the | 359 // 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 | 360 // response complete message even if we're waiting for an ack to to a |
357 // previous upload progress message. | 361 // previous upload progress message. |
358 waiting_for_upload_progress_ack_ = false; | 362 if (info->is_upload_progress_enabled()) { |
359 ReportUploadProgress(); | 363 waiting_for_upload_progress_ack_ = false; |
| 364 ReportUploadProgress(); |
| 365 } |
360 | 366 |
361 CompleteResponseStarted(); | 367 CompleteResponseStarted(); |
362 | 368 |
363 if (is_deferred()) | 369 if (is_deferred()) |
364 return; | 370 return; |
365 | 371 |
366 if (request_->status().is_success()) | 372 if (request_->status().is_success()) |
367 StartReading(false); // Read the first chunk. | 373 StartReading(false); // Read the first chunk. |
368 else | 374 else |
369 ResponseCompleted(); | 375 ResponseCompleted(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 void ResourceLoader::StartRequestInternal() { | 495 void ResourceLoader::StartRequestInternal() { |
490 DCHECK(!request_->is_pending()); | 496 DCHECK(!request_->is_pending()); |
491 | 497 |
492 if (!request_->status().is_success()) { | 498 if (!request_->status().is_success()) { |
493 return; | 499 return; |
494 } | 500 } |
495 | 501 |
496 request_->Start(); | 502 request_->Start(); |
497 | 503 |
498 delegate_->DidStartRequest(this); | 504 delegate_->DidStartRequest(this); |
| 505 |
| 506 if (GetRequestInfo()->is_upload_progress_enabled() && |
| 507 request_->has_upload()) { |
| 508 progress_timer_.Start( |
| 509 FROM_HERE, |
| 510 base::TimeDelta::FromMilliseconds(kUploadProgressIntervalMsec), |
| 511 this, |
| 512 &ResourceLoader::ReportUploadProgress); |
| 513 } |
499 } | 514 } |
500 | 515 |
501 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { | 516 void ResourceLoader::CancelRequestInternal(int error, bool from_renderer) { |
502 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); | 517 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); |
503 | 518 |
504 ResourceRequestInfoImpl* info = GetRequestInfo(); | 519 ResourceRequestInfoImpl* info = GetRequestInfo(); |
505 | 520 |
506 // WebKit will send us a cancel for downloads since it no longer handles | 521 // 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 | 522 // them. In this case, ignore the cancel since we handle downloads in the |
508 // browser. | 523 // browser. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 case net::URLRequestStatus::FAILED: | 768 case net::URLRequestStatus::FAILED: |
754 status = STATUS_UNDEFINED; | 769 status = STATUS_UNDEFINED; |
755 break; | 770 break; |
756 } | 771 } |
757 | 772 |
758 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 773 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
759 } | 774 } |
760 } | 775 } |
761 | 776 |
762 } // namespace content | 777 } // namespace content |
OLD | NEW |