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/download/download_resource_handler.h" | 5 #include "content/browser/download/download_resource_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (vector_size > kLoadsToWrite) | 243 if (vector_size > kLoadsToWrite) |
244 StartPauseTimer(); | 244 StartPauseTimer(); |
245 | 245 |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 bool DownloadResourceHandler::OnResponseCompleted( | 249 bool DownloadResourceHandler::OnResponseCompleted( |
250 int request_id, | 250 int request_id, |
251 const net::URLRequestStatus& status, | 251 const net::URLRequestStatus& status, |
252 const std::string& security_info) { | 252 const std::string& security_info) { |
| 253 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
| 254 << " request_id = " << request_id |
| 255 << " status.status() = " << status.status() |
| 256 << " status.error() = " << status.error(); |
253 if (download_id_.IsValid()) { | 257 if (download_id_.IsValid()) { |
254 OnResponseCompletedInternal(request_id, status, security_info); | 258 OnResponseCompletedInternal(request_id, status, security_info); |
255 } else { | 259 } else { |
256 // We got cancelled before the task which sets the id ran on the IO thread. | 260 // We got cancelled before the task which sets the id ran on the IO thread. |
257 // Wait for it. | 261 // Wait for it. |
258 BrowserThread::PostTaskAndReply( | 262 BrowserThread::PostTaskAndReply( |
259 BrowserThread::UI, FROM_HERE, | 263 BrowserThread::UI, FROM_HERE, |
260 base::Bind(&base::DoNothing), | 264 base::Bind(&base::DoNothing), |
261 base::Bind(&DownloadResourceHandler::OnResponseCompletedInternal, this, | 265 base::Bind(&DownloadResourceHandler::OnResponseCompletedInternal, this, |
262 request_id, status, security_info)); | 266 request_id, status, security_info)); |
263 } | 267 } |
264 return true; | 268 return true; |
265 } | 269 } |
266 | 270 |
267 void DownloadResourceHandler::OnResponseCompletedInternal( | 271 void DownloadResourceHandler::OnResponseCompletedInternal( |
268 int request_id, | 272 int request_id, |
269 const net::URLRequestStatus& status, | 273 const net::URLRequestStatus& status, |
270 const std::string& security_info) { | 274 const std::string& security_info) { |
271 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 275 // NOTE: |request_| may be a dangling pointer at this point. |
| 276 VLOG(20) << __FUNCTION__ << "()" |
272 << " request_id = " << request_id | 277 << " request_id = " << request_id |
273 << " status.status() = " << status.status() | 278 << " status.status() = " << status.status() |
274 << " status.error() = " << status.error(); | 279 << " status.error() = " << status.error(); |
275 net::Error error_code = net::OK; | 280 net::Error error_code = net::OK; |
276 if (status.status() == net::URLRequestStatus::FAILED) | 281 if (status.status() == net::URLRequestStatus::FAILED) |
277 error_code = static_cast<net::Error>(status.error()); // Normal case. | 282 error_code = static_cast<net::Error>(status.error()); // Normal case. |
278 // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild | 283 // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild |
279 // advertise a larger Content-Length than the amount of bytes in the message | 284 // advertise a larger Content-Length than the amount of bytes in the message |
280 // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1, | 285 // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1, |
281 // and Safari 5.0.4 - treat the download as complete in this case, so we | 286 // and Safari 5.0.4 - treat the download as complete in this case, so we |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 " }", | 429 " }", |
425 request_ ? | 430 request_ ? |
426 request_->url().spec().c_str() : | 431 request_->url().spec().c_str() : |
427 "<NULL request>", | 432 "<NULL request>", |
428 download_id_.local(), | 433 download_id_.local(), |
429 global_id_.child_id, | 434 global_id_.child_id, |
430 global_id_.request_id, | 435 global_id_.request_id, |
431 render_view_id_, | 436 render_view_id_, |
432 save_info_.file_path.value().c_str()); | 437 save_info_.file_path.value().c_str()); |
433 } | 438 } |
OLD | NEW |