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/renderer_host/resource_loader.h" | 5 #include "content/browser/renderer_host/resource_loader.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
10 #include "content/browser/renderer_host/doomed_resource_handler.h" | 10 #include "content/browser/renderer_host/doomed_resource_handler.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void ResourceLoader::CancelRequest(bool from_renderer) { | 100 void ResourceLoader::CancelRequest(bool from_renderer) { |
101 CancelRequestInternal(net::ERR_ABORTED, from_renderer); | 101 CancelRequestInternal(net::ERR_ABORTED, from_renderer); |
102 } | 102 } |
103 | 103 |
104 void ResourceLoader::ReportUploadProgress() { | 104 void ResourceLoader::ReportUploadProgress() { |
105 ResourceRequestInfoImpl* info = GetRequestInfo(); | 105 ResourceRequestInfoImpl* info = GetRequestInfo(); |
106 | 106 |
107 if (waiting_for_upload_progress_ack_) | 107 if (waiting_for_upload_progress_ack_) |
108 return; // Send one progress event at a time. | 108 return; // Send one progress event at a time. |
109 | 109 |
110 uint64 size = info->GetUploadSize(); | 110 net::UploadProgress progress = request_->GetUploadProgress(); |
111 if (!size) | 111 if (!progress.size()) |
112 return; // Nothing to upload. | 112 return; // Nothing to upload. |
113 | 113 |
114 uint64 position = request_->GetUploadProgress(); | 114 if (progress.position() == last_upload_position_) |
115 if (position == last_upload_position_) | |
116 return; // No progress made since last time. | 115 return; // No progress made since last time. |
117 | 116 |
118 const uint64 kHalfPercentIncrements = 200; | 117 const uint64 kHalfPercentIncrements = 200; |
119 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); | 118 const TimeDelta kOneSecond = TimeDelta::FromMilliseconds(1000); |
120 | 119 |
121 uint64 amt_since_last = position - last_upload_position_; | 120 uint64 amt_since_last = progress.position() - last_upload_position_; |
122 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; | 121 TimeDelta time_since_last = TimeTicks::Now() - last_upload_ticks_; |
123 | 122 |
124 bool is_finished = (size == position); | 123 bool is_finished = (progress.size() == progress.position()); |
125 bool enough_new_progress = (amt_since_last > (size / kHalfPercentIncrements)); | 124 bool enough_new_progress = |
| 125 (amt_since_last > (progress.size() / kHalfPercentIncrements)); |
126 bool too_much_time_passed = time_since_last > kOneSecond; | 126 bool too_much_time_passed = time_since_last > kOneSecond; |
127 | 127 |
128 if (is_finished || enough_new_progress || too_much_time_passed) { | 128 if (is_finished || enough_new_progress || too_much_time_passed) { |
129 if (request_->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { | 129 if (request_->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { |
130 handler_->OnUploadProgress(info->GetRequestID(), position, size); | 130 handler_->OnUploadProgress( |
| 131 info->GetRequestID(), progress.position(), progress.size()); |
131 waiting_for_upload_progress_ack_ = true; | 132 waiting_for_upload_progress_ack_ = true; |
132 } | 133 } |
133 last_upload_ticks_ = TimeTicks::Now(); | 134 last_upload_ticks_ = TimeTicks::Now(); |
134 last_upload_position_ = position; | 135 last_upload_position_ = progress.position(); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 void ResourceLoader::MarkAsTransferring() { | 139 void ResourceLoader::MarkAsTransferring() { |
139 is_transferring_ = true; | 140 is_transferring_ = true; |
140 | 141 |
141 // When an URLRequest is transferred to a new RenderViewHost, its | 142 // When an URLRequest is transferred to a new RenderViewHost, its |
142 // ResourceHandler should not receive any notifications because it may depend | 143 // ResourceHandler should not receive any notifications because it may depend |
143 // on the state of the old RVH. We set a ResourceHandler that only allows | 144 // on the state of the old RVH. We set a ResourceHandler that only allows |
144 // canceling requests, because on shutdown of the RDH all pending requests | 145 // canceling requests, because on shutdown of the RDH all pending requests |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // we resume. | 563 // we resume. |
563 deferred_stage_ = DEFERRED_FINISH; | 564 deferred_stage_ = DEFERRED_FINISH; |
564 } | 565 } |
565 } | 566 } |
566 | 567 |
567 void ResourceLoader::CallDidFinishLoading() { | 568 void ResourceLoader::CallDidFinishLoading() { |
568 delegate_->DidFinishLoading(this); | 569 delegate_->DidFinishLoading(this); |
569 } | 570 } |
570 | 571 |
571 } // namespace content | 572 } // namespace content |
OLD | NEW |