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

Side by Side 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: Sync'd to LKGR. Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/timer.h" 16 #include "base/timer.h"
17 #include "content/browser/download/download_item.h" 17 #include "content/browser/download/download_item.h"
18 #include "content/browser/download/download_id.h" 18 #include "content/browser/download/download_id.h"
19 #include "content/browser/download/download_request_handle.h" 19 #include "content/browser/download/download_request_handle.h"
20 #include "content/browser/download/download_state_info.h" 20 #include "content/browser/download/download_state_info.h"
21 #include "content/browser/download/interrupt_reasons.h" 21 #include "content/browser/download/interrupt_reasons.h"
22 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
25 25
26 class DownloadFileManager; 26 class DownloadFileManager;
27 class DownloadId;
28 class DownloadManager;
29 class TabContents; 27 class TabContents;
30 28
31 struct DownloadCreateInfo; 29 struct DownloadCreateInfo;
32 struct DownloadPersistentStoreInfo; 30 struct DownloadPersistentStoreInfo;
33 31
32 namespace content {
33 class BrowserContext;
34 }
35
34 // See download_item.h for usage. 36 // See download_item.h for usage.
35 class CONTENT_EXPORT DownloadItemImpl : public DownloadItem { 37 class CONTENT_EXPORT DownloadItemImpl : public DownloadItem {
36 public: 38 public:
39 // Interface to delegate to which DownloadItemImpl requests operations
cbentzel 2011/12/02 18:00:52 "Interface to delegate to which" is confusing. Pe
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Done.
40 // it doesn't know how to perform.
41 //
42 // Placed in DownloadItemImpl (rather than DownloadItem) as it's relevant
43 // to the class implementation (class methods need to call into it)
44 // and doesn't have anything to do with its interface.
45 // Despite this, the delegate methods take DownloadItems as arguments
46 // (rather than DownloadItemImpls) so that classes that inherit from it
47 // can be used with DownloadItem mocks rather than being tied to
48 // DownloadItemImpls.
49 class Delegate {
50 public:
51 virtual ~Delegate() {}
52
53 // Tests if a file type should be opened automatically.
54 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) = 0;
cbentzel 2011/12/02 18:00:52 Probably for another CL - but seems like this shou
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Noted for another CL (this signature already exist
55
56 // Allows the delegate to override the opening of a download. If it returns
57 // true then it's reponsible for opening the item.
58 virtual bool ShouldOpenDownload(DownloadItem* download) = 0;
59
60 // Checks whether a downloaded file still exists and updates the
61 // file's state if the file is already removed. The check runs in
62 // the background and may finish asynchronously after this method returns.
63 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0;
cbentzel 2011/12/02 18:00:52 Is it expected that this will call back into OnDow
cbentzel 2011/12/02 18:00:52 Could this move to a const DownloadItem* argument?
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Done.
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Yeah; I think I want to put this one of into anoth
64
65 // If all pre-requisites have been met, complete download processing.
66 // TODO(rdsmith): Move into DownloadItem.
67 virtual void MaybeCompleteDownload(DownloadItem* download) = 0;
68
69 // For contextual issues like language and prefs.
70 virtual content::BrowserContext* BrowserContext() const = 0;
71
72 // Handle any delegate portions of a state change operation on the
73 // DownloadItem.
cbentzel 2011/12/02 18:00:52 Should these move to DownloadItem::Observer?
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Architecturally, definitely. Practically, I'm war
74 virtual void DownloadCancelled(DownloadItem* download) = 0;
75 virtual void DownloadCompleted(DownloadItem* download) = 0;
76 virtual void DownloadOpened(DownloadItem* download) = 0;
77 virtual void DownloadRemoved(DownloadItem* download) = 0;
78
79 // Assert consistent state for delgate object at various transitions.
80 virtual void AssertStateConsistent(DownloadItem* download) const = 0;
81 };
82
83 // Note that it is the responsibility of the caller to ensure that a
84 // DownloadItemImpl::Delegate passed to a DownloadItemImpl constructor
85 // outlive the DownloadItemImpl.
cbentzel 2011/12/02 18:00:52 Nit: outlives? Should you put some debug checks
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Done.
86
37 // Constructing from persistent store: 87 // Constructing from persistent store:
38 DownloadItemImpl(DownloadManager* download_manager, 88 DownloadItemImpl(Delegate* delegate,
89 DownloadId download_id,
39 const DownloadPersistentStoreInfo& info); 90 const DownloadPersistentStoreInfo& info);
40 91
41 // Constructing for a regular download. 92 // Constructing for a regular download.
42 // Takes ownership of the object pointed to by |request_handle|. 93 // Takes ownership of the object pointed to by |request_handle|.
43 DownloadItemImpl(DownloadManager* download_manager, 94 DownloadItemImpl(Delegate* delegate,
44 const DownloadCreateInfo& info, 95 const DownloadCreateInfo& info,
45 DownloadRequestHandleInterface* request_handle, 96 DownloadRequestHandleInterface* request_handle,
46 bool is_otr); 97 bool is_otr);
47 98
48 // Constructing for the "Save Page As..." feature: 99 // Constructing for the "Save Page As..." feature:
49 DownloadItemImpl(DownloadManager* download_manager, 100 DownloadItemImpl(Delegate* delegate,
50 const FilePath& path, 101 const FilePath& path,
51 const GURL& url, 102 const GURL& url,
52 bool is_otr, 103 bool is_otr,
53 DownloadId download_id); 104 DownloadId download_id);
54 105
55 virtual ~DownloadItemImpl(); 106 virtual ~DownloadItemImpl();
56 107
57 // Overridden from DownloadItem. 108 // Overridden from DownloadItem.
58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 109 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 110 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
60 virtual void UpdateObservers() OVERRIDE; 111 virtual void UpdateObservers() OVERRIDE;
61 virtual bool CanShowInFolder() OVERRIDE; 112 virtual bool CanShowInFolder() OVERRIDE;
62 virtual bool CanOpenDownload() OVERRIDE; 113 virtual bool CanOpenDownload() OVERRIDE;
63 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 114 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
64 virtual void OpenDownload() OVERRIDE; 115 virtual void OpenDownload() OVERRIDE;
65 virtual void ShowDownloadInShell() OVERRIDE; 116 virtual void ShowDownloadInShell() OVERRIDE;
66 virtual void DangerousDownloadValidated() OVERRIDE; 117 virtual void DangerousDownloadValidated() OVERRIDE;
67 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; 118 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE;
68 virtual void Cancel(bool user_cancel) OVERRIDE; 119 virtual void Cancel(bool user_cancel) OVERRIDE;
69 virtual void MarkAsComplete() OVERRIDE; 120 virtual void MarkAsComplete() OVERRIDE;
70 virtual void DelayedDownloadOpened() OVERRIDE; 121 virtual void DelayedDownloadOpened() OVERRIDE;
71 virtual void OnAllDataSaved( 122 virtual void OnAllDataSaved(
72 int64 size, const std::string& final_hash) OVERRIDE; 123 int64 size, const std::string& final_hash) OVERRIDE;
73 virtual void OnDownloadedFileRemoved() OVERRIDE; 124 virtual void OnDownloadedFileRemoved() OVERRIDE;
125 virtual void MaybeCompleteDownload() OVERRIDE;
74 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; 126 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE;
75 virtual void Delete(DeleteReason reason) OVERRIDE; 127 virtual void Delete(DeleteReason reason) OVERRIDE;
76 virtual void Remove() OVERRIDE; 128 virtual void Remove() OVERRIDE;
77 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 129 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
78 virtual int64 CurrentSpeed() const OVERRIDE; 130 virtual int64 CurrentSpeed() const OVERRIDE;
79 virtual int PercentComplete() const OVERRIDE; 131 virtual int PercentComplete() const OVERRIDE;
80 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; 132 virtual void OnPathDetermined(const FilePath& path) OVERRIDE;
81 virtual bool AllDataSaved() const OVERRIDE; 133 virtual bool AllDataSaved() const OVERRIDE;
82 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; 134 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE;
83 virtual void Rename(const FilePath& full_path) OVERRIDE; 135 virtual void Rename(const FilePath& full_path) OVERRIDE;
(...skipping 21 matching lines...) Expand all
105 virtual int64 GetTotalBytes() const OVERRIDE; 157 virtual int64 GetTotalBytes() const OVERRIDE;
106 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 158 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
107 virtual const std::string& GetHash() const OVERRIDE; 159 virtual const std::string& GetHash() const OVERRIDE;
108 virtual int64 GetReceivedBytes() const OVERRIDE; 160 virtual int64 GetReceivedBytes() const OVERRIDE;
109 virtual int32 GetId() const OVERRIDE; 161 virtual int32 GetId() const OVERRIDE;
110 virtual DownloadId GetGlobalId() const OVERRIDE; 162 virtual DownloadId GetGlobalId() const OVERRIDE;
111 virtual base::Time GetStartTime() const OVERRIDE; 163 virtual base::Time GetStartTime() const OVERRIDE;
112 virtual base::Time GetEndTime() const OVERRIDE; 164 virtual base::Time GetEndTime() const OVERRIDE;
113 virtual void SetDbHandle(int64 handle) OVERRIDE; 165 virtual void SetDbHandle(int64 handle) OVERRIDE;
114 virtual int64 GetDbHandle() const OVERRIDE; 166 virtual int64 GetDbHandle() const OVERRIDE;
115 virtual DownloadManager* GetDownloadManager() OVERRIDE;
116 virtual bool IsPaused() const OVERRIDE; 167 virtual bool IsPaused() const OVERRIDE;
117 virtual bool GetOpenWhenComplete() const OVERRIDE; 168 virtual bool GetOpenWhenComplete() const OVERRIDE;
118 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 169 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
119 virtual bool GetFileExternallyRemoved() const OVERRIDE; 170 virtual bool GetFileExternallyRemoved() const OVERRIDE;
120 virtual SafetyState GetSafetyState() const OVERRIDE; 171 virtual SafetyState GetSafetyState() const OVERRIDE;
121 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; 172 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE;
122 virtual bool IsDangerous() const OVERRIDE; 173 virtual bool IsDangerous() const OVERRIDE;
123 virtual void MarkFileDangerous() OVERRIDE; 174 virtual void MarkFileDangerous() OVERRIDE;
124 virtual void MarkUrlDangerous() OVERRIDE; 175 virtual void MarkUrlDangerous() OVERRIDE;
125 virtual void MarkContentDangerous() OVERRIDE; 176 virtual void MarkContentDangerous() OVERRIDE;
126 virtual bool GetAutoOpened() OVERRIDE; 177 virtual bool GetAutoOpened() OVERRIDE;
127 virtual const FilePath& GetTargetName() const OVERRIDE; 178 virtual const FilePath& GetTargetName() const OVERRIDE;
128 virtual bool PromptUserForSaveLocation() const OVERRIDE; 179 virtual bool PromptUserForSaveLocation() const OVERRIDE;
129 virtual bool IsOtr() const OVERRIDE; 180 virtual bool IsOtr() const OVERRIDE;
130 virtual const FilePath& GetSuggestedPath() const OVERRIDE; 181 virtual const FilePath& GetSuggestedPath() const OVERRIDE;
131 virtual bool IsTemporary() const OVERRIDE; 182 virtual bool IsTemporary() const OVERRIDE;
132 virtual void SetOpened(bool opened) OVERRIDE; 183 virtual void SetOpened(bool opened) OVERRIDE;
133 virtual bool GetOpened() const OVERRIDE; 184 virtual bool GetOpened() const OVERRIDE;
134 virtual InterruptReason GetLastReason() const OVERRIDE; 185 virtual InterruptReason GetLastReason() const OVERRIDE;
135 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; 186 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE;
136 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; 187 virtual DownloadStateInfo GetStateInfo() const OVERRIDE;
188 virtual content::BrowserContext* BrowserContext() const OVERRIDE;
137 virtual TabContents* GetTabContents() const OVERRIDE; 189 virtual TabContents* GetTabContents() const OVERRIDE;
138 virtual FilePath GetTargetFilePath() const OVERRIDE; 190 virtual FilePath GetTargetFilePath() const OVERRIDE;
139 virtual FilePath GetFileNameToReportUser() const OVERRIDE; 191 virtual FilePath GetFileNameToReportUser() const OVERRIDE;
140 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; 192 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE;
141 virtual bool NeedsRename() const OVERRIDE; 193 virtual bool NeedsRename() const OVERRIDE;
142 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; 194 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE;
143 virtual std::string DebugString(bool verbose) const OVERRIDE; 195 virtual std::string DebugString(bool verbose) const OVERRIDE;
144 virtual void MockDownloadOpenForTesting() OVERRIDE; 196 virtual void MockDownloadOpenForTesting() OVERRIDE;
145 197
146 private: 198 private:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 290
239 // Time the download was started 291 // Time the download was started
240 base::Time start_time_; 292 base::Time start_time_;
241 293
242 // Time the download completed 294 // Time the download completed
243 base::Time end_time_; 295 base::Time end_time_;
244 296
245 // Our persistent store handle 297 // Our persistent store handle
246 int64 db_handle_; 298 int64 db_handle_;
247 299
248 // Our owning object 300 // Our delegate.
249 DownloadManager* download_manager_; 301 Delegate* delegate_;
250 302
251 // In progress downloads may be paused by the user, we note it here 303 // In progress downloads may be paused by the user, we note it here
252 bool is_paused_; 304 bool is_paused_;
253 305
254 // A flag for indicating if the download should be opened at completion. 306 // A flag for indicating if the download should be opened at completion.
255 bool open_when_complete_; 307 bool open_when_complete_;
256 308
257 // A flag for indicating if the downloaded file is externally removed. 309 // A flag for indicating if the downloaded file is externally removed.
258 bool file_externally_removed_; 310 bool file_externally_removed_;
259 311
(...skipping 25 matching lines...) Expand all
285 // only. 337 // only.
286 bool open_enabled_; 338 bool open_enabled_;
287 339
288 // Did the delegate delay calling Complete on this download? 340 // Did the delegate delay calling Complete on this download?
289 bool delegate_delayed_complete_; 341 bool delegate_delayed_complete_;
290 342
291 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 343 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
292 }; 344 };
293 345
294 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 346 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698