From 159ffc1ba1d4846e7b7c459f5c098c581436ef82 Mon Sep 17 00:00:00 2001 From: "ahendrickson@chromium.org" Date: Thu, 8 Dec 2011 21:04:35 +0000 Subject: Added a download file factory to the download file manager, for testing. BUG=None TEST=None Review URL: http://codereview.chromium.org/8770024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113658 0039d316-1c4b-4281-b951-d872f2087c98 --- content/browser/download/download_file_manager.cc | 32 ++++++++++++++++++----- content/browser/download/download_file_manager.h | 18 ++++++++++++- 2 files changed, 43 insertions(+), 7 deletions(-) (limited to 'content/browser/download') diff --git a/content/browser/download/download_file_manager.cc b/content/browser/download/download_file_manager.cc index 0a5f5e9..e9794b7 100644 --- a/content/browser/download/download_file_manager.cc +++ b/content/browser/download/download_file_manager.cc @@ -34,10 +34,32 @@ namespace { // cause it to become unresponsive (in milliseconds). const int kUpdatePeriodMs = 500; +class DownloadFileFactoryImpl + : public DownloadFileManager::DownloadFileFactory { + public: + DownloadFileFactoryImpl() {} + + virtual DownloadFile* CreateFile(DownloadCreateInfo* info, + const DownloadRequestHandle& request_handle, + DownloadManager* download_manager) OVERRIDE; +}; + +DownloadFile* DownloadFileFactoryImpl::CreateFile( + DownloadCreateInfo* info, + const DownloadRequestHandle& request_handle, + DownloadManager* download_manager) { + return new DownloadFileImpl(info, + new DownloadRequestHandle(request_handle), + download_manager); +} + } // namespace -DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) - : resource_dispatcher_host_(rdh) { +DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh, + DownloadFileFactory* factory) + : resource_dispatcher_host_(rdh), download_file_factory_(factory) { + if (download_file_factory_ == NULL) + download_file_factory_.reset(new DownloadFileFactoryImpl); } DownloadFileManager::~DownloadFileManager() { @@ -67,10 +89,8 @@ void DownloadFileManager::CreateDownloadFile( // Life of |info| ends here. No more references to it after this method. scoped_ptr infop(info); - scoped_ptr download_file( - new DownloadFileImpl(info, - new DownloadRequestHandle(request_handle), - download_manager)); + scoped_ptr download_file(download_file_factory_->CreateFile( + info, request_handle, download_manager)); if (net::OK != download_file->Initialize(get_hash)) { request_handle.CancelRequest(); return; diff --git a/content/browser/download/download_file_manager.h b/content/browser/download/download_file_manager.h index da86124..3dc8046 100644 --- a/content/browser/download/download_file_manager.h +++ b/content/browser/download/download_file_manager.h @@ -47,6 +47,7 @@ #include "base/gtest_prod_util.h" #include "base/hash_tables.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "base/timer.h" #include "content/browser/download/download_id.h" #include "content/browser/download/interrupt_reasons.h" @@ -69,7 +70,21 @@ class DownloadBuffer; class CONTENT_EXPORT DownloadFileManager : public base::RefCountedThreadSafe { public: - explicit DownloadFileManager(ResourceDispatcherHost* rdh); + class DownloadFileFactory { + public: + virtual ~DownloadFileFactory() {} + + virtual DownloadFile* CreateFile( + DownloadCreateInfo* info, + const DownloadRequestHandle& request_handle, + DownloadManager* download_manager) = 0; + }; + + // Takes ownership of the factory. + // Passing in a NULL for |factory| will cause a default + // |DownloadFileFactory| to be used. + DownloadFileManager(ResourceDispatcherHost* rdh, + DownloadFileFactory* factory); // Called on shutdown on the UI thread. void Shutdown(); @@ -165,6 +180,7 @@ class CONTENT_EXPORT DownloadFileManager base::RepeatingTimer update_timer_; ResourceDispatcherHost* resource_dispatcher_host_; + scoped_ptr download_file_factory_; DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); }; -- cgit v1.1