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/profiles/profile_io_data.h" |
9 #include "chrome/browser/renderer_host/download_resource_handler.h" | 10 #include "chrome/browser/renderer_host/download_resource_handler.h" |
10 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 11 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 12 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
11 #include "content/common/resource_response.h" | 13 #include "content/common/resource_response.h" |
12 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
13 #include "net/base/mime_sniffer.h" | 15 #include "net/base/mime_sniffer.h" |
14 | 16 |
15 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( | 17 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( |
16 ResourceDispatcherHost* host, | 18 ResourceDispatcherHost* host, |
17 net::URLRequest* request, | 19 net::URLRequest* request, |
18 const GURL& url, | 20 const GURL& url, |
19 int render_process_host_id, | 21 int render_process_host_id, |
20 int render_view_id, | 22 int render_view_id, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 168 |
167 void DownloadThrottlingResourceHandler::CancelDownload() { | 169 void DownloadThrottlingResourceHandler::CancelDownload() { |
168 if (!request_closed_) | 170 if (!request_closed_) |
169 host_->CancelRequest(render_process_host_id_, request_id_, false); | 171 host_->CancelRequest(render_process_host_id_, request_id_, false); |
170 Release(); // Release the additional reference from constructor. | 172 Release(); // Release the additional reference from constructor. |
171 } | 173 } |
172 | 174 |
173 void DownloadThrottlingResourceHandler::ContinueDownload() { | 175 void DownloadThrottlingResourceHandler::ContinueDownload() { |
174 DCHECK(!download_handler_.get()); | 176 DCHECK(!download_handler_.get()); |
175 if (!request_closed_) { | 177 if (!request_closed_) { |
| 178 ResourceDispatcherHostRequestInfo* info = |
| 179 ResourceDispatcherHost::InfoForRequest(request_); |
| 180 ProfileIOData* profile_io_data = reinterpret_cast<ProfileIOData*>( |
| 181 info->context()->GetUserData(NULL)); |
| 182 const DownloadManager::GetNextIdThunkType& get_next_id = |
| 183 profile_io_data->next_download_id_thunk(); |
176 download_handler_ = | 184 download_handler_ = |
177 new DownloadResourceHandler(host_, | 185 new DownloadResourceHandler(host_, |
178 render_process_host_id_, | 186 render_process_host_id_, |
179 render_view_id_, | 187 render_view_id_, |
180 request_id_, | 188 request_id_, |
181 url_, | 189 url_, |
| 190 get_next_id, |
182 host_->download_file_manager(), | 191 host_->download_file_manager(), |
183 request_, | 192 request_, |
184 false, | 193 false, |
185 DownloadSaveInfo()); | 194 DownloadSaveInfo()); |
186 if (response_.get()) | 195 if (response_.get()) |
187 download_handler_->OnResponseStarted(request_id_, response_.get()); | 196 download_handler_->OnResponseStarted(request_id_, response_.get()); |
188 | 197 |
189 if (tmp_buffer_length_) | 198 if (tmp_buffer_length_) |
190 CopyTmpBufferToDownloadHandler(); | 199 CopyTmpBufferToDownloadHandler(); |
191 | 200 |
192 // And let the request continue. | 201 // And let the request continue. |
193 host_->PauseRequest(render_process_host_id_, request_id_, false); | 202 host_->PauseRequest(render_process_host_id_, request_id_, false); |
194 } | 203 } |
195 Release(); // Release the addtional reference from constructor. | 204 Release(); // Release the addtional reference from constructor. |
196 } | 205 } |
197 | 206 |
198 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { | 207 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { |
199 // Copy over the tmp buffer. | 208 // Copy over the tmp buffer. |
200 net::IOBuffer* buffer; | 209 net::IOBuffer* buffer; |
201 int buf_size; | 210 int buf_size; |
202 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, | 211 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, |
203 tmp_buffer_length_)) { | 212 tmp_buffer_length_)) { |
204 CHECK(buf_size >= tmp_buffer_length_); | 213 CHECK(buf_size >= tmp_buffer_length_); |
205 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); | 214 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); |
206 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); | 215 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); |
207 } | 216 } |
208 tmp_buffer_length_ = 0; | 217 tmp_buffer_length_ = 0; |
209 tmp_buffer_ = NULL; | 218 tmp_buffer_ = NULL; |
210 } | 219 } |
OLD | NEW |