OLD | NEW |
---|---|
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 | |
40 // it doesn't know how to perform. | |
41 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
| |
42 public: | |
43 virtual ~Delegate() {} | |
44 | |
45 // Tests if a file type should be opened automatically. | |
46 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) = 0; | |
47 | |
48 // Allows the delegate to override the opening of a download. If it returns | |
49 // true then it's reponsible for opening the item. | |
50 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
| |
51 | |
52 // Checks whether a downloaded file still exists and updates the | |
53 // file's state if the file is already removed. The check runs in | |
54 // the background and may finish asynchronously after this method returns. | |
55 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0; | |
56 | |
57 // If all pre-requisites have been met, complete download processing. | |
58 // TODO(rdsmith): Move into DownloadItem. | |
59 virtual void MaybeCompleteDownload(DownloadItem* download) = 0; | |
60 | |
61 // For contextual issues like language and prefs. | |
62 virtual content::BrowserContext* BrowserContext() const = 0; | |
63 | |
64 // Handle any delegate portions of a state change operation on the | |
65 // DownloadItem. | |
66 virtual void DownloadCancelled(DownloadItem* download) = 0; | |
67 virtual void DownloadCompleted(DownloadItem* download) = 0; | |
68 virtual void DownloadOpened(DownloadItem* download) = 0; | |
69 virtual void DownloadRemoved(DownloadItem* download) = 0; | |
70 | |
71 // Assert consistent state for delgate object at various transitions. | |
72 virtual void AssertStateConsistent(DownloadItem* download) const = 0; | |
73 }; | |
74 | |
37 // Constructing from persistent store: | 75 // Constructing from persistent store: |
38 DownloadItemImpl(DownloadManager* download_manager, | 76 DownloadItemImpl(Delegate* delegate, |
77 DownloadId download_id, | |
39 const DownloadPersistentStoreInfo& info); | 78 const DownloadPersistentStoreInfo& info); |
40 | 79 |
41 // Constructing for a regular download. | 80 // Constructing for a regular download. |
42 // Takes ownership of the object pointed to by |request_handle|. | 81 // Takes ownership of the object pointed to by |request_handle|. |
43 DownloadItemImpl(DownloadManager* download_manager, | 82 DownloadItemImpl(Delegate* delegate, |
44 const DownloadCreateInfo& info, | 83 const DownloadCreateInfo& info, |
45 DownloadRequestHandleInterface* request_handle, | 84 DownloadRequestHandleInterface* request_handle, |
46 bool is_otr); | 85 bool is_otr); |
47 | 86 |
48 // Constructing for the "Save Page As..." feature: | 87 // Constructing for the "Save Page As..." feature: |
49 DownloadItemImpl(DownloadManager* download_manager, | 88 DownloadItemImpl(Delegate* delegate, |
50 const FilePath& path, | 89 const FilePath& path, |
51 const GURL& url, | 90 const GURL& url, |
52 bool is_otr, | 91 bool is_otr, |
53 DownloadId download_id); | 92 DownloadId download_id); |
54 | 93 |
55 virtual ~DownloadItemImpl(); | 94 virtual ~DownloadItemImpl(); |
56 | 95 |
57 // Overridden from DownloadItem. | 96 // Overridden from DownloadItem. |
58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 97 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 98 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 virtual int64 GetTotalBytes() const OVERRIDE; | 144 virtual int64 GetTotalBytes() const OVERRIDE; |
106 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 145 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
107 virtual const std::string& GetHash() const OVERRIDE; | 146 virtual const std::string& GetHash() const OVERRIDE; |
108 virtual int64 GetReceivedBytes() const OVERRIDE; | 147 virtual int64 GetReceivedBytes() const OVERRIDE; |
109 virtual int32 GetId() const OVERRIDE; | 148 virtual int32 GetId() const OVERRIDE; |
110 virtual DownloadId GetGlobalId() const OVERRIDE; | 149 virtual DownloadId GetGlobalId() const OVERRIDE; |
111 virtual base::Time GetStartTime() const OVERRIDE; | 150 virtual base::Time GetStartTime() const OVERRIDE; |
112 virtual base::Time GetEndTime() const OVERRIDE; | 151 virtual base::Time GetEndTime() const OVERRIDE; |
113 virtual void SetDbHandle(int64 handle) OVERRIDE; | 152 virtual void SetDbHandle(int64 handle) OVERRIDE; |
114 virtual int64 GetDbHandle() const OVERRIDE; | 153 virtual int64 GetDbHandle() const OVERRIDE; |
115 virtual DownloadManager* GetDownloadManager() OVERRIDE; | |
116 virtual bool IsPaused() const OVERRIDE; | 154 virtual bool IsPaused() const OVERRIDE; |
117 virtual bool GetOpenWhenComplete() const OVERRIDE; | 155 virtual bool GetOpenWhenComplete() const OVERRIDE; |
118 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 156 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
119 virtual bool GetFileExternallyRemoved() const OVERRIDE; | 157 virtual bool GetFileExternallyRemoved() const OVERRIDE; |
120 virtual SafetyState GetSafetyState() const OVERRIDE; | 158 virtual SafetyState GetSafetyState() const OVERRIDE; |
121 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; | 159 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; |
122 virtual bool IsDangerous() const OVERRIDE; | 160 virtual bool IsDangerous() const OVERRIDE; |
123 virtual void MarkFileDangerous() OVERRIDE; | 161 virtual void MarkFileDangerous() OVERRIDE; |
124 virtual void MarkUrlDangerous() OVERRIDE; | 162 virtual void MarkUrlDangerous() OVERRIDE; |
125 virtual void MarkContentDangerous() OVERRIDE; | 163 virtual void MarkContentDangerous() OVERRIDE; |
126 virtual bool GetAutoOpened() OVERRIDE; | 164 virtual bool GetAutoOpened() OVERRIDE; |
127 virtual const FilePath& GetTargetName() const OVERRIDE; | 165 virtual const FilePath& GetTargetName() const OVERRIDE; |
128 virtual bool PromptUserForSaveLocation() const OVERRIDE; | 166 virtual bool PromptUserForSaveLocation() const OVERRIDE; |
129 virtual bool IsOtr() const OVERRIDE; | 167 virtual bool IsOtr() const OVERRIDE; |
130 virtual const FilePath& GetSuggestedPath() const OVERRIDE; | 168 virtual const FilePath& GetSuggestedPath() const OVERRIDE; |
131 virtual bool IsTemporary() const OVERRIDE; | 169 virtual bool IsTemporary() const OVERRIDE; |
132 virtual void SetOpened(bool opened) OVERRIDE; | 170 virtual void SetOpened(bool opened) OVERRIDE; |
133 virtual bool GetOpened() const OVERRIDE; | 171 virtual bool GetOpened() const OVERRIDE; |
134 virtual InterruptReason GetLastReason() const OVERRIDE; | 172 virtual InterruptReason GetLastReason() const OVERRIDE; |
135 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; | 173 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; |
136 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; | 174 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; |
175 virtual content::BrowserContext* BrowserContext() const OVERRIDE; | |
137 virtual TabContents* GetTabContents() const OVERRIDE; | 176 virtual TabContents* GetTabContents() const OVERRIDE; |
138 virtual FilePath GetTargetFilePath() const OVERRIDE; | 177 virtual FilePath GetTargetFilePath() const OVERRIDE; |
139 virtual FilePath GetFileNameToReportUser() const OVERRIDE; | 178 virtual FilePath GetFileNameToReportUser() const OVERRIDE; |
140 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; | 179 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; |
141 virtual bool NeedsRename() const OVERRIDE; | 180 virtual bool NeedsRename() const OVERRIDE; |
142 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; | 181 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; |
143 virtual std::string DebugString(bool verbose) const OVERRIDE; | 182 virtual std::string DebugString(bool verbose) const OVERRIDE; |
144 virtual void MockDownloadOpenForTesting() OVERRIDE; | 183 virtual void MockDownloadOpenForTesting() OVERRIDE; |
145 | 184 |
146 private: | 185 private: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 274 |
236 // Time the download was started | 275 // Time the download was started |
237 base::Time start_time_; | 276 base::Time start_time_; |
238 | 277 |
239 // Time the download completed | 278 // Time the download completed |
240 base::Time end_time_; | 279 base::Time end_time_; |
241 | 280 |
242 // Our persistent store handle | 281 // Our persistent store handle |
243 int64 db_handle_; | 282 int64 db_handle_; |
244 | 283 |
245 // Our owning object | 284 // Our delegate. |
246 DownloadManager* download_manager_; | 285 Delegate* delegate_; |
247 | 286 |
248 // In progress downloads may be paused by the user, we note it here | 287 // In progress downloads may be paused by the user, we note it here |
249 bool is_paused_; | 288 bool is_paused_; |
250 | 289 |
251 // A flag for indicating if the download should be opened at completion. | 290 // A flag for indicating if the download should be opened at completion. |
252 bool open_when_complete_; | 291 bool open_when_complete_; |
253 | 292 |
254 // A flag for indicating if the downloaded file is externally removed. | 293 // A flag for indicating if the downloaded file is externally removed. |
255 bool file_externally_removed_; | 294 bool file_externally_removed_; |
256 | 295 |
(...skipping 25 matching lines...) Expand all Loading... | |
282 // only. | 321 // only. |
283 bool open_enabled_; | 322 bool open_enabled_; |
284 | 323 |
285 // Did the delegate delay calling Complete on this download? | 324 // Did the delegate delay calling Complete on this download? |
286 bool delegate_delayed_complete_; | 325 bool delegate_delayed_complete_; |
287 | 326 |
288 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 327 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
289 }; | 328 }; |
290 | 329 |
291 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 330 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
OLD | NEW |