Chromium Code Reviews| 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" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 class DownloadFileFactoryImpl | 40 class DownloadFileFactoryImpl |
| 41 : public DownloadFileManager::DownloadFileFactory { | 41 : public DownloadFileManager::DownloadFileFactory { |
| 42 public: | 42 public: |
| 43 DownloadFileFactoryImpl() {} | 43 DownloadFileFactoryImpl() {} |
| 44 | 44 |
| 45 virtual content::DownloadFile* CreateFile( | 45 virtual content::DownloadFile* CreateFile( |
| 46 DownloadCreateInfo* info, | 46 DownloadCreateInfo* info, |
| 47 const DownloadRequestHandle& request_handle, | 47 const DownloadRequestHandle& request_handle, |
| 48 DownloadManager* download_manager, | 48 DownloadManager* download_manager, |
| 49 bool calculate_hash) OVERRIDE; | 49 bool calculate_hash, |
| 50 const net::BoundNetLog& bound_net_log) OVERRIDE; | |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 DownloadFile* DownloadFileFactoryImpl::CreateFile( | 53 DownloadFile* DownloadFileFactoryImpl::CreateFile( |
| 53 DownloadCreateInfo* info, | 54 DownloadCreateInfo* info, |
| 54 const DownloadRequestHandle& request_handle, | 55 const DownloadRequestHandle& request_handle, |
| 55 DownloadManager* download_manager, | 56 DownloadManager* download_manager, |
| 56 bool calculate_hash) { | 57 bool calculate_hash, |
| 58 const net::BoundNetLog& bound_net_log) { | |
| 57 return new DownloadFileImpl(info, | 59 return new DownloadFileImpl(info, |
| 58 new DownloadRequestHandle(request_handle), | 60 new DownloadRequestHandle(request_handle), |
| 59 download_manager, calculate_hash); | 61 download_manager, calculate_hash, |
| 62 bound_net_log); | |
| 60 } | 63 } |
| 61 | 64 |
| 62 } // namespace | 65 } // namespace |
| 63 | 66 |
| 64 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh, | 67 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh, |
| 65 DownloadFileFactory* factory) | 68 DownloadFileFactory* factory) |
| 66 : resource_dispatcher_host_(rdh), download_file_factory_(factory) { | 69 : resource_dispatcher_host_(rdh), download_file_factory_(factory) { |
| 67 if (download_file_factory_ == NULL) | 70 if (download_file_factory_ == NULL) |
| 68 download_file_factory_.reset(new DownloadFileFactoryImpl); | 71 download_file_factory_.reset(new DownloadFileFactoryImpl); |
| 69 } | 72 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 80 } | 83 } |
| 81 | 84 |
| 82 void DownloadFileManager::OnShutdown() { | 85 void DownloadFileManager::OnShutdown() { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 84 StopUpdateTimer(); | 87 StopUpdateTimer(); |
| 85 STLDeleteValues(&downloads_); | 88 STLDeleteValues(&downloads_); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void DownloadFileManager::CreateDownloadFile( | 91 void DownloadFileManager::CreateDownloadFile( |
| 89 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, | 92 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, |
| 90 DownloadManager* download_manager, bool get_hash) { | 93 DownloadManager* download_manager, bool get_hash, |
| 94 const net::BoundNetLog& bound_net_log) { | |
| 91 DCHECK(info); | 95 DCHECK(info); |
| 92 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); | 96 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 94 | 98 |
| 95 // Life of |info| ends here. No more references to it after this method. | 99 // Life of |info| ends here. No more references to it after this method. |
| 96 scoped_ptr<DownloadCreateInfo> infop(info); | 100 scoped_ptr<DownloadCreateInfo> infop(info); |
| 97 | 101 |
| 98 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile( | 102 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile( |
| 99 info, request_handle, download_manager, get_hash)); | 103 info, request_handle, download_manager, get_hash, bound_net_log)); |
| 100 if (net::OK != download_file->Initialize()) { | 104 if (net::OK != download_file->Initialize()) { |
| 101 request_handle.CancelRequest(); | 105 request_handle.CancelRequest(); |
| 102 return; | 106 return; |
| 103 } | 107 } |
| 104 | 108 |
| 105 DCHECK(GetDownloadFile(info->download_id) == NULL); | 109 DCHECK(GetDownloadFile(info->download_id) == NULL); |
| 106 downloads_[info->download_id] = download_file.release(); | 110 downloads_[info->download_id] = download_file.release(); |
| 107 | 111 |
| 108 // The file is now ready, we can un-pause the request and start saving data. | 112 // The file is now ready, we can un-pause the request and start saving data. |
| 109 request_handle.ResumeRequest(); | 113 request_handle.ResumeRequest(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 DCHECK(info); | 165 DCHECK(info); |
| 162 | 166 |
| 163 DownloadManager* manager = request_handle.GetDownloadManager(); | 167 DownloadManager* manager = request_handle.GetDownloadManager(); |
| 164 if (!manager) { | 168 if (!manager) { |
| 165 request_handle.CancelRequest(); | 169 request_handle.CancelRequest(); |
| 166 delete info; | 170 delete info; |
| 167 return; | 171 return; |
| 168 } | 172 } |
| 169 | 173 |
| 170 manager->CreateDownloadItem(info, request_handle); | 174 net::BoundNetLog bound_net_log = |
|
Randy Smith (Not in Mondays)
2012/02/07 23:19:14
I'd put a comment somewhere in here about using th
ahendrickson
2012/02/07 23:58:54
Done.
| |
| 175 manager->CreateDownloadItem(info, request_handle); | |
| 171 bool hash_needed = manager->GenerateFileHash(); | 176 bool hash_needed = manager->GenerateFileHash(); |
| 172 | 177 |
| 173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 178 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 174 base::Bind(&DownloadFileManager::CreateDownloadFile, this, | 179 base::Bind(&DownloadFileManager::CreateDownloadFile, this, |
| 175 info, request_handle, make_scoped_refptr(manager), | 180 info, request_handle, make_scoped_refptr(manager), |
| 176 hash_needed)); | 181 hash_needed, bound_net_log)); |
| 177 } | 182 } |
| 178 | 183 |
| 179 // We don't forward an update to the UI thread here, since we want to throttle | 184 // We don't forward an update to the UI thread here, since we want to throttle |
| 180 // the UI update rate via a periodic timer. If the user has cancelled the | 185 // the UI update rate via a periodic timer. If the user has cancelled the |
| 181 // download (in the UI thread), we may receive a few more updates before the IO | 186 // download (in the UI thread), we may receive a few more updates before the IO |
| 182 // thread gets the cancel message: we just delete the data since the | 187 // thread gets the cancel message: we just delete the data since the |
| 183 // DownloadFile has been deleted. | 188 // DownloadFile has been deleted. |
| 184 void DownloadFileManager::UpdateDownload( | 189 void DownloadFileManager::UpdateDownload( |
| 185 DownloadId global_id, content::DownloadBuffer* buffer) { | 190 DownloadId global_id, content::DownloadBuffer* buffer) { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 << " id = " << global_id | 474 << " id = " << global_id |
| 470 << " download_file = " << download_file->DebugString(); | 475 << " download_file = " << download_file->DebugString(); |
| 471 | 476 |
| 472 downloads_.erase(global_id); | 477 downloads_.erase(global_id); |
| 473 | 478 |
| 474 delete download_file; | 479 delete download_file; |
| 475 | 480 |
| 476 if (downloads_.empty()) | 481 if (downloads_.empty()) |
| 477 StopUpdateTimer(); | 482 StopUpdateTimer(); |
| 478 } | 483 } |
| OLD | NEW |