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

Side by Side Diff: content/browser/download/download_item.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 // Each download is represented by a DownloadItem, and all DownloadItems 5 // Each download is represented by a DownloadItem, and all DownloadItems
6 // are owned by the DownloadManager which maintains a global list of all 6 // are owned by the DownloadManager which maintains a global list of all
7 // downloads. DownloadItems are created when a user initiates a download, 7 // downloads. DownloadItems are created when a user initiates a download,
8 // and exist for the duration of the browser life time. 8 // and exist for the duration of the browser life time.
9 // 9 //
10 // Download observers: 10 // Download observers:
11 // DownloadItem::Observer: 11 // DownloadItem::Observer:
12 // - allows observers to receive notifications about one download from start 12 // - allows observers to receive notifications about one download from start
13 // to completion 13 // to completion
14 // Use AddObserver() / RemoveObserver() on the appropriate download object to 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to
15 // receive state updates. 15 // receive state updates.
16 16
17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
19 #pragma once 19 #pragma once
20 20
21 #include <string> 21 #include <string>
22 22
23 #include "base/string16.h" 23 #include "base/string16.h"
24 #include "content/browser/download/download_id.h"
cbentzel 2011/12/02 18:00:52 Why does this need to be included instead of forwa
Randy Smith (Not in Mondays) 2011/12/02 20:04:12 Well, I would have thought a by-value return of th
24 #include "content/browser/download/download_state_info.h" 25 #include "content/browser/download/download_state_info.h"
25 #include "content/browser/download/interrupt_reasons.h" 26 #include "content/browser/download/interrupt_reasons.h"
26 27
27 class DownloadFileManager; 28 class DownloadFileManager;
28 class DownloadId;
29 class DownloadManager; 29 class DownloadManager;
30 class FilePath; 30 class FilePath;
31 class GURL; 31 class GURL;
32 class TabContents; 32 class TabContents;
33 struct DownloadCreateInfo; 33 struct DownloadCreateInfo;
34 struct DownloadPersistentStoreInfo; 34 struct DownloadPersistentStoreInfo;
35 namespace base { 35 namespace base {
36 class Time; 36 class Time;
37 class TimeDelta; 37 class TimeDelta;
38 } 38 }
39 39
40 namespace content {
41 class BrowserContext;
42 }
43
40 // One DownloadItem per download. This is the model class that stores all the 44 // One DownloadItem per download. This is the model class that stores all the
41 // state for a download. Multiple views, such as a tab's download shelf and the 45 // state for a download. Multiple views, such as a tab's download shelf and the
42 // Destination tab's download view, may refer to a given DownloadItem. 46 // Destination tab's download view, may refer to a given DownloadItem.
43 // 47 //
44 // This is intended to be used only on the UI thread. 48 // This is intended to be used only on the UI thread.
45 class CONTENT_EXPORT DownloadItem { 49 class CONTENT_EXPORT DownloadItem {
46 public: 50 public:
47 enum DownloadState { 51 enum DownloadState {
48 // Download is actively progressing. 52 // Download is actively progressing.
49 IN_PROGRESS = 0, 53 IN_PROGRESS = 0,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Called by the delegate after it delayed opening the download in 150 // Called by the delegate after it delayed opening the download in
147 // DownloadManagerDelegate::ShouldOpenDownload. 151 // DownloadManagerDelegate::ShouldOpenDownload.
148 virtual void DelayedDownloadOpened() = 0; 152 virtual void DelayedDownloadOpened() = 0;
149 153
150 // Called when all data has been saved. Only has display effects. 154 // Called when all data has been saved. Only has display effects.
151 virtual void OnAllDataSaved(int64 size, const std::string& final_hash) = 0; 155 virtual void OnAllDataSaved(int64 size, const std::string& final_hash) = 0;
152 156
153 // Called when the downloaded file is removed. 157 // Called when the downloaded file is removed.
154 virtual void OnDownloadedFileRemoved() = 0; 158 virtual void OnDownloadedFileRemoved() = 0;
155 159
160 // If all pre-requisites have been met, complete download processing, i.e.
161 // do internal cleanup, file rename, and potentially auto-open.
162 // (Dangerous downloads still may block on user acceptance after this
163 // point.)
164 virtual void MaybeCompleteDownload() = 0;
165
156 // Download operation had an error. 166 // Download operation had an error.
157 // |size| is the amount of data received at interruption. 167 // |size| is the amount of data received at interruption.
158 // |reason| is the download interrupt reason code that the operation received. 168 // |reason| is the download interrupt reason code that the operation received.
159 virtual void Interrupted(int64 size, InterruptReason reason) = 0; 169 virtual void Interrupted(int64 size, InterruptReason reason) = 0;
160 170
161 // Deletes the file from disk and removes the download from the views and 171 // Deletes the file from disk and removes the download from the views and
162 // history. |user| should be true if this is the result of the user clicking 172 // history. |user| should be true if this is the result of the user clicking
163 // the discard button, and false if it is being deleted for other reasons like 173 // the discard button, and false if it is being deleted for other reasons like
164 // browser shutdown. 174 // browser shutdown.
165 virtual void Delete(DeleteReason reason) = 0; 175 virtual void Delete(DeleteReason reason) = 0;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 virtual std::string GetReferrerCharset() const = 0; 250 virtual std::string GetReferrerCharset() const = 0;
241 virtual int64 GetTotalBytes() const = 0; 251 virtual int64 GetTotalBytes() const = 0;
242 virtual void SetTotalBytes(int64 total_bytes) = 0; 252 virtual void SetTotalBytes(int64 total_bytes) = 0;
243 virtual int64 GetReceivedBytes() const = 0; 253 virtual int64 GetReceivedBytes() const = 0;
244 virtual int32 GetId() const = 0; 254 virtual int32 GetId() const = 0;
245 virtual DownloadId GetGlobalId() const = 0; 255 virtual DownloadId GetGlobalId() const = 0;
246 virtual base::Time GetStartTime() const = 0; 256 virtual base::Time GetStartTime() const = 0;
247 virtual base::Time GetEndTime() const = 0; 257 virtual base::Time GetEndTime() const = 0;
248 virtual void SetDbHandle(int64 handle) = 0; 258 virtual void SetDbHandle(int64 handle) = 0;
249 virtual int64 GetDbHandle() const = 0; 259 virtual int64 GetDbHandle() const = 0;
250 virtual DownloadManager* GetDownloadManager() = 0;
251 virtual bool IsPaused() const = 0; 260 virtual bool IsPaused() const = 0;
252 virtual bool GetOpenWhenComplete() const = 0; 261 virtual bool GetOpenWhenComplete() const = 0;
253 virtual void SetOpenWhenComplete(bool open) = 0; 262 virtual void SetOpenWhenComplete(bool open) = 0;
254 virtual bool GetFileExternallyRemoved() const = 0; 263 virtual bool GetFileExternallyRemoved() const = 0;
255 virtual SafetyState GetSafetyState() const = 0; 264 virtual SafetyState GetSafetyState() const = 0;
256 // Why |safety_state_| is not SAFE. 265 // Why |safety_state_| is not SAFE.
257 virtual DownloadStateInfo::DangerType GetDangerType() const = 0; 266 virtual DownloadStateInfo::DangerType GetDangerType() const = 0;
258 virtual bool IsDangerous() const = 0; 267 virtual bool IsDangerous() const = 0;
259 virtual void MarkContentDangerous() = 0; 268 virtual void MarkContentDangerous() = 0;
260 virtual void MarkFileDangerous() = 0; 269 virtual void MarkFileDangerous() = 0;
261 virtual void MarkUrlDangerous() = 0; 270 virtual void MarkUrlDangerous() = 0;
262 271
263 virtual bool GetAutoOpened() = 0; 272 virtual bool GetAutoOpened() = 0;
264 virtual const FilePath& GetTargetName() const = 0; 273 virtual const FilePath& GetTargetName() const = 0;
265 virtual bool PromptUserForSaveLocation() const = 0; 274 virtual bool PromptUserForSaveLocation() const = 0;
266 virtual bool IsOtr() const = 0; 275 virtual bool IsOtr() const = 0;
267 virtual const FilePath& GetSuggestedPath() const = 0; 276 virtual const FilePath& GetSuggestedPath() const = 0;
268 virtual bool IsTemporary() const = 0; 277 virtual bool IsTemporary() const = 0;
269 virtual void SetOpened(bool opened) = 0; 278 virtual void SetOpened(bool opened) = 0;
270 virtual bool GetOpened() const = 0; 279 virtual bool GetOpened() const = 0;
271 280
272 virtual InterruptReason GetLastReason() const = 0; 281 virtual InterruptReason GetLastReason() const = 0;
273 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const = 0; 282 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const = 0;
274 virtual DownloadStateInfo GetStateInfo() const = 0; 283 virtual DownloadStateInfo GetStateInfo() const = 0;
284 virtual content::BrowserContext* BrowserContext() const = 0;
275 virtual TabContents* GetTabContents() const = 0; 285 virtual TabContents* GetTabContents() const = 0;
276 286
277 // Returns the final target file path for the download. 287 // Returns the final target file path for the download.
278 virtual FilePath GetTargetFilePath() const = 0; 288 virtual FilePath GetTargetFilePath() const = 0;
279 289
280 // Returns the file-name that should be reported to the user, which is 290 // Returns the file-name that should be reported to the user, which is
281 // target_name possibly with the uniquifier number. 291 // target_name possibly with the uniquifier number.
282 virtual FilePath GetFileNameToReportUser() const = 0; 292 virtual FilePath GetFileNameToReportUser() const = 0;
283 293
284 // Returns the user-verified target file path for the download. 294 // Returns the user-verified target file path for the download.
(...skipping 11 matching lines...) Expand all
296 // DownloadManager::FileSelectionCancelled() without doing some 306 // DownloadManager::FileSelectionCancelled() without doing some
297 // rewrites of the DownloadManager queues. 307 // rewrites of the DownloadManager queues.
298 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; 308 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0;
299 309
300 virtual std::string DebugString(bool verbose) const = 0; 310 virtual std::string DebugString(bool verbose) const = 0;
301 311
302 virtual void MockDownloadOpenForTesting() = 0; 312 virtual void MockDownloadOpenForTesting() = 0;
303 }; 313 };
304 314
305 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 315 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698