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

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: Merged 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 // Delegate is defined in DownloadItemImpl (rather than DownloadItem)
40 // as it's relevant to the class implementation (class methods need to
41 // call into it) and doesn't have anything to do with its interface.
42 // Despite this, the delegate methods take DownloadItems as arguments
43 // (rather than DownloadItemImpls) so that classes that inherit from it
44 // can be used with DownloadItem mocks rather than being tied to
45 // DownloadItemImpls.
46 class Delegate {
47 public:
48 Delegate();
49 virtual ~Delegate();
50
51 // Used for catching use-after-free errors.
52 void Attach();
cbentzel 2011/12/02 20:12:56 I wonder if we want to keep these around for the l
Randy Smith (Not in Mondays) 2011/12/02 20:26:29 Just as much on the fence as I was about putting t
53 void Detach();
54
55 // Tests if a file type should be opened automatically.
56 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) = 0;
57
58 // Allows the delegate to override the opening of a download. If it returns
59 // true then it's reponsible for opening the item.
60 virtual bool ShouldOpenDownload(DownloadItem* download) = 0;
61
62 // Checks whether a downloaded file still exists and updates the
63 // file's state if the file is already removed.
64 // The check may or may not result in a later asynchronous call
65 // to OnDownloadedFileRemoved().
66 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0;
67
68 // If all pre-requisites have been met, complete download processing.
69 // TODO(rdsmith): Move into DownloadItem.
70 virtual void MaybeCompleteDownload(DownloadItem* download) = 0;
71
72 // For contextual issues like language and prefs.
73 virtual content::BrowserContext* BrowserContext() const = 0;
74
75 // Handle any delegate portions of a state change operation on the
76 // DownloadItem.
77 virtual void DownloadCancelled(DownloadItem* download) = 0;
78 virtual void DownloadCompleted(DownloadItem* download) = 0;
79 virtual void DownloadOpened(DownloadItem* download) = 0;
80 virtual void DownloadRemoved(DownloadItem* download) = 0;
81
82 // Assert consistent state for delgate object at various transitions.
83 virtual void AssertStateConsistent(DownloadItem* download) const = 0;
84 private:
cbentzel 2011/12/02 20:12:56 Nit: add an extra newline between AssertStateConsi
Randy Smith (Not in Mondays) 2011/12/02 20:26:29 Done.
85 // For "Outlives attached DownloadItemImpl" invariant assertion.
86 int count_;
87 };
88
89 // Note that it is the responsibility of the caller to ensure that a
90 // DownloadItemImpl::Delegate passed to a DownloadItemImpl constructor
91 // outlives the DownloadItemImpl.
92
37 // Constructing from persistent store: 93 // Constructing from persistent store:
38 DownloadItemImpl(DownloadManager* download_manager, 94 DownloadItemImpl(Delegate* delegate,
95 DownloadId download_id,
39 const DownloadPersistentStoreInfo& info); 96 const DownloadPersistentStoreInfo& info);
40 97
41 // Constructing for a regular download. 98 // Constructing for a regular download.
42 // Takes ownership of the object pointed to by |request_handle|. 99 // Takes ownership of the object pointed to by |request_handle|.
43 DownloadItemImpl(DownloadManager* download_manager, 100 DownloadItemImpl(Delegate* delegate,
44 const DownloadCreateInfo& info, 101 const DownloadCreateInfo& info,
45 DownloadRequestHandleInterface* request_handle, 102 DownloadRequestHandleInterface* request_handle,
46 bool is_otr); 103 bool is_otr);
47 104
48 // Constructing for the "Save Page As..." feature: 105 // Constructing for the "Save Page As..." feature:
49 DownloadItemImpl(DownloadManager* download_manager, 106 DownloadItemImpl(Delegate* delegate,
50 const FilePath& path, 107 const FilePath& path,
51 const GURL& url, 108 const GURL& url,
52 bool is_otr, 109 bool is_otr,
53 DownloadId download_id); 110 DownloadId download_id);
54 111
55 virtual ~DownloadItemImpl(); 112 virtual ~DownloadItemImpl();
56 113
57 // Overridden from DownloadItem. 114 // Overridden from DownloadItem.
58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 115 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 116 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
60 virtual void UpdateObservers() OVERRIDE; 117 virtual void UpdateObservers() OVERRIDE;
61 virtual bool CanShowInFolder() OVERRIDE; 118 virtual bool CanShowInFolder() OVERRIDE;
62 virtual bool CanOpenDownload() OVERRIDE; 119 virtual bool CanOpenDownload() OVERRIDE;
63 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 120 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
64 virtual void OpenDownload() OVERRIDE; 121 virtual void OpenDownload() OVERRIDE;
65 virtual void ShowDownloadInShell() OVERRIDE; 122 virtual void ShowDownloadInShell() OVERRIDE;
66 virtual void DangerousDownloadValidated() OVERRIDE; 123 virtual void DangerousDownloadValidated() OVERRIDE;
67 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; 124 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE;
68 virtual void Cancel(bool user_cancel) OVERRIDE; 125 virtual void Cancel(bool user_cancel) OVERRIDE;
69 virtual void MarkAsComplete() OVERRIDE; 126 virtual void MarkAsComplete() OVERRIDE;
70 virtual void DelayedDownloadOpened() OVERRIDE; 127 virtual void DelayedDownloadOpened() OVERRIDE;
71 virtual void OnAllDataSaved( 128 virtual void OnAllDataSaved(
72 int64 size, const std::string& final_hash) OVERRIDE; 129 int64 size, const std::string& final_hash) OVERRIDE;
73 virtual void OnDownloadedFileRemoved() OVERRIDE; 130 virtual void OnDownloadedFileRemoved() OVERRIDE;
131 virtual void MaybeCompleteDownload() OVERRIDE;
74 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; 132 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE;
75 virtual void Delete(DeleteReason reason) OVERRIDE; 133 virtual void Delete(DeleteReason reason) OVERRIDE;
76 virtual void Remove() OVERRIDE; 134 virtual void Remove() OVERRIDE;
77 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 135 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
78 virtual int64 CurrentSpeed() const OVERRIDE; 136 virtual int64 CurrentSpeed() const OVERRIDE;
79 virtual int PercentComplete() const OVERRIDE; 137 virtual int PercentComplete() const OVERRIDE;
80 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; 138 virtual void OnPathDetermined(const FilePath& path) OVERRIDE;
81 virtual bool AllDataSaved() const OVERRIDE; 139 virtual bool AllDataSaved() const OVERRIDE;
82 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; 140 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE;
83 virtual void Rename(const FilePath& full_path) OVERRIDE; 141 virtual void Rename(const FilePath& full_path) OVERRIDE;
(...skipping 21 matching lines...) Expand all
105 virtual int64 GetTotalBytes() const OVERRIDE; 163 virtual int64 GetTotalBytes() const OVERRIDE;
106 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 164 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
107 virtual const std::string& GetHash() const OVERRIDE; 165 virtual const std::string& GetHash() const OVERRIDE;
108 virtual int64 GetReceivedBytes() const OVERRIDE; 166 virtual int64 GetReceivedBytes() const OVERRIDE;
109 virtual int32 GetId() const OVERRIDE; 167 virtual int32 GetId() const OVERRIDE;
110 virtual DownloadId GetGlobalId() const OVERRIDE; 168 virtual DownloadId GetGlobalId() const OVERRIDE;
111 virtual base::Time GetStartTime() const OVERRIDE; 169 virtual base::Time GetStartTime() const OVERRIDE;
112 virtual base::Time GetEndTime() const OVERRIDE; 170 virtual base::Time GetEndTime() const OVERRIDE;
113 virtual void SetDbHandle(int64 handle) OVERRIDE; 171 virtual void SetDbHandle(int64 handle) OVERRIDE;
114 virtual int64 GetDbHandle() const OVERRIDE; 172 virtual int64 GetDbHandle() const OVERRIDE;
115 virtual DownloadManager* GetDownloadManager() OVERRIDE;
116 virtual bool IsPaused() const OVERRIDE; 173 virtual bool IsPaused() const OVERRIDE;
117 virtual bool GetOpenWhenComplete() const OVERRIDE; 174 virtual bool GetOpenWhenComplete() const OVERRIDE;
118 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 175 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
119 virtual bool GetFileExternallyRemoved() const OVERRIDE; 176 virtual bool GetFileExternallyRemoved() const OVERRIDE;
120 virtual SafetyState GetSafetyState() const OVERRIDE; 177 virtual SafetyState GetSafetyState() const OVERRIDE;
121 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; 178 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE;
122 virtual bool IsDangerous() const OVERRIDE; 179 virtual bool IsDangerous() const OVERRIDE;
123 virtual void MarkFileDangerous() OVERRIDE; 180 virtual void MarkFileDangerous() OVERRIDE;
124 virtual void MarkUrlDangerous() OVERRIDE; 181 virtual void MarkUrlDangerous() OVERRIDE;
125 virtual void MarkContentDangerous() OVERRIDE; 182 virtual void MarkContentDangerous() OVERRIDE;
126 virtual bool GetAutoOpened() OVERRIDE; 183 virtual bool GetAutoOpened() OVERRIDE;
127 virtual const FilePath& GetTargetName() const OVERRIDE; 184 virtual const FilePath& GetTargetName() const OVERRIDE;
128 virtual bool PromptUserForSaveLocation() const OVERRIDE; 185 virtual bool PromptUserForSaveLocation() const OVERRIDE;
129 virtual bool IsOtr() const OVERRIDE; 186 virtual bool IsOtr() const OVERRIDE;
130 virtual const FilePath& GetSuggestedPath() const OVERRIDE; 187 virtual const FilePath& GetSuggestedPath() const OVERRIDE;
131 virtual bool IsTemporary() const OVERRIDE; 188 virtual bool IsTemporary() const OVERRIDE;
132 virtual void SetOpened(bool opened) OVERRIDE; 189 virtual void SetOpened(bool opened) OVERRIDE;
133 virtual bool GetOpened() const OVERRIDE; 190 virtual bool GetOpened() const OVERRIDE;
134 virtual InterruptReason GetLastReason() const OVERRIDE; 191 virtual InterruptReason GetLastReason() const OVERRIDE;
135 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; 192 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE;
136 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; 193 virtual DownloadStateInfo GetStateInfo() const OVERRIDE;
194 virtual content::BrowserContext* BrowserContext() const OVERRIDE;
137 virtual TabContents* GetTabContents() const OVERRIDE; 195 virtual TabContents* GetTabContents() const OVERRIDE;
138 virtual FilePath GetTargetFilePath() const OVERRIDE; 196 virtual FilePath GetTargetFilePath() const OVERRIDE;
139 virtual FilePath GetFileNameToReportUser() const OVERRIDE; 197 virtual FilePath GetFileNameToReportUser() const OVERRIDE;
140 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; 198 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE;
141 virtual bool NeedsRename() const OVERRIDE; 199 virtual bool NeedsRename() const OVERRIDE;
142 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; 200 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE;
143 virtual std::string DebugString(bool verbose) const OVERRIDE; 201 virtual std::string DebugString(bool verbose) const OVERRIDE;
144 virtual void MockDownloadOpenForTesting() OVERRIDE; 202 virtual void MockDownloadOpenForTesting() OVERRIDE;
145 203
146 private: 204 private:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 296
239 // Time the download was started 297 // Time the download was started
240 base::Time start_time_; 298 base::Time start_time_;
241 299
242 // Time the download completed 300 // Time the download completed
243 base::Time end_time_; 301 base::Time end_time_;
244 302
245 // Our persistent store handle 303 // Our persistent store handle
246 int64 db_handle_; 304 int64 db_handle_;
247 305
248 // Our owning object 306 // Our delegate.
249 DownloadManager* download_manager_; 307 Delegate* delegate_;
250 308
251 // In progress downloads may be paused by the user, we note it here 309 // In progress downloads may be paused by the user, we note it here
252 bool is_paused_; 310 bool is_paused_;
253 311
254 // A flag for indicating if the download should be opened at completion. 312 // A flag for indicating if the download should be opened at completion.
255 bool open_when_complete_; 313 bool open_when_complete_;
256 314
257 // A flag for indicating if the downloaded file is externally removed. 315 // A flag for indicating if the downloaded file is externally removed.
258 bool file_externally_removed_; 316 bool file_externally_removed_;
259 317
(...skipping 25 matching lines...) Expand all
285 // only. 343 // only.
286 bool open_enabled_; 344 bool open_enabled_;
287 345
288 // Did the delegate delay calling Complete on this download? 346 // Did the delegate delay calling Complete on this download?
289 bool delegate_delayed_complete_; 347 bool delegate_delayed_complete_;
290 348
291 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 349 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
292 }; 350 };
293 351
294 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 352 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_item.h ('k') | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698