OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/renderer_host/download_throttling_resource_handler.h" | 5 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/download/download_util.h" | 8 #include "chrome/browser/download/download_util.h" |
9 #include "chrome/browser/renderer_host/download_resource_handler.h" | 9 #include "chrome/browser/renderer_host/download_resource_handler.h" |
10 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 void DownloadThrottlingResourceHandler::CancelDownload() { | 167 void DownloadThrottlingResourceHandler::CancelDownload() { |
168 if (!request_closed_) | 168 if (!request_closed_) |
169 host_->CancelRequest(render_process_host_id_, request_id_, false); | 169 host_->CancelRequest(render_process_host_id_, request_id_, false); |
170 Release(); // Release the additional reference from constructor. | 170 Release(); // Release the additional reference from constructor. |
171 } | 171 } |
172 | 172 |
173 void DownloadThrottlingResourceHandler::ContinueDownload() { | 173 void DownloadThrottlingResourceHandler::ContinueDownload() { |
174 DCHECK(!download_handler_.get()); | 174 DCHECK(!download_handler_.get()); |
175 if (!request_closed_) { | 175 if (!request_closed_) { |
176 download_handler_ = | 176 download_handler_ = new DownloadResourceHandler( |
177 new DownloadResourceHandler(host_, | 177 host_, |
178 render_process_host_id_, | 178 render_process_host_id_, |
179 render_view_id_, | 179 render_view_id_, |
180 request_id_, | 180 request_id_, |
181 url_, | 181 url_, |
182 host_->download_file_manager(), | 182 host_->download_file_manager(), |
183 request_, | 183 request_, |
184 false, | 184 false, |
185 DownloadSaveInfo()); | 185 DownloadResourceHandler::OnResponseStartedCallback(), |
| 186 DownloadResourceHandler::OnUnstartableCallback(), |
| 187 DownloadSaveInfo()); |
186 if (response_.get()) | 188 if (response_.get()) |
187 download_handler_->OnResponseStarted(request_id_, response_.get()); | 189 download_handler_->OnResponseStarted(request_id_, response_.get()); |
188 | 190 |
189 if (tmp_buffer_length_) | 191 if (tmp_buffer_length_) |
190 CopyTmpBufferToDownloadHandler(); | 192 CopyTmpBufferToDownloadHandler(); |
191 | 193 |
192 // And let the request continue. | 194 // And let the request continue. |
193 host_->PauseRequest(render_process_host_id_, request_id_, false); | 195 host_->PauseRequest(render_process_host_id_, request_id_, false); |
194 } | 196 } |
195 Release(); // Release the addtional reference from constructor. | 197 Release(); // Release the addtional reference from constructor. |
196 } | 198 } |
197 | 199 |
198 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { | 200 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { |
199 // Copy over the tmp buffer. | 201 // Copy over the tmp buffer. |
200 net::IOBuffer* buffer; | 202 net::IOBuffer* buffer; |
201 int buf_size; | 203 int buf_size; |
202 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 204 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
203 tmp_buffer_length_)) { | 205 tmp_buffer_length_)) { |
204 CHECK(buf_size >= tmp_buffer_length_); | 206 CHECK(buf_size >= tmp_buffer_length_); |
205 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 207 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
206 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 208 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
207 } | 209 } |
208 tmp_buffer_length_ = 0; | 210 tmp_buffer_length_ = 0; |
209 tmp_buffer_ = NULL; | 211 tmp_buffer_ = NULL; |
210 } | 212 } |
OLD | NEW |