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

Side by Side Diff: content/browser/download/download_item.h

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

Powered by Google App Engine
This is Rietveld 408576698