Index: content/browser/download/download_manager.h |
diff --git a/content/browser/download/download_manager.h b/content/browser/download/download_manager.h |
index cf8d2db4a181143d753237d84207361f1c49f600..14ca2a22bbf1cb9da125cacc5ed67cd3aad6b4ec 100644 |
--- a/content/browser/download/download_manager.h |
+++ b/content/browser/download/download_manager.h |
@@ -70,15 +70,12 @@ class DownloadManagerDelegate; |
// Browser's download manager: manages all downloads and destination view. |
class CONTENT_EXPORT DownloadManager |
: public base::RefCountedThreadSafe< |
- DownloadManager, content::BrowserThread::DeleteOnUIThread>, |
- public DownloadStatusUpdaterDelegate { |
+ DownloadManager, content::BrowserThread::DeleteOnUIThread> { |
public: |
- DownloadManager(content::DownloadManagerDelegate* delegate, |
- DownloadIdFactory* id_factory, |
- DownloadStatusUpdater* status_updater); |
+ virtual ~DownloadManager() {} |
// Shutdown the download manager. Must be called before destruction. |
- void Shutdown(); |
+ virtual void Shutdown() = 0; |
// Interface to implement for observers that wish to be informed of changes |
// to the DownloadManager's collection of downloads. |
@@ -104,187 +101,295 @@ class CONTENT_EXPORT DownloadManager |
typedef std::vector<DownloadItem*> DownloadVector; |
// Return all temporary downloads that reside in the specified directory. |
- void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); |
+ virtual void GetTemporaryDownloads(const FilePath& dir_path, |
+ DownloadVector* result) = 0; |
// Return all non-temporary downloads in the specified directory that are |
// are in progress or have completed. |
- void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
+ virtual void GetAllDownloads(const FilePath& dir_path, |
+ DownloadVector* result) = 0; |
// Returns all non-temporary downloads matching |query|. Empty query matches |
// everything. |
- void SearchDownloads(const string16& query, DownloadVector* result); |
+ virtual void SearchDownloads(const string16& query, |
+ DownloadVector* result) = 0; |
// Returns true if initialized properly. |
- bool Init(content::BrowserContext* browser_context); |
+ virtual bool Init(content::BrowserContext* browser_context) = 0; |
// Notifications sent from the download thread to the UI thread |
- void StartDownload(int32 id); |
- void UpdateDownload(int32 download_id, int64 size); |
+ virtual void StartDownload(int32 id) = 0; |
+ virtual void UpdateDownload(int32 download_id, int64 size) = 0; |
// |download_id| is the ID of the download. |
// |size| is the number of bytes that have been downloaded. |
// |hash| is sha256 hash for the downloaded file. It is empty when the hash |
// is not available. |
- void OnResponseCompleted(int32 download_id, int64 size, |
- const std::string& hash); |
+ virtual void OnResponseCompleted(int32 download_id, int64 size, |
+ const std::string& hash) = 0; |
// Offthread target for cancelling a particular download. Will be a no-op |
// if the download has already been cancelled. |
- void CancelDownload(int32 download_id); |
+ virtual void CancelDownload(int32 download_id) = 0; |
// Called when there is an error in the download. |
// |download_id| is the ID of the download. |
// |size| is the number of bytes that are currently downloaded. |
// |reason| is a download interrupt reason code. |
- void OnDownloadInterrupted(int32 download_id, int64 size, |
- InterruptReason reason); |
+ virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
+ InterruptReason reason) = 0; |
// Called from DownloadItem to handle the DownloadManager portion of a |
// Cancel; should not be called from other locations. |
- void DownloadCancelledInternal(DownloadItem* download); |
+ virtual void DownloadCancelledInternal(DownloadItem* download) = 0; |
// Called from a view when a user clicks a UI button or link. |
- void RemoveDownload(int64 download_handle); |
+ virtual void RemoveDownload(int64 download_handle) = 0; |
// Determine if the download is ready for completion, i.e. has had |
// all data saved, and completed the filename determination and |
// history insertion. |
- bool IsDownloadReadyForCompletion(DownloadItem* download); |
+ virtual bool IsDownloadReadyForCompletion(DownloadItem* download) = 0; |
// If all pre-requisites have been met, complete download processing, i.e. |
// do internal cleanup, file rename, and potentially auto-open. |
// (Dangerous downloads still may block on user acceptance after this |
// point.) |
- void MaybeCompleteDownload(DownloadItem* download); |
+ virtual void MaybeCompleteDownload(DownloadItem* download) = 0; |
// Called when the download is renamed to its final name. |
// |uniquifier| is a number used to make unique names for the file. It is |
// only valid for the DANGEROUS_BUT_VALIDATED state of the download item. |
- void OnDownloadRenamedToFinalName(int download_id, |
+ virtual void OnDownloadRenamedToFinalName(int download_id, |
const FilePath& full_path, |
- int uniquifier); |
+ int uniquifier) = 0; |
// Remove downloads after remove_begin (inclusive) and before remove_end |
// (exclusive). You may pass in null Time values to do an unbounded delete |
// in either direction. |
- int RemoveDownloadsBetween(const base::Time remove_begin, |
- const base::Time remove_end); |
+ virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
+ const base::Time remove_end) = 0; |
// Remove downloads will delete all downloads that have a timestamp that is |
// the same or more recent than |remove_begin|. The number of downloads |
// deleted is returned back to the caller. |
- int RemoveDownloads(const base::Time remove_begin); |
+ virtual int RemoveDownloads(const base::Time remove_begin) = 0; |
// Remove all downloads will delete all downloads. The number of downloads |
// deleted is returned back to the caller. |
- int RemoveAllDownloads(); |
+ virtual int RemoveAllDownloads() = 0; |
// Final download manager transition for download: Update the download |
// history and remove the download from |active_downloads_|. |
- void DownloadCompleted(int32 download_id); |
+ virtual void DownloadCompleted(int32 download_id) = 0; |
// Download the object at the URL. Used in cases such as "Save Link As..." |
- void DownloadUrl(const GURL& url, |
+ virtual void DownloadUrl(const GURL& url, |
const GURL& referrer, |
const std::string& referrer_encoding, |
- TabContents* tab_contents); |
+ TabContents* tab_contents) = 0; |
// Download the object at the URL and save it to the specified path. The |
// download is treated as the temporary download and thus will not appear |
// in the download history. Used in cases such as drag and drop. |
- void DownloadUrlToFile(const GURL& url, |
+ virtual void DownloadUrlToFile(const GURL& url, |
const GURL& referrer, |
const std::string& referrer_encoding, |
const DownloadSaveInfo& save_info, |
- TabContents* tab_contents); |
+ TabContents* tab_contents) = 0; |
// Allow objects to observe the download creation process. |
- void AddObserver(Observer* observer); |
+ virtual void AddObserver(Observer* observer) = 0; |
// Remove a download observer from ourself. |
- void RemoveObserver(Observer* observer); |
+ virtual void RemoveObserver(Observer* observer) = 0; |
// Called by the embedder, after creating the download manager, to let it know |
// about downloads from previous runs of the browser. |
- void OnPersistentStoreQueryComplete( |
- std::vector<DownloadPersistentStoreInfo>* entries); |
+ virtual void OnPersistentStoreQueryComplete( |
+ std::vector<DownloadPersistentStoreInfo>* entries) = 0; |
// Called by the embedder, in response to |
// DownloadManagerDelegate::AddItemToPersistentStore. |
- void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
+ virtual void OnItemAddedToPersistentStore(int32 download_id, |
+ int64 db_handle) = 0; |
// Display a new download in the appropriate browser UI. |
- void ShowDownloadInBrowser(DownloadItem* download); |
+ virtual void ShowDownloadInBrowser(DownloadItem* download) = 0; |
// The number of in progress (including paused) downloads. |
- int in_progress_count() const { |
- return static_cast<int>(in_progress_.size()); |
- } |
+ virtual int InProgressCount() const = 0; |
- content::BrowserContext* browser_context() { return browser_context_; } |
+ virtual content::BrowserContext* BrowserContext() = 0; |
- FilePath last_download_path() { return last_download_path_; } |
+ virtual FilePath LastDownloadPath() = 0; |
// Creates the download item. Must be called on the UI thread. |
- void CreateDownloadItem(DownloadCreateInfo* info, |
- const DownloadRequestHandle& request_handle); |
+ virtual void CreateDownloadItem(DownloadCreateInfo* info, |
+ const DownloadRequestHandle& request_handle) = 0; |
// Clears the last download path, used to initialize "save as" dialogs. |
- void ClearLastDownloadPath(); |
- |
- // Overridden from DownloadStatusUpdaterDelegate: |
- virtual bool IsDownloadProgressKnown() const OVERRIDE; |
- virtual int64 GetInProgressDownloadCount() const OVERRIDE; |
- virtual int64 GetReceivedDownloadBytes() const OVERRIDE; |
- virtual int64 GetTotalDownloadBytes() const OVERRIDE; |
+ virtual void ClearLastDownloadPath() = 0; |
// Called by the delegate after the save as dialog is closed. |
- void FileSelected(const FilePath& path, void* params); |
- void FileSelectionCanceled(void* params); |
+ virtual void FileSelected(const FilePath& path, void* params) = 0; |
+ virtual void FileSelectionCanceled(void* params) = 0; |
// Called by the delegate if it delayed the download in |
// DownloadManagerDelegate::ShouldStartDownload and now is ready. |
- void RestartDownload(int32 download_id); |
+ virtual void RestartDownload(int32 download_id) = 0; |
// Mark the download opened in the persistent store. |
- void MarkDownloadOpened(DownloadItem* download); |
+ virtual void MarkDownloadOpened(DownloadItem* download) = 0; |
// Checks whether downloaded files still exist. Updates state of downloads |
// that refer to removed files. The check runs in the background and may |
// finish asynchronously after this method returns. |
- void CheckForHistoryFilesRemoval(); |
+ virtual void CheckForHistoryFilesRemoval() = 0; |
// Checks whether a downloaded file still exists and updates the file's state |
// if the file is already removed. The check runs in the background and may |
// finish asynchronously after this method returns. |
- void CheckForFileRemoval(DownloadItem* download_item); |
+ virtual void CheckForFileRemoval(DownloadItem* download_item) = 0; |
// Assert the named download item is on the correct queues |
// in the DownloadManager. For debugging. |
- void AssertQueueStateConsistent(DownloadItem* download); |
+ virtual void AssertQueueStateConsistent(DownloadItem* download) = 0; |
// Get the download item from the history map. Useful after the item has |
// been removed from the active map, or was retrieved from the history DB. |
- DownloadItem* GetDownloadItem(int id); |
+ virtual DownloadItem* GetDownloadItem(int id) = 0; |
// Called when Save Page download starts. Transfers ownership of |download| |
// to the DownloadManager. |
- void SavePageDownloadStarted(DownloadItem* download); |
+ virtual void SavePageDownloadStarted(DownloadItem* download) = 0; |
// Called when Save Page download is done. |
- void SavePageDownloadFinished(DownloadItem* download); |
+ virtual void SavePageDownloadFinished(DownloadItem* download) = 0; |
// Get the download item from the active map. Useful when the item is not |
// yet in the history map. |
- DownloadItem* GetActiveDownloadItem(int id); |
+ virtual DownloadItem* GetActiveDownloadItem(int id) = 0; |
- content::DownloadManagerDelegate* delegate() const { return delegate_; } |
+ virtual content::DownloadManagerDelegate* delegate() const = 0; |
// For testing only. May be called from tests indirectly (through |
// other for testing only methods). |
- void SetDownloadManagerDelegate(content::DownloadManagerDelegate* delegate); |
+ virtual void SetDownloadManagerDelegate( |
+ content::DownloadManagerDelegate* delegate) = 0; |
+ |
+ virtual DownloadId GetNextId() = 0; |
+ |
+ protected: |
+ // These functions are here for unit tests. |
+ |
+ // Called back after a target path for the file to be downloaded to has been |
+ // determined, either automatically based on the suggested file name, or by |
+ // the user in a Save As dialog box. |
+ virtual void ContinueDownloadWithPath(DownloadItem* download, |
+ const FilePath& chosen_file) = 0; |
+ |
+ // Retrieves the download from the |download_id|. |
+ // Returns NULL if the download is not active. |
+ virtual DownloadItem* GetActiveDownload(int32 download_id) = 0; |
+ |
+ virtual void SetFileManager(DownloadFileManager* file_manager) = 0; |
+ |
+private: |
+ // For testing. |
+ friend class DownloadManagerTest; |
+ friend class DownloadTest; |
+ friend class MockDownloadManager; |
+ |
+ friend class base::RefCountedThreadSafe< |
+ DownloadManager, content::BrowserThread::DeleteOnUIThread>; |
+ friend struct content::BrowserThread::DeleteOnThread< |
+ content::BrowserThread::UI>; |
+ friend class DeleteTask<DownloadManager>; |
+}; |
- DownloadId GetNextId(); |
+class CONTENT_EXPORT DownloadManagerImpl |
jam
2011/11/09 17:34:00
this need to go into a separate file, i.e .downloa
ahendrickson
2011/11/09 22:00:59
Done.
|
+ : public DownloadManager, |
+ public DownloadStatusUpdaterDelegate { |
+ public: |
+ DownloadManagerImpl(content::DownloadManagerDelegate* delegate, |
+ DownloadIdFactory* id_factory, |
+ DownloadStatusUpdater* status_updater); |
+ |
+ // DownloadManager functions. |
+ virtual void Shutdown() OVERRIDE; |
+ virtual void GetTemporaryDownloads(const FilePath& dir_path, |
+ DownloadVector* result) OVERRIDE; |
+ virtual void GetAllDownloads(const FilePath& dir_path, |
+ DownloadVector* result) OVERRIDE; |
+ virtual void SearchDownloads(const string16& query, |
+ DownloadVector* result) OVERRIDE; |
+ virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; |
+ virtual void StartDownload(int32 id) OVERRIDE; |
+ virtual void UpdateDownload(int32 download_id, int64 size) OVERRIDE; |
+ virtual void OnResponseCompleted(int32 download_id, int64 size, |
+ const std::string& hash) OVERRIDE; |
+ virtual void CancelDownload(int32 download_id) OVERRIDE; |
+ virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
+ InterruptReason reason) OVERRIDE; |
+ virtual void DownloadCancelledInternal(DownloadItem* download) OVERRIDE; |
+ virtual void RemoveDownload(int64 download_handle) OVERRIDE; |
+ virtual bool IsDownloadReadyForCompletion(DownloadItem* download) OVERRIDE; |
+ virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; |
+ virtual void OnDownloadRenamedToFinalName(int download_id, |
+ const FilePath& full_path, |
+ int uniquifier) OVERRIDE; |
+ virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
+ const base::Time remove_end) OVERRIDE; |
+ virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; |
+ virtual int RemoveAllDownloads() OVERRIDE; |
+ virtual void DownloadCompleted(int32 download_id) OVERRIDE; |
+ virtual void DownloadUrl(const GURL& url, |
+ const GURL& referrer, |
+ const std::string& referrer_encoding, |
+ TabContents* tab_contents) OVERRIDE; |
+ virtual void DownloadUrlToFile(const GURL& url, |
+ const GURL& referrer, |
+ const std::string& referrer_encoding, |
+ const DownloadSaveInfo& save_info, |
+ TabContents* tab_contents) OVERRIDE; |
+ virtual void AddObserver(Observer* observer) OVERRIDE; |
+ virtual void RemoveObserver(Observer* observer) OVERRIDE; |
+ virtual void OnPersistentStoreQueryComplete( |
+ std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; |
+ virtual void OnItemAddedToPersistentStore(int32 download_id, |
+ int64 db_handle) OVERRIDE; |
+ virtual void ShowDownloadInBrowser(DownloadItem* download) OVERRIDE; |
+ virtual int InProgressCount() const OVERRIDE; |
+ virtual content::BrowserContext* BrowserContext() OVERRIDE; |
+ virtual FilePath LastDownloadPath() OVERRIDE; |
+ virtual void CreateDownloadItem( |
+ DownloadCreateInfo* info, |
+ const DownloadRequestHandle& request_handle) OVERRIDE; |
+ virtual void ClearLastDownloadPath() OVERRIDE; |
+ |
+ // Overridden from DownloadStatusUpdaterDelegate: |
+ virtual bool IsDownloadProgressKnown() const OVERRIDE; |
+ virtual int64 GetInProgressDownloadCount() const OVERRIDE; |
+ virtual int64 GetReceivedDownloadBytes() const OVERRIDE; |
+ virtual int64 GetTotalDownloadBytes() const OVERRIDE; |
+ |
+ // More DownloadManager functions. |
+ virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; |
+ virtual void FileSelectionCanceled(void* params) OVERRIDE; |
+ virtual void RestartDownload(int32 download_id) OVERRIDE; |
+ virtual void MarkDownloadOpened(DownloadItem* download) OVERRIDE; |
+ virtual void CheckForHistoryFilesRemoval() OVERRIDE; |
+ virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; |
+ virtual void AssertQueueStateConsistent(DownloadItem* download) OVERRIDE; |
+ virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; |
+ virtual void SavePageDownloadStarted(DownloadItem* download) OVERRIDE; |
+ virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; |
+ virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; |
+ virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; |
+ virtual void SetDownloadManagerDelegate( |
+ content::DownloadManagerDelegate* delegate) OVERRIDE; |
+ virtual DownloadId GetNextId() OVERRIDE; |
private: |
typedef std::set<DownloadItem*> DownloadSet; |
@@ -296,12 +401,12 @@ class CONTENT_EXPORT DownloadManager |
friend class MockDownloadManager; |
friend class base::RefCountedThreadSafe< |
- DownloadManager, content::BrowserThread::DeleteOnUIThread>; |
+ DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; |
friend struct content::BrowserThread::DeleteOnThread< |
content::BrowserThread::UI>; |
- friend class DeleteTask<DownloadManager>; |
+ friend class DeleteTask<DownloadManagerImpl>; |
- virtual ~DownloadManager(); |
+ virtual ~DownloadManagerImpl(); |
// Called on the FILE thread to check the existence of a downloaded file. |
void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
@@ -314,12 +419,12 @@ class CONTENT_EXPORT DownloadManager |
// Called back after a target path for the file to be downloaded to has been |
// determined, either automatically based on the suggested file name, or by |
// the user in a Save As dialog box. |
- void ContinueDownloadWithPath(DownloadItem* download, |
- const FilePath& chosen_file); |
+ virtual void ContinueDownloadWithPath(DownloadItem* download, |
+ const FilePath& chosen_file) OVERRIDE; |
// Retrieves the download from the |download_id|. |
// Returns NULL if the download is not active. |
- DownloadItem* GetActiveDownload(int32 download_id); |
+ virtual DownloadItem* GetActiveDownload(int32 download_id) OVERRIDE; |
// Removes |download| from the active and in progress maps. |
// Called when the download is cancelled or has an error. |
@@ -345,9 +450,12 @@ class CONTENT_EXPORT DownloadManager |
// Called when a download entry is committed to the persistent store. |
void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
- // Called when Save Page As entry is commited to the persistent store. |
+ // Called when Save Page As entry is committed to the persistent store. |
void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
+ // For unit tests only. |
+ virtual void SetFileManager(DownloadFileManager* file_manager) OVERRIDE; |
+ |
// |downloads_| is the owning set for all downloads known to the |
// DownloadManager. This includes downloads started by the user in |
// this session, downloads initialized from the history system, and |
@@ -420,7 +528,7 @@ class CONTENT_EXPORT DownloadManager |
// For debugging only. |
int64 largest_db_handle_in_history_; |
- DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
+ DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
}; |
#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |