| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/download/download_file_manager.h" | 5 #include "chrome/browser/download/download_file_manager.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/download/download_manager.h" | 14 #include "chrome/browser/download/download_manager.h" |
| 15 #include "chrome/browser/download/download_util.h" | 15 #include "chrome/browser/download/download_util.h" |
| 16 #include "chrome/browser/history/download_create_info.h" | 16 #include "chrome/browser/history/download_create_info.h" |
| 17 #include "chrome/browser/net/chrome_url_request_context.h" | 17 #include "chrome/browser/net/chrome_url_request_context.h" |
| 18 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 20 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 22 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 24 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 #include "chrome/common/win_safe_util.h" | 28 #include "chrome/common/win_safe_util.h" |
| 28 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 29 #include "chrome/browser/ui/cocoa/file_metadata.h" | 30 #include "chrome/browser/ui/cocoa/file_metadata.h" |
| 30 #endif | 31 #endif |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 BrowserThread::FILE, FROM_HERE, | 68 BrowserThread::FILE, FROM_HERE, |
| 68 NewRunnableMethod(this, &DownloadFileManager::OnShutdown)); | 69 NewRunnableMethod(this, &DownloadFileManager::OnShutdown)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void DownloadFileManager::OnShutdown() { | 72 void DownloadFileManager::OnShutdown() { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 73 StopUpdateTimer(); | 74 StopUpdateTimer(); |
| 74 STLDeleteValues(&downloads_); | 75 STLDeleteValues(&downloads_); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void DownloadFileManager::CreateDownloadFile( | 78 void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info, |
| 78 DownloadCreateInfo* info, DownloadManager* download_manager) { | 79 DownloadManager* download_manager, |
| 80 bool get_hash) { |
| 79 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); | 81 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 81 | 83 |
| 82 scoped_ptr<DownloadFile> download_file( | 84 scoped_ptr<DownloadFile> |
| 83 new DownloadFile(info, download_manager)); | 85 download_file(new DownloadFile(info, download_manager)); |
| 84 if (!download_file->Initialize()) { | 86 if (!download_file->Initialize(get_hash)) { |
| 85 BrowserThread::PostTask( | 87 BrowserThread::PostTask( |
| 86 BrowserThread::IO, FROM_HERE, | 88 BrowserThread::IO, FROM_HERE, |
| 87 NewRunnableFunction(&download_util::CancelDownloadRequest, | 89 NewRunnableFunction(&download_util::CancelDownloadRequest, |
| 88 resource_dispatcher_host_, | 90 resource_dispatcher_host_, |
| 89 info->child_id, | 91 info->child_id, |
| 90 info->request_id)); | 92 info->request_id)); |
| 91 delete info; | 93 delete info; |
| 92 return; | 94 return; |
| 93 } | 95 } |
| 94 | 96 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 NewRunnableFunction(&download_util::CancelDownloadRequest, | 172 NewRunnableFunction(&download_util::CancelDownloadRequest, |
| 171 resource_dispatcher_host_, | 173 resource_dispatcher_host_, |
| 172 info->child_id, | 174 info->child_id, |
| 173 info->request_id)); | 175 info->request_id)); |
| 174 delete info; | 176 delete info; |
| 175 return; | 177 return; |
| 176 } | 178 } |
| 177 | 179 |
| 178 manager->CreateDownloadItem(info); | 180 manager->CreateDownloadItem(info); |
| 179 | 181 |
| 182 bool hash_needed = resource_dispatcher_host_->safe_browsing_service()-> |
| 183 DownloadBinHashNeeded(); |
| 184 |
| 180 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 185 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 181 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile, | 186 NewRunnableMethod(this, &DownloadFileManager::CreateDownloadFile, |
| 182 info, make_scoped_refptr(manager))); | 187 info, make_scoped_refptr(manager), hash_needed)); |
| 183 } | 188 } |
| 184 | 189 |
| 185 // We don't forward an update to the UI thread here, since we want to throttle | 190 // We don't forward an update to the UI thread here, since we want to throttle |
| 186 // the UI update rate via a periodic timer. If the user has cancelled the | 191 // the UI update rate via a periodic timer. If the user has cancelled the |
| 187 // download (in the UI thread), we may receive a few more updates before the IO | 192 // download (in the UI thread), we may receive a few more updates before the IO |
| 188 // thread gets the cancel message: we just delete the data since the | 193 // thread gets the cancel message: we just delete the data since the |
| 189 // DownloadFile has been deleted. | 194 // DownloadFile has been deleted. |
| 190 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { | 195 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { |
| 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 192 std::vector<DownloadBuffer::Contents> contents; | 197 std::vector<DownloadBuffer::Contents> contents; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 if (!download_manager) { | 374 if (!download_manager) { |
| 370 download->CancelDownloadRequest(resource_dispatcher_host_); | 375 download->CancelDownloadRequest(resource_dispatcher_host_); |
| 371 return; | 376 return; |
| 372 } | 377 } |
| 373 | 378 |
| 374 BrowserThread::PostTask( | 379 BrowserThread::PostTask( |
| 375 BrowserThread::UI, FROM_HERE, | 380 BrowserThread::UI, FROM_HERE, |
| 376 NewRunnableMethod(download_manager, | 381 NewRunnableMethod(download_manager, |
| 377 &DownloadManager::DownloadCancelled, id)); | 382 &DownloadManager::DownloadCancelled, id)); |
| 378 } | 383 } |
| OLD | NEW |