OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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: |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 // One DownloadItem per download. This is the model class that stores all the | 34 // One DownloadItem per download. This is the model class that stores all the |
35 // state for a download. Multiple views, such as a tab's download shelf and the | 35 // state for a download. Multiple views, such as a tab's download shelf and the |
36 // Destination tab's download view, may refer to a given DownloadItem. | 36 // Destination tab's download view, may refer to a given DownloadItem. |
37 // | 37 // |
38 // This is intended to be used only on the UI thread. | 38 // This is intended to be used only on the UI thread. |
39 class DownloadItem { | 39 class DownloadItem { |
40 public: | 40 public: |
41 enum DownloadState { | 41 enum DownloadState { |
42 IN_PROGRESS, | 42 IN_PROGRESS, |
| 43 |
| 44 // Note that COMPLETE indicates that the download has gotten all of its |
| 45 // data, has figured out its final destination file, has been entered |
| 46 // into the history store, and has been shown in the UI. The only |
| 47 // operations remaining are acceptance by the user of |
| 48 // a dangerous download (if dangerous), renaming the file |
| 49 // to the final name, and auto-opening it (if it auto-opens). |
43 COMPLETE, | 50 COMPLETE, |
| 51 |
44 CANCELLED, | 52 CANCELLED, |
| 53 |
| 54 // This state indicates that the download item is about to be destroyed, |
| 55 // and observers seeing this state should release all references. |
45 REMOVING | 56 REMOVING |
46 }; | 57 }; |
47 | 58 |
48 enum SafetyState { | 59 enum SafetyState { |
49 SAFE = 0, | 60 SAFE = 0, |
50 DANGEROUS, | 61 DANGEROUS, |
51 DANGEROUS_BUT_VALIDATED // Dangerous but the user confirmed the download. | 62 DANGEROUS_BUT_VALIDATED // Dangerous but the user confirmed the download. |
52 }; | 63 }; |
53 | 64 |
54 // Interface that observers of a particular download must implement in order | 65 // Interface that observers of a particular download must implement in order |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // exit (DownloadManager destructor) from user interface initiated cancels | 132 // exit (DownloadManager destructor) from user interface initiated cancels |
122 // 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 |
123 // require AddRef'ing the DownloadManager in the destructor which results in | 134 // require AddRef'ing the DownloadManager in the destructor which results in |
124 // a DCHECK failure. Set 'update_history' to false when canceling from at | 135 // a DCHECK failure. Set 'update_history' to false when canceling from at |
125 // 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 |
126 // 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 |
127 // 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 |
128 // when resuming a download (assuming the server supports byte ranges). | 139 // when resuming a download (assuming the server supports byte ranges). |
129 void Cancel(bool update_history); | 140 void Cancel(bool update_history); |
130 | 141 |
131 // Called when all data has been saved. | 142 // Called when all data has been saved. Only has display effects. |
132 void OnAllDataSaved(int64 size); | 143 void OnAllDataSaved(int64 size); |
133 | 144 |
| 145 // Called when ready to consider the data received and move on to the |
| 146 // next stage. |
| 147 void MarkAsComplete(); |
| 148 |
134 // Called when the entire download operation (including renaming etc) | 149 // Called when the entire download operation (including renaming etc) |
135 // is finished. | 150 // is finished. |
136 void Finished(); | 151 void Finished(); |
137 | 152 |
138 // The user wants to remove the download from the views and history. If | 153 // The user wants to remove the download from the views and history. If |
139 // |delete_file| is true, the file is deleted on the disk. | 154 // |delete_file| is true, the file is deleted on the disk. |
140 void Remove(bool delete_file); | 155 void Remove(bool delete_file); |
141 | 156 |
142 // Simple calculation of the amount of time remaining to completion. Fills | 157 // Simple calculation of the amount of time remaining to completion. Fills |
143 // |*remaining| with the amount of time remaining if successful. Fails and | 158 // |*remaining| with the amount of time remaining if successful. Fails and |
144 // returns false if we do not have the number of bytes or the speed so can | 159 // returns false if we do not have the number of bytes or the speed so can |
145 // not estimate. | 160 // not estimate. |
146 bool TimeRemaining(base::TimeDelta* remaining) const; | 161 bool TimeRemaining(base::TimeDelta* remaining) const; |
147 | 162 |
148 // Simple speed estimate in bytes/s | 163 // Simple speed estimate in bytes/s |
149 int64 CurrentSpeed() const; | 164 int64 CurrentSpeed() const; |
150 | 165 |
151 // Rough percent complete, -1 means we don't know (since we didn't receive a | 166 // Rough percent complete, -1 means we don't know (since we didn't receive a |
152 // total size). | 167 // total size). |
153 int PercentComplete() const; | 168 int PercentComplete() const; |
154 | 169 |
| 170 // Whether or not this download has saved all of its data. |
| 171 bool all_data_saved() const { return all_data_saved_; } |
| 172 |
155 // Update the fields that may have changed in DownloadCreateInfo as a | 173 // Update the fields that may have changed in DownloadCreateInfo as a |
156 // result of analyzing the file and figuring out its type, location, etc. | 174 // result of analyzing the file and figuring out its type, location, etc. |
157 // May only be called once. | 175 // May only be called once. |
158 void SetFileCheckResults(const FilePath& path, | 176 void SetFileCheckResults(const FilePath& path, |
159 bool is_dangerous, | 177 bool is_dangerous, |
160 int path_uniquifier, | 178 int path_uniquifier, |
161 bool prompt, | 179 bool prompt, |
162 bool is_extension_install, | 180 bool is_extension_install, |
163 const FilePath& original_name); | 181 const FilePath& original_name); |
164 | 182 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 346 |
329 // True if the item was downloaded for an extension installation. | 347 // True if the item was downloaded for an extension installation. |
330 bool is_extension_install_; | 348 bool is_extension_install_; |
331 | 349 |
332 // True if the filename is finalized. | 350 // True if the filename is finalized. |
333 bool name_finalized_; | 351 bool name_finalized_; |
334 | 352 |
335 // True if the item was downloaded temporarily. | 353 // True if the item was downloaded temporarily. |
336 bool is_temporary_; | 354 bool is_temporary_; |
337 | 355 |
| 356 // True if we've saved all the data for the download. |
| 357 bool all_data_saved_; |
| 358 |
338 // Did the user open the item either directly or indirectly (such as by | 359 // Did the user open the item either directly or indirectly (such as by |
339 // setting always open files of this type)? The shelf also sets this field | 360 // setting always open files of this type)? The shelf also sets this field |
340 // when the user closes the shelf before the item has been opened but should | 361 // when the user closes the shelf before the item has been opened but should |
341 // be treated as though the user opened it. | 362 // be treated as though the user opened it. |
342 bool opened_; | 363 bool opened_; |
343 | 364 |
344 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 365 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
345 }; | 366 }; |
346 | 367 |
347 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 368 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
OLD | NEW |