| 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_file_manager.h" | 5 #include "content/browser/download/download_file_manager.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "content/browser/download/base_file.h" | 15 #include "content/browser/download/base_file.h" |
| 16 #include "content/browser/download/download_buffer.h" | 16 #include "content/browser/download/download_buffer.h" |
| 17 #include "content/browser/download/download_create_info.h" | 17 #include "content/browser/download/download_create_info.h" |
| 18 #include "content/browser/download/download_file_impl.h" | 18 #include "content/browser/download/download_file_impl.h" |
| 19 #include "content/browser/download/download_interrupt_reasons_impl.h" |
| 19 #include "content/browser/download/download_request_handle.h" | 20 #include "content/browser/download/download_request_handle.h" |
| 20 #include "content/browser/download/download_stats.h" | 21 #include "content/browser/download/download_stats.h" |
| 21 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 22 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 22 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/download_manager.h" | 25 #include "content/public/browser/download_manager.h" |
| 25 #include "content/public/browser/download_manager_delegate.h" | 26 #include "content/public/browser/download_manager_delegate.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/io_buffer.h" | 28 #include "net/base/io_buffer.h" |
| 28 | 29 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Error: Handle via download manager/item. | 109 // Error: Handle via download manager/item. |
| 109 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
| 110 BrowserThread::UI, | 111 BrowserThread::UI, |
| 111 FROM_HERE, | 112 FROM_HERE, |
| 112 base::Bind( | 113 base::Bind( |
| 113 &DownloadManager::OnDownloadInterrupted, | 114 &DownloadManager::OnDownloadInterrupted, |
| 114 download_manager, | 115 download_manager, |
| 115 info->download_id.local(), | 116 info->download_id.local(), |
| 116 0, | 117 0, |
| 117 "", | 118 "", |
| 118 ConvertNetErrorToInterruptReason(init_result, | 119 content::ConvertNetErrorToInterruptReason( |
| 119 DOWNLOAD_INTERRUPT_FROM_DISK))); | 120 init_result, content::DOWNLOAD_INTERRUPT_FROM_DISK))); |
| 120 } else { | 121 } else { |
| 121 DCHECK(GetDownloadFile(info->download_id) == NULL); | 122 DCHECK(GetDownloadFile(info->download_id) == NULL); |
| 122 downloads_[info->download_id] = download_file.release(); | 123 downloads_[info->download_id] = download_file.release(); |
| 123 | 124 |
| 124 // The file is now ready, we can un-pause the request and start saving data. | 125 // The file is now ready, we can un-pause the request and start saving data. |
| 125 request_handle.ResumeRequest(); | 126 request_handle.ResumeRequest(); |
| 126 | 127 |
| 127 StartUpdateTimer(); | 128 StartUpdateTimer(); |
| 128 } | 129 } |
| 129 | 130 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 download_file = NULL; // Was deleted in |CancelDownload|. | 233 download_file = NULL; // Was deleted in |CancelDownload|. |
| 233 | 234 |
| 234 if (download_manager) { | 235 if (download_manager) { |
| 235 BrowserThread::PostTask( | 236 BrowserThread::PostTask( |
| 236 BrowserThread::UI, FROM_HERE, | 237 BrowserThread::UI, FROM_HERE, |
| 237 base::Bind(&DownloadManager::OnDownloadInterrupted, | 238 base::Bind(&DownloadManager::OnDownloadInterrupted, |
| 238 download_manager, | 239 download_manager, |
| 239 global_id.local(), | 240 global_id.local(), |
| 240 bytes_downloaded, | 241 bytes_downloaded, |
| 241 hash_state, | 242 hash_state, |
| 242 ConvertNetErrorToInterruptReason( | 243 content::ConvertNetErrorToInterruptReason( |
| 243 write_result, | 244 write_result, |
| 244 DOWNLOAD_INTERRUPT_FROM_DISK))); | 245 content::DOWNLOAD_INTERRUPT_FROM_DISK))); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 data->Release(); | 249 data->Release(); |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 252 void DownloadFileManager::OnResponseCompleted( | 253 void DownloadFileManager::OnResponseCompleted( |
| 253 DownloadId global_id, | 254 DownloadId global_id, |
| 254 InterruptReason reason, | 255 content::DownloadInterruptReason reason, |
| 255 const std::string& security_info) { | 256 const std::string& security_info) { |
| 256 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id | 257 VLOG(20) << __FUNCTION__ << "()" << " id = " << global_id |
| 257 << " reason = " << InterruptReasonDebugString(reason) | 258 << " reason = " << InterruptReasonDebugString(reason) |
| 258 << " security_info = \"" << security_info << "\""; | 259 << " security_info = \"" << security_info << "\""; |
| 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 260 DownloadFile* download_file = GetDownloadFile(global_id); | 261 DownloadFile* download_file = GetDownloadFile(global_id); |
| 261 if (!download_file) | 262 if (!download_file) |
| 262 return; | 263 return; |
| 263 | 264 |
| 264 download_file->Finish(); | 265 download_file->Finish(); |
| 265 | 266 |
| 266 DownloadManager* download_manager = download_file->GetDownloadManager(); | 267 DownloadManager* download_manager = download_file->GetDownloadManager(); |
| 267 if (!download_manager) { | 268 if (!download_manager) { |
| 268 CancelDownload(global_id); | 269 CancelDownload(global_id); |
| 269 return; | 270 return; |
| 270 } | 271 } |
| 271 | 272 |
| 272 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) { | 273 if (reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 273 std::string hash; | 274 std::string hash; |
| 274 if (!download_file->GetHash(&hash) || | 275 if (!download_file->GetHash(&hash) || |
| 275 BaseFile::IsEmptyHash(hash)) { | 276 BaseFile::IsEmptyHash(hash)) { |
| 276 hash.clear(); | 277 hash.clear(); |
| 277 } | 278 } |
| 278 | 279 |
| 279 BrowserThread::PostTask( | 280 BrowserThread::PostTask( |
| 280 BrowserThread::UI, FROM_HERE, | 281 BrowserThread::UI, FROM_HERE, |
| 281 base::Bind(&DownloadManager::OnResponseCompleted, | 282 base::Bind(&DownloadManager::OnResponseCompleted, |
| 282 download_manager, global_id.local(), | 283 download_manager, global_id.local(), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 return; | 466 return; |
| 466 } | 467 } |
| 467 | 468 |
| 468 BrowserThread::PostTask( | 469 BrowserThread::PostTask( |
| 469 BrowserThread::UI, FROM_HERE, | 470 BrowserThread::UI, FROM_HERE, |
| 470 base::Bind(&DownloadManager::OnDownloadInterrupted, | 471 base::Bind(&DownloadManager::OnDownloadInterrupted, |
| 471 download_manager, | 472 download_manager, |
| 472 global_id.local(), | 473 global_id.local(), |
| 473 download_file->BytesSoFar(), | 474 download_file->BytesSoFar(), |
| 474 download_file->GetHashState(), | 475 download_file->GetHashState(), |
| 475 ConvertNetErrorToInterruptReason( | 476 content::ConvertNetErrorToInterruptReason( |
| 476 rename_error, | 477 rename_error, |
| 477 DOWNLOAD_INTERRUPT_FROM_DISK))); | 478 content::DOWNLOAD_INTERRUPT_FROM_DISK))); |
| 478 } | 479 } |
| 479 | 480 |
| 480 void DownloadFileManager::EraseDownload(DownloadId global_id) { | 481 void DownloadFileManager::EraseDownload(DownloadId global_id) { |
| 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 482 | 483 |
| 483 if (!ContainsKey(downloads_, global_id)) | 484 if (!ContainsKey(downloads_, global_id)) |
| 484 return; | 485 return; |
| 485 | 486 |
| 486 DownloadFile* download_file = downloads_[global_id]; | 487 DownloadFile* download_file = downloads_[global_id]; |
| 487 | 488 |
| 488 VLOG(20) << " " << __FUNCTION__ << "()" | 489 VLOG(20) << " " << __FUNCTION__ << "()" |
| 489 << " id = " << global_id | 490 << " id = " << global_id |
| 490 << " download_file = " << download_file->DebugString(); | 491 << " download_file = " << download_file->DebugString(); |
| 491 | 492 |
| 492 downloads_.erase(global_id); | 493 downloads_.erase(global_id); |
| 493 | 494 |
| 494 delete download_file; | 495 delete download_file; |
| 495 | 496 |
| 496 if (downloads_.empty()) | 497 if (downloads_.empty()) |
| 497 StopUpdateTimer(); | 498 StopUpdateTimer(); |
| 498 } | 499 } |
| OLD | NEW |