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 // 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/basictypes.h" | 23 #include "base/string16.h" |
24 #include "base/file_path.h" | |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "base/observer_list.h" | |
27 #include "base/time.h" | |
28 #include "content/browser/download/download_id.h" | |
29 #include "content/browser/download/download_request_handle.h" | |
30 #include "content/browser/download/download_state_info.h" | 24 #include "content/browser/download/download_state_info.h" |
31 #include "content/browser/download/interrupt_reasons.h" | 25 #include "content/browser/download/interrupt_reasons.h" |
32 #include "content/common/content_export.h" | |
33 #include "googleurl/src/gurl.h" | |
34 #include "net/base/net_errors.h" | |
35 | 26 |
27 namespace base { | |
cbentzel
2011/11/16 12:28:44
Nit: forward declarations in a namespace come afte
benjhayden
2011/11/18 18:59:34
Done.
| |
28 class Time; | |
29 class TimeDelta; | |
30 } | |
36 class DownloadFileManager; | 31 class DownloadFileManager; |
37 class DownloadId; | 32 class DownloadId; |
38 class DownloadManager; | 33 class DownloadManager; |
34 class FilePath; | |
35 class GURL; | |
39 class TabContents; | 36 class TabContents; |
40 | |
41 struct DownloadCreateInfo; | 37 struct DownloadCreateInfo; |
42 struct DownloadPersistentStoreInfo; | 38 struct DownloadPersistentStoreInfo; |
43 | 39 |
44 // One DownloadItem per download. This is the model class that stores all the | 40 // One DownloadItem per download. This is the model class that stores all the |
45 // state for a download. Multiple views, such as a tab's download shelf and the | 41 // state for a download. Multiple views, such as a tab's download shelf and the |
46 // Destination tab's download view, may refer to a given DownloadItem. | 42 // Destination tab's download view, may refer to a given DownloadItem. |
47 // | 43 // |
48 // This is intended to be used only on the UI thread. | 44 // This is intended to be used only on the UI thread. |
49 class CONTENT_EXPORT DownloadItem { | 45 class CONTENT_EXPORT DownloadItem { |
50 public: | 46 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 public: | 106 public: |
111 virtual void OnDownloadUpdated(DownloadItem* download) = 0; | 107 virtual void OnDownloadUpdated(DownloadItem* download) = 0; |
112 | 108 |
113 // Called when a downloaded file has been opened. | 109 // Called when a downloaded file has been opened. |
114 virtual void OnDownloadOpened(DownloadItem* download) = 0; | 110 virtual void OnDownloadOpened(DownloadItem* download) = 0; |
115 | 111 |
116 protected: | 112 protected: |
117 virtual ~Observer() {} | 113 virtual ~Observer() {} |
118 }; | 114 }; |
119 | 115 |
120 // Constructing from persistent store: | |
121 DownloadItem(DownloadManager* download_manager, | |
122 const DownloadPersistentStoreInfo& info); | |
123 | |
124 // Constructing for a regular download. | |
125 // Takes ownership of the object pointed to by |request_handle|. | |
126 DownloadItem(DownloadManager* download_manager, | |
127 const DownloadCreateInfo& info, | |
128 DownloadRequestHandleInterface* request_handle, | |
129 bool is_otr); | |
130 | |
131 // Constructing for the "Save Page As..." feature: | |
132 DownloadItem(DownloadManager* download_manager, | |
133 const FilePath& path, | |
134 const GURL& url, | |
135 bool is_otr, | |
136 DownloadId download_id); | |
137 | |
138 virtual ~DownloadItem(); | 116 virtual ~DownloadItem(); |
139 | 117 |
140 void AddObserver(Observer* observer); | 118 virtual void AddObserver(DownloadItem::Observer* observer) = 0; |
141 void RemoveObserver(Observer* observer); | 119 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; |
142 | 120 |
143 // Notifies our observers periodically. | 121 // Notifies our observers periodically. |
144 void UpdateObservers(); | 122 virtual void UpdateObservers() = 0; |
145 | 123 |
146 // Returns true if it is OK to open a folder which this file is inside. | 124 // Returns true if it is OK to open a folder which this file is inside. |
147 bool CanShowInFolder(); | 125 virtual bool CanShowInFolder() = 0; |
148 | 126 |
149 // Returns true if it is OK to register the type of this file so that | 127 // Returns true if it is OK to register the type of this file so that |
150 // it opens automatically. | 128 // it opens automatically. |
151 bool CanOpenDownload(); | 129 virtual bool CanOpenDownload() = 0; |
152 | 130 |
153 // Tests if a file type should be opened automatically. | 131 // Tests if a file type should be opened automatically. |
154 bool ShouldOpenFileBasedOnExtension(); | 132 virtual bool ShouldOpenFileBasedOnExtension() = 0; |
155 | 133 |
156 // Open the file associated with this download (wait for the download to | 134 // Open the file associated with this download (wait for the download to |
157 // complete if it is in progress). | 135 // complete if it is in progress). |
158 void OpenDownload(); | 136 virtual void OpenDownload() = 0; |
159 | 137 |
160 // Show the download via the OS shell. | 138 // Show the download via the OS shell. |
161 void ShowDownloadInShell(); | 139 virtual void ShowDownloadInShell() = 0; |
162 | 140 |
163 // Called when the user has validated the download of a dangerous file. | 141 // Called when the user has validated the download of a dangerous file. |
164 void DangerousDownloadValidated(); | 142 virtual void DangerousDownloadValidated() = 0; |
165 | 143 |
166 // Received a new chunk of data | 144 // Received a new chunk of data |
167 void Update(int64 bytes_so_far); | 145 virtual void Update(int64 bytes_so_far) = 0; |
168 | 146 |
169 // Cancel the download operation. We need to distinguish between cancels at | 147 // Cancel the download operation. We need to distinguish between cancels at |
170 // exit (DownloadManager destructor) from user interface initiated cancels | 148 // exit (DownloadManager destructor) from user interface initiated cancels |
171 // because at exit, the history system may not exist, and any updates to it | 149 // because at exit, the history system may not exist, and any updates to it |
172 // require AddRef'ing the DownloadManager in the destructor which results in | 150 // require AddRef'ing the DownloadManager in the destructor which results in |
173 // a DCHECK failure. Set |user_cancel| to false when canceling from at | 151 // a DCHECK failure. Set |user_cancel| to false when canceling from at |
174 // exit to prevent this crash. This may result in a difference between the | 152 // exit to prevent this crash. This may result in a difference between the |
175 // downloaded file's size on disk, and what the history system's last record | 153 // downloaded file's size on disk, and what the history system's last record |
176 // of it is. At worst, we'll end up re-downloading a small portion of the file | 154 // of it is. At worst, we'll end up re-downloading a small portion of the file |
177 // when resuming a download (assuming the server supports byte ranges). | 155 // when resuming a download (assuming the server supports byte ranges). |
178 void Cancel(bool user_cancel); | 156 virtual void Cancel(bool user_cancel) = 0; |
179 | 157 |
180 // Called by external code (SavePackage) using the DownloadItem interface | 158 // Called by external code (SavePackage) using the DownloadItem interface |
181 // to display progress when the DownloadItem should be considered complete. | 159 // to display progress when the DownloadItem should be considered complete. |
182 void MarkAsComplete(); | 160 virtual void MarkAsComplete() = 0; |
183 | 161 |
184 // Called by the delegate after it delayed opening the download in | 162 // Called by the delegate after it delayed opening the download in |
185 // DownloadManagerDelegate::ShouldOpenDownload. | 163 // DownloadManagerDelegate::ShouldOpenDownload. |
186 void DelayedDownloadOpened(); | 164 virtual void DelayedDownloadOpened() = 0; |
187 | 165 |
188 // Called when all data has been saved. | 166 // Called when all data has been saved. Only has display effects. |
189 void OnAllDataSaved(int64 size, const std::string& final_hash); | 167 virtual void OnAllDataSaved(int64 size, const std::string& final_hash) = 0; |
190 | 168 |
191 // Called when the downloaded file is removed. | 169 // Called when the downloaded file is removed. |
192 void OnDownloadedFileRemoved(); | 170 virtual void OnDownloadedFileRemoved() = 0; |
193 | 171 |
194 // Download operation had an error. | 172 // Download operation had an error. |
195 // |size| is the amount of data received at interruption. | 173 // |size| is the amount of data received at interruption. |
196 // |reason| is the download interrupt reason code that the operation received. | 174 // |reason| is the download interrupt reason code that the operation received. |
197 void Interrupted(int64 size, InterruptReason reason); | 175 virtual void Interrupted(int64 size, InterruptReason reason) = 0; |
198 | 176 |
199 // Deletes the file from disk and removes the download from the views and | 177 // Deletes the file from disk and removes the download from the views and |
200 // history. |user| should be true if this is the result of the user clicking | 178 // history. |user| should be true if this is the result of the user clicking |
201 // the discard button, and false if it is being deleted for other reasons like | 179 // the discard button, and false if it is being deleted for other reasons like |
202 // browser shutdown. | 180 // browser shutdown. |
203 void Delete(DeleteReason reason); | 181 virtual void Delete(DeleteReason reason) = 0; |
204 | 182 |
205 // Removes the download from the views and history. | 183 // Removes the download from the views and history. |
206 void Remove(); | 184 virtual void Remove() = 0; |
207 | 185 |
208 // Simple calculation of the amount of time remaining to completion. Fills | 186 // Simple calculation of the amount of time remaining to completion. Fills |
209 // |*remaining| with the amount of time remaining if successful. Fails and | 187 // |*remaining| with the amount of time remaining if successful. Fails and |
210 // returns false if we do not have the number of bytes or the speed so can | 188 // returns false if we do not have the number of bytes or the speed so can |
211 // not estimate. | 189 // not estimate. |
212 bool TimeRemaining(base::TimeDelta* remaining) const; | 190 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0; |
213 | 191 |
214 // Simple speed estimate in bytes/s | 192 // Simple speed estimate in bytes/s |
215 int64 CurrentSpeed() const; | 193 virtual int64 CurrentSpeed() const = 0; |
216 | 194 |
217 // Rough percent complete, -1 means we don't know (since we didn't receive a | 195 // Rough percent complete, -1 means we don't know (since we didn't receive a |
218 // total size). | 196 // total size). |
219 int PercentComplete() const; | 197 virtual int PercentComplete() const = 0; |
220 | 198 |
221 // Called when the final path has been determined. | 199 // Called when the final path has been determined. |
222 void OnPathDetermined(const FilePath& path); | 200 virtual void OnPathDetermined(const FilePath& path) = 0; |
223 | 201 |
224 // Returns true if this download has saved all of its data. | 202 // Returns true if this download has saved all of its data. |
225 bool all_data_saved() const { return all_data_saved_; } | 203 virtual bool AllDataSaved() const = 0; |
226 | 204 |
227 // Update the fields that may have changed in DownloadStateInfo as a | 205 // Update the fields that may have changed in DownloadStateInfo as a |
228 // result of analyzing the file and figuring out its type, location, etc. | 206 // result of analyzing the file and figuring out its type, location, etc. |
229 // May only be called once. | 207 // May only be called once. |
230 void SetFileCheckResults(const DownloadStateInfo& state); | 208 virtual void SetFileCheckResults(const DownloadStateInfo& state) = 0; |
231 | 209 |
232 // Update the download's path, the actual file is renamed on the download | 210 // Update the download's path, the actual file is renamed on the download |
233 // thread. | 211 // thread. |
234 void Rename(const FilePath& full_path); | 212 virtual void Rename(const FilePath& full_path) = 0; |
235 | 213 |
236 // Allow the user to temporarily pause a download or resume a paused download. | 214 // Allow the user to temporarily pause a download or resume a paused download. |
237 void TogglePause(); | 215 virtual void TogglePause() = 0; |
238 | 216 |
239 // Called when the download is ready to complete. | 217 // Called when the download is ready to complete. |
240 // This may perform final rename if necessary and will eventually call | 218 // This may perform final rename if necessary and will eventually call |
241 // DownloadItem::Completed(). | 219 // DownloadItem::Completed(). |
242 void OnDownloadCompleting(DownloadFileManager* file_manager); | 220 virtual void OnDownloadCompleting(DownloadFileManager* file_manager) = 0; |
243 | 221 |
244 // Called when the file name for the download is renamed to its final name. | 222 // Called when the file name for the download is renamed to its final name. |
245 void OnDownloadRenamedToFinalName(const FilePath& full_path); | 223 virtual void OnDownloadRenamedToFinalName(const FilePath& full_path) = 0; |
246 | 224 |
247 // Returns true if this item matches |query|. |query| must be lower-cased. | 225 // Returns true if this item matches |query|. |query| must be lower-cased. |
248 bool MatchesQuery(const string16& query) const; | 226 virtual bool MatchesQuery(const string16& query) const = 0; |
249 | 227 |
250 // Returns true if the download needs more data. | 228 // Returns true if the download needs more data. |
251 bool IsPartialDownload() const; | 229 virtual bool IsPartialDownload() const = 0; |
252 | 230 |
253 // Returns true if the download is still receiving data. | 231 // Returns true if the download is still receiving data. |
254 bool IsInProgress() const; | 232 virtual bool IsInProgress() const = 0; |
255 | 233 |
256 // Returns true if the download has been cancelled or was interrupted. | 234 // Returns true if the download has been cancelled or was interrupted. |
257 bool IsCancelled() const; | 235 virtual bool IsCancelled() const = 0; |
258 | 236 |
259 // Returns true if the download was interrupted. | 237 // Returns true if the download was interrupted. |
260 bool IsInterrupted() const; | 238 virtual bool IsInterrupted() const = 0; |
261 | 239 |
262 // Returns true if we have all the data and know the final file name. | 240 // Returns true if we have all the data and know the final file name. |
263 bool IsComplete() const; | 241 virtual bool IsComplete() const = 0; |
264 | 242 |
265 // Accessors | 243 // Accessors |
266 DownloadState state() const { return state_; } | 244 virtual const std::string& GetHash() const = 0; |
267 const FilePath& full_path() const { return full_path_; } | 245 virtual DownloadState GetState() const = 0; |
268 void set_path_uniquifier(int uniquifier) { | 246 virtual const FilePath& GetFullPath() const = 0; |
269 state_info_.path_uniquifier = uniquifier; | 247 virtual void SetPathUniquifier(int uniquifier) = 0; |
270 } | 248 virtual const GURL& GetURL() const = 0; |
271 const GURL& GetURL() const; | 249 virtual const std::vector<GURL>& GetUrlChain() const = 0; |
250 virtual const GURL& GetOriginalUrl() const = 0; | |
251 virtual const GURL& GetReferrerUrl() const = 0; | |
252 virtual std::string GetSuggestedFilename() const = 0; | |
253 virtual std::string GetContentDisposition() const = 0; | |
254 virtual std::string GetMimeType() const = 0; | |
255 virtual std::string GetOriginalMimeType() const = 0; | |
256 virtual std::string GetReferrerCharset() const = 0; | |
257 virtual int64 GetTotalBytes() const = 0; | |
258 virtual void SetTotalBytes(int64 total_bytes) = 0; | |
259 virtual int64 GetReceivedBytes() const = 0; | |
260 virtual int32 GetId() const = 0; | |
261 virtual DownloadId GetGlobalId() const = 0; | |
262 virtual base::Time GetStartTime() const = 0; | |
263 virtual base::Time GetEndTime() const = 0; | |
264 virtual void SetDbHandle(int64 handle) = 0; | |
265 virtual int64 GetDbHandle() const = 0; | |
266 virtual DownloadManager* GetDownloadManager() = 0; | |
267 virtual bool IsPaused() const = 0; | |
268 virtual bool GetOpenWhenComplete() const = 0; | |
269 virtual void SetOpenWhenComplete(bool open) = 0; | |
270 virtual bool GetFileExternallyRemoved() const = 0; | |
271 virtual SafetyState GetSafetyState() const = 0; | |
272 // Why |safety_state_| is not SAFE. | |
273 virtual DangerType GetDangerType() const = 0; | |
274 virtual bool IsDangerous() const = 0; | |
275 virtual void MarkFileDangerous() = 0; | |
276 virtual void MarkUrlDangerous() = 0; | |
272 | 277 |
273 const std::vector<GURL>& url_chain() const { return url_chain_; } | 278 virtual bool GetAutoOpened() = 0; |
274 const GURL& original_url() const { return url_chain_.front(); } | 279 virtual const FilePath& GetTargetName() const = 0; |
275 const GURL& referrer_url() const { return referrer_url_; } | 280 virtual bool PromptUserForSaveLocation() const = 0; |
276 std::string suggested_filename() const { return suggested_filename_; } | 281 virtual bool IsOtr() const = 0; |
277 std::string content_disposition() const { return content_disposition_; } | 282 virtual const FilePath& GetSuggestedPath() const = 0; |
278 std::string mime_type() const { return mime_type_; } | 283 virtual bool IsTemporary() const = 0; |
279 std::string original_mime_type() const { return original_mime_type_; } | 284 virtual void SetOpened(bool opened) = 0; |
280 std::string referrer_charset() const { return referrer_charset_; } | 285 virtual bool GetOpened() const = 0; |
281 int64 total_bytes() const { return total_bytes_; } | |
282 void set_total_bytes(int64 total_bytes) { | |
283 total_bytes_ = total_bytes; | |
284 } | |
285 int64 received_bytes() const { return received_bytes_; } | |
286 const std::string& hash() const { return hash_; } | |
287 int32 id() const { return download_id_.local(); } | |
288 DownloadId global_id() const { return download_id_; } | |
289 base::Time start_time() const { return start_time_; } | |
290 base::Time end_time() const { return end_time_; } | |
291 void set_db_handle(int64 handle) { db_handle_ = handle; } | |
292 int64 db_handle() const { return db_handle_; } | |
293 DownloadManager* download_manager() { return download_manager_; } | |
294 bool is_paused() const { return is_paused_; } | |
295 bool open_when_complete() const { return open_when_complete_; } | |
296 void set_open_when_complete(bool open) { open_when_complete_ = open; } | |
297 bool file_externally_removed() const { return file_externally_removed_; } | |
298 SafetyState safety_state() const { return safety_state_; } | |
299 // Why |safety_state_| is not SAFE. | |
300 DangerType GetDangerType() const; | |
301 bool IsDangerous() const; | |
302 void MarkFileDangerous(); | |
303 void MarkUrlDangerous(); | |
304 | 286 |
305 bool auto_opened() { return auto_opened_; } | 287 virtual InterruptReason GetLastReason() const = 0; |
306 const FilePath& target_name() const { return state_info_.target_name; } | 288 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const = 0; |
307 bool prompt_user_for_save_location() const { | 289 virtual DownloadStateInfo GetStateInfo() const = 0; |
308 return state_info_.prompt_user_for_save_location; | 290 virtual TabContents* GetTabContents() const = 0; |
309 } | |
310 bool is_otr() const { return is_otr_; } | |
311 const FilePath& suggested_path() const { return state_info_.suggested_path; } | |
312 bool is_temporary() const { return is_temporary_; } | |
313 void set_opened(bool opened) { opened_ = opened; } | |
314 bool opened() const { return opened_; } | |
315 | |
316 InterruptReason last_reason() const { return last_reason_; } | |
317 | |
318 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; | |
319 DownloadStateInfo state_info() const { return state_info_; } | |
320 | |
321 TabContents* GetTabContents() const; | |
322 | 291 |
323 // Returns the final target file path for the download. | 292 // Returns the final target file path for the download. |
324 FilePath GetTargetFilePath() const; | 293 virtual FilePath GetTargetFilePath() const = 0; |
325 | 294 |
326 // Returns the file-name that should be reported to the user, which is | 295 // Returns the file-name that should be reported to the user, which is |
327 // target_name possibly with the uniquifier number. | 296 // target_name possibly with the uniquifier number. |
328 FilePath GetFileNameToReportUser() const; | 297 virtual FilePath GetFileNameToReportUser() const = 0; |
329 | 298 |
330 // Returns the user-verified target file path for the download. | 299 // Returns the user-verified target file path for the download. |
331 // This returns the same path as GetTargetFilePath() for safe downloads | 300 // This returns the same path as GetTargetFilePath() for safe downloads |
332 // but does not for dangerous downloads until the name is verified. | 301 // but does not for dangerous downloads until the name is verified. |
333 FilePath GetUserVerifiedFilePath() const; | 302 virtual FilePath GetUserVerifiedFilePath() const = 0; |
334 | 303 |
335 // Returns true if the current file name is not the final target name yet. | 304 // Returns true if the current file name is not the final target name yet. |
336 bool NeedsRename() const { | 305 virtual bool NeedsRename() const = 0; |
337 return state_info_.target_name != full_path_.BaseName(); | |
338 } | |
339 | 306 |
340 // Cancels the off-thread aspects of the download. | 307 // Cancels the off-thread aspects of the download. |
341 // TODO(rdsmith): This should be private and only called from | 308 // TODO(rdsmith): This should be private and only called from |
342 // DownloadItem::Cancel/Interrupt; it isn't now because we can't | 309 // DownloadItem::Cancel/Interrupt; it isn't now because we can't |
343 // call those functions from | 310 // call those functions from |
344 // DownloadManager::FileSelectionCancelled() without doing some | 311 // DownloadManager::FileSelectionCancelled() without doing some |
345 // rewrites of the DownloadManager queues. | 312 // rewrites of the DownloadManager queues. |
346 void OffThreadCancel(DownloadFileManager* file_manager); | 313 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; |
347 | 314 |
348 std::string DebugString(bool verbose) const; | 315 virtual std::string DebugString(bool verbose) const = 0; |
349 | 316 |
350 void MockDownloadOpenForTesting() { open_enabled_ = false; } | 317 virtual void MockDownloadOpenForTesting() = 0; |
351 | |
352 private: | |
353 // Construction common to all constructors. |active| should be true for new | |
354 // downloads and false for downloads from the history. | |
355 void Init(bool active); | |
356 | |
357 // Internal helper for maintaining consistent received and total sizes. | |
358 void UpdateSize(int64 size); | |
359 | |
360 // Called when the entire download operation (including renaming etc) | |
361 // is completed. | |
362 void Completed(); | |
363 | |
364 // Call to transition state; all state transitions should go through this. | |
365 void TransitionTo(DownloadState new_state); | |
366 | |
367 // Called when safety_state_ should be recomputed from is_dangerous_file | |
368 // and is_dangerous_url. | |
369 void UpdateSafetyState(); | |
370 | |
371 // Helper function to recompute |state_info_.target_name| when | |
372 // it may have changed. (If it's non-null it should be left alone, | |
373 // otherwise updated from |full_path_|.) | |
374 void UpdateTarget(); | |
375 | |
376 // State information used by the download manager. | |
377 DownloadStateInfo state_info_; | |
378 | |
379 // The handle to the request information. Used for operations outside the | |
380 // download system. May be null if the download item isn't associated | |
381 // with a request (e.g. created from persistent store). | |
382 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | |
383 | |
384 // Download ID assigned by DownloadResourceHandler. | |
385 DownloadId download_id_; | |
386 | |
387 // Full path to the downloaded or downloading file. | |
388 FilePath full_path_; | |
389 | |
390 // A number that should be appended to the path to make it unique, or 0 if the | |
391 // path should be used as is. | |
392 int path_uniquifier_; | |
393 | |
394 // The chain of redirects that leading up to and including the final URL. | |
395 std::vector<GURL> url_chain_; | |
396 | |
397 // The URL of the page that initiated the download. | |
398 GURL referrer_url_; | |
399 | |
400 // Suggested filename in 'download' attribute of an anchor. Details: | |
401 // http://www.whatwg.org/specs/web-apps/current-work/#downloading-hyperlinks | |
402 std::string suggested_filename_; | |
403 | |
404 // Information from the request. | |
405 // Content-disposition field from the header. | |
406 std::string content_disposition_; | |
407 | |
408 // Mime-type from the header. Subject to change. | |
409 std::string mime_type_; | |
410 | |
411 // The value of the content type header sent with the downloaded item. It | |
412 // may be different from |mime_type_|, which may be set based on heuristics | |
413 // which may look at the file extension and first few bytes of the file. | |
414 std::string original_mime_type_; | |
415 | |
416 // The charset of the referring page where the download request comes from. | |
417 // It's used to construct a suggested filename. | |
418 std::string referrer_charset_; | |
419 | |
420 // Total bytes expected | |
421 int64 total_bytes_; | |
422 | |
423 // Current received bytes | |
424 int64 received_bytes_; | |
425 | |
426 // Sha256 hash of the content. This might be empty either because | |
427 // the download isn't done yet or because the hash isn't needed | |
428 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). | |
429 std::string hash_; | |
430 | |
431 // Last reason. | |
432 InterruptReason last_reason_; | |
433 | |
434 // Start time for calculating remaining time | |
435 base::TimeTicks start_tick_; | |
436 | |
437 // The current state of this download | |
438 DownloadState state_; | |
439 | |
440 // The views of this item in the download shelf and download tab | |
441 ObserverList<Observer> observers_; | |
442 | |
443 // Time the download was started | |
444 base::Time start_time_; | |
445 | |
446 // Time the download completed | |
447 base::Time end_time_; | |
448 | |
449 // Our persistent store handle | |
450 int64 db_handle_; | |
451 | |
452 // Our owning object | |
453 DownloadManager* download_manager_; | |
454 | |
455 // In progress downloads may be paused by the user, we note it here | |
456 bool is_paused_; | |
457 | |
458 // A flag for indicating if the download should be opened at completion. | |
459 bool open_when_complete_; | |
460 | |
461 // A flag for indicating if the downloaded file is externally removed. | |
462 bool file_externally_removed_; | |
463 | |
464 // Indicates if the download is considered potentially safe or dangerous | |
465 // (executable files are typically considered dangerous). | |
466 SafetyState safety_state_; | |
467 | |
468 // True if the download was auto-opened. We set this rather than using | |
469 // an observer as it's frequently possible for the download to be auto opened | |
470 // before the observer is added. | |
471 bool auto_opened_; | |
472 | |
473 // True if the download was initiated in an incognito window. | |
474 bool is_otr_; | |
475 | |
476 // True if the item was downloaded temporarily. | |
477 bool is_temporary_; | |
478 | |
479 // True if we've saved all the data for the download. | |
480 bool all_data_saved_; | |
481 | |
482 // Did the user open the item either directly or indirectly (such as by | |
483 // setting always open files of this type)? The shelf also sets this field | |
484 // when the user closes the shelf before the item has been opened but should | |
485 // be treated as though the user opened it. | |
486 bool opened_; | |
487 | |
488 // Do we actual open downloads when requested? For testing purposes | |
489 // only. | |
490 bool open_enabled_; | |
491 | |
492 // Did the delegate delay calling Complete on this download? | |
493 bool delegate_delayed_complete_; | |
494 | |
495 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | |
496 }; | 318 }; |
497 | 319 |
498 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 320 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
OLD | NEW |