| 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::OnStartedCallback(), |
| 186 DownloadSaveInfo()); |
| 186 if (response_.get()) | 187 if (response_.get()) |
| 187 download_handler_->OnResponseStarted(request_id_, response_.get()); | 188 download_handler_->OnResponseStarted(request_id_, response_.get()); |
| 188 | 189 |
| 189 if (tmp_buffer_length_) | 190 if (tmp_buffer_length_) |
| 190 CopyTmpBufferToDownloadHandler(); | 191 CopyTmpBufferToDownloadHandler(); |
| 191 | 192 |
| 192 // And let the request continue. | 193 // And let the request continue. |
| 193 host_->PauseRequest(render_process_host_id_, request_id_, false); | 194 host_->PauseRequest(render_process_host_id_, request_id_, false); |
| 194 } | 195 } |
| 195 Release(); // Release the addtional reference from constructor. | 196 Release(); // Release the addtional reference from constructor. |
| 196 } | 197 } |
| 197 | 198 |
| 198 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { | 199 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { |
| 199 // Copy over the tmp buffer. | 200 // Copy over the tmp buffer. |
| 200 net::IOBuffer* buffer; | 201 net::IOBuffer* buffer; |
| 201 int buf_size; | 202 int buf_size; |
| 202 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 203 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
| 203 tmp_buffer_length_)) { | 204 tmp_buffer_length_)) { |
| 204 CHECK(buf_size >= tmp_buffer_length_); | 205 CHECK(buf_size >= tmp_buffer_length_); |
| 205 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 206 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
| 206 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 207 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
| 207 } | 208 } |
| 208 tmp_buffer_length_ = 0; | 209 tmp_buffer_length_ = 0; |
| 209 tmp_buffer_ = NULL; | 210 tmp_buffer_ = NULL; |
| 210 } | 211 } |
| OLD | NEW |