Chromium Code Reviews| 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 "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 18 matching lines...) Expand all Loading... | |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Throttle updates to the UI thread so that a fast moving download doesn't | 33 // Throttle updates to the UI thread so that a fast moving download doesn't |
| 34 // cause it to become unresponsive (in milliseconds). | 34 // cause it to become unresponsive (in milliseconds). |
| 35 const int kUpdatePeriodMs = 500; | 35 const int kUpdatePeriodMs = 500; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) | 39 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh, |
| 40 : resource_dispatcher_host_(rdh) { | 40 DownloadFileFactory* factory) |
| 41 : resource_dispatcher_host_(rdh), download_file_factory_(factory) { | |
|
cbentzel
2011/12/07 18:58:21
Should DCHECK here that both rdh and factory are n
ahendrickson
2011/12/07 19:55:15
rdh is allowed to be NULL.
If |factory| is NULL,
| |
| 41 } | 42 } |
| 42 | 43 |
| 43 DownloadFileManager::~DownloadFileManager() { | 44 DownloadFileManager::~DownloadFileManager() { |
| 44 DCHECK(downloads_.empty()); | 45 DCHECK(downloads_.empty()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DownloadFileManager::Shutdown() { | 48 void DownloadFileManager::Shutdown() { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 49 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
| 50 BrowserThread::FILE, FROM_HERE, | 51 BrowserThread::FILE, FROM_HERE, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 61 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, | 62 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, |
| 62 DownloadManager* download_manager, bool get_hash) { | 63 DownloadManager* download_manager, bool get_hash) { |
| 63 DCHECK(info); | 64 DCHECK(info); |
| 64 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); | 65 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 66 | 67 |
| 67 // Life of |info| ends here. No more references to it after this method. | 68 // Life of |info| ends here. No more references to it after this method. |
| 68 scoped_ptr<DownloadCreateInfo> infop(info); | 69 scoped_ptr<DownloadCreateInfo> infop(info); |
| 69 | 70 |
| 70 scoped_ptr<DownloadFile> download_file( | 71 scoped_ptr<DownloadFile> download_file( |
| 71 new DownloadFileImpl(info, | 72 download_file_factory_->GetFile(info, request_handle, download_manager)); |
|
cbentzel
2011/12/07 18:58:21
that one unit test passes in a NULL DownloadFileFa
ahendrickson
2011/12/07 19:55:15
Done.
| |
| 72 new DownloadRequestHandle(request_handle), | |
| 73 download_manager)); | |
| 74 if (net::OK != download_file->Initialize(get_hash)) { | 73 if (net::OK != download_file->Initialize(get_hash)) { |
| 75 request_handle.CancelRequest(); | 74 request_handle.CancelRequest(); |
| 76 return; | 75 return; |
| 77 } | 76 } |
| 78 | 77 |
| 79 DCHECK(GetDownloadFile(info->download_id) == NULL); | 78 DCHECK(GetDownloadFile(info->download_id) == NULL); |
| 80 downloads_[info->download_id] = download_file.release(); | 79 downloads_[info->download_id] = download_file.release(); |
| 81 | 80 |
| 82 // The file is now ready, we can un-pause the request and start saving data. | 81 // The file is now ready, we can un-pause the request and start saving data. |
| 83 request_handle.ResumeRequest(); | 82 request_handle.ResumeRequest(); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 << " id = " << global_id | 425 << " id = " << global_id |
| 427 << " download_file = " << download_file->DebugString(); | 426 << " download_file = " << download_file->DebugString(); |
| 428 | 427 |
| 429 downloads_.erase(global_id); | 428 downloads_.erase(global_id); |
| 430 | 429 |
| 431 delete download_file; | 430 delete download_file; |
| 432 | 431 |
| 433 if (downloads_.empty()) | 432 if (downloads_.empty()) |
| 434 StopUpdateTimer(); | 433 StopUpdateTimer(); |
| 435 } | 434 } |
| OLD | NEW |