Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: content/browser/download/download_item_impl.h

Issue 8697006: DownloadManager intereface refactoring to allow cleaner DownloadItem unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved isolation of MockDownloadManager. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_item_impl.h
diff --git a/content/browser/download/download_item_impl.h b/content/browser/download/download_item_impl.h
index e19080170e19f46e57e3fc72682bda4bbf667565..624ea0c1cc63216a8fe051a60c3f9ac982739560 100644
--- a/content/browser/download/download_item_impl.h
+++ b/content/browser/download/download_item_impl.h
@@ -24,29 +24,68 @@
#include "net/base/net_errors.h"
class DownloadFileManager;
-class DownloadId;
-class DownloadManager;
class TabContents;
struct DownloadCreateInfo;
struct DownloadPersistentStoreInfo;
+namespace content {
+class BrowserContext;
+}
+
// See download_item.h for usage.
class CONTENT_EXPORT DownloadItemImpl : public DownloadItem {
public:
+ // Interface to delegate to which DownloadItemImpl requests operations
+ // it doesn't know how to perform.
+ class Delegate {
cbentzel 2011/11/29 21:30:44 There's no documentation about lifetime expectatio
ahendrickson 2011/11/29 21:40:15 Should this be part of DownloadItem instead of Dow
Randy Smith (Not in Mondays) 2011/11/30 22:44:05 My intent was to specify that the delegate must ou
Randy Smith (Not in Mondays) 2011/11/30 22:44:05 Nope. It's irrelevant to the DownloadItem interfa
+ public:
+ virtual ~Delegate() {}
+
+ // Tests if a file type should be opened automatically.
+ virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) = 0;
+
+ // Allows the delegate to override the opening of a download. If it returns
+ // true then it's reponsible for opening the item.
+ virtual bool ShouldOpenDownload(DownloadItem* download) = 0;
cbentzel 2011/11/29 21:30:44 It's a little strange that the DownloadItemImpl::D
Randy Smith (Not in Mondays) 2011/11/30 22:44:05 As I indicated to Andy above, I don't think so. I
+
+ // 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.
+ virtual void CheckForFileRemoval(DownloadItem* download_item) = 0;
+
+ // If all pre-requisites have been met, complete download processing.
+ // TODO(rdsmith): Move into DownloadItem.
+ virtual void MaybeCompleteDownload(DownloadItem* download) = 0;
+
+ // For contextual issues like language and prefs.
+ virtual content::BrowserContext* BrowserContext() const = 0;
+
+ // Handle any delegate portions of a state change operation on the
+ // DownloadItem.
+ virtual void DownloadCancelled(DownloadItem* download) = 0;
+ virtual void DownloadCompleted(DownloadItem* download) = 0;
+ virtual void DownloadOpened(DownloadItem* download) = 0;
+ virtual void DownloadRemoved(DownloadItem* download) = 0;
+
+ // Assert consistent state for delgate object at various transitions.
+ virtual void AssertStateConsistent(DownloadItem* download) const = 0;
+ };
+
// Constructing from persistent store:
- DownloadItemImpl(DownloadManager* download_manager,
+ DownloadItemImpl(Delegate* delegate,
+ DownloadId download_id,
const DownloadPersistentStoreInfo& info);
// Constructing for a regular download.
// Takes ownership of the object pointed to by |request_handle|.
- DownloadItemImpl(DownloadManager* download_manager,
+ DownloadItemImpl(Delegate* delegate,
const DownloadCreateInfo& info,
DownloadRequestHandleInterface* request_handle,
bool is_otr);
// Constructing for the "Save Page As..." feature:
- DownloadItemImpl(DownloadManager* download_manager,
+ DownloadItemImpl(Delegate* delegate,
const FilePath& path,
const GURL& url,
bool is_otr,
@@ -112,7 +151,6 @@ class CONTENT_EXPORT DownloadItemImpl : public DownloadItem {
virtual base::Time GetEndTime() const OVERRIDE;
virtual void SetDbHandle(int64 handle) OVERRIDE;
virtual int64 GetDbHandle() const OVERRIDE;
- virtual DownloadManager* GetDownloadManager() OVERRIDE;
virtual bool IsPaused() const OVERRIDE;
virtual bool GetOpenWhenComplete() const OVERRIDE;
virtual void SetOpenWhenComplete(bool open) OVERRIDE;
@@ -134,6 +172,7 @@ class CONTENT_EXPORT DownloadItemImpl : public DownloadItem {
virtual InterruptReason GetLastReason() const OVERRIDE;
virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE;
virtual DownloadStateInfo GetStateInfo() const OVERRIDE;
+ virtual content::BrowserContext* BrowserContext() const OVERRIDE;
virtual TabContents* GetTabContents() const OVERRIDE;
virtual FilePath GetTargetFilePath() const OVERRIDE;
virtual FilePath GetFileNameToReportUser() const OVERRIDE;
@@ -242,8 +281,8 @@ class CONTENT_EXPORT DownloadItemImpl : public DownloadItem {
// Our persistent store handle
int64 db_handle_;
- // Our owning object
- DownloadManager* download_manager_;
+ // Our delegate.
+ Delegate* delegate_;
// In progress downloads may be paused by the user, we note it here
bool is_paused_;

Powered by Google App Engine
This is Rietveld 408576698