Chromium Code Reviews| 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: |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 156 |
| 157 // Show the download via the OS shell. | 157 // Show the download via the OS shell. |
| 158 void ShowDownloadInShell(); | 158 void ShowDownloadInShell(); |
| 159 | 159 |
| 160 // Called when the user has validated the download of a dangerous file. | 160 // Called when the user has validated the download of a dangerous file. |
| 161 void DangerousDownloadValidated(); | 161 void DangerousDownloadValidated(); |
| 162 | 162 |
| 163 // Received a new chunk of data | 163 // Received a new chunk of data |
| 164 void Update(int64 bytes_so_far); | 164 void Update(int64 bytes_so_far); |
| 165 | 165 |
| 166 // Cancel the download operation. We need to distinguish between cancels at | 166 // Cancel the download operation. This may be called at any time; if |
| 167 // exit (DownloadManager destructor) from user interface initiated cancels | 167 // it is called before the download has been persisted into the history |
| 168 // because at exit, the history system may not exist, and any updates to it | 168 // it will remove the download completely from the system. |
|
Randy Smith (Not in Mondays)
2011/06/30 23:05:13
Change comment to indicate both behaviors (before
Randy Smith (Not in Mondays)
2011/07/05 20:28:44
Changed phrasing, left assymetric specification.
| |
| 169 // require AddRef'ing the DownloadManager in the destructor which results in | 169 void Cancel(); |
| 170 // a DCHECK failure. Set 'update_history' to false when canceling from at | |
| 171 // exit to prevent this crash. This may result in a difference between the | |
| 172 // downloaded file's size on disk, and what the history system's last record | |
| 173 // of it is. At worst, we'll end up re-downloading a small portion of the file | |
| 174 // when resuming a download (assuming the server supports byte ranges). | |
| 175 void Cancel(bool update_history); | |
| 176 | 170 |
| 177 // Called by external code (SavePackage) using the DownloadItem interface | 171 // Called by external code (SavePackage) using the DownloadItem interface |
| 178 // to display progress when the DownloadItem should be considered complete. | 172 // to display progress when the DownloadItem should be considered complete. |
| 179 void MarkAsComplete(); | 173 void MarkAsComplete(); |
| 180 | 174 |
| 181 // Called when all data has been saved. Only has display effects. | 175 // Called when all data has been saved. Only has display effects. |
| 182 void OnAllDataSaved(int64 size); | 176 void OnAllDataSaved(int64 size); |
| 183 | 177 |
| 184 // Called when the downloaded file is removed. | 178 // Called when the downloaded file is removed. |
| 185 void OnDownloadedFileRemoved(); | 179 void OnDownloadedFileRemoved(); |
| 186 | 180 |
| 187 // Download operation had an error. | 181 // Download operation had an error; call to interrupt the processing. |
| 182 // Note that if the download hasn't yet been persisted to the history | |
| 183 // (which implies that it hasn't yet been shown to the user in the UI), | |
| 184 // it will be completely removed. | |
|
Randy Smith (Not in Mondays)
2011/06/30 23:05:13
Make this comment align with the Cancel comment.
Randy Smith (Not in Mondays)
2011/07/05 20:28:44
Done.
| |
| 188 // |size| is the amount of data received so far, and |os_error| is the error | 185 // |size| is the amount of data received so far, and |os_error| is the error |
| 189 // code that the operation received. | 186 // code that the operation received. |
| 190 void Interrupted(int64 size, int os_error); | 187 void Interrupt(int64 size, int os_error); |
| 191 | 188 |
| 192 // Deletes the file from disk and removes the download from the views and | 189 // Deletes the file from disk and removes the download from the views and |
| 193 // history. |user| should be true if this is the result of the user clicking | 190 // history. |user| should be true if this is the result of the user clicking |
| 194 // the discard button, and false if it is being deleted for other reasons like | 191 // the discard button, and false if it is being deleted for other reasons like |
| 195 // browser shutdown. | 192 // browser shutdown. |
| 196 void Delete(DeleteReason reason); | 193 void Delete(DeleteReason reason); |
| 197 | 194 |
| 198 // Removes the download from the views and history. | 195 // Removes the download from the views and history. |
| 199 void Remove(); | 196 void Remove(); |
| 200 | 197 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 #endif | 343 #endif |
| 347 | 344 |
| 348 private: | 345 private: |
| 349 // Construction common to all constructors. |active| should be true for new | 346 // Construction common to all constructors. |active| should be true for new |
| 350 // downloads and false for downloads from the history. | 347 // downloads and false for downloads from the history. |
| 351 void Init(bool active); | 348 void Init(bool active); |
| 352 | 349 |
| 353 // Internal helper for maintaining consistent received and total sizes. | 350 // Internal helper for maintaining consistent received and total sizes. |
| 354 void UpdateSize(int64 size); | 351 void UpdateSize(int64 size); |
| 355 | 352 |
| 353 // Internal function to do the main work of cancelling or | |
| 354 // interrupting a download. | |
| 355 void StopInternal(DownloadState target_state); | |
| 356 | |
| 356 // Called when the entire download operation (including renaming etc) | 357 // Called when the entire download operation (including renaming etc) |
| 357 // is completed. | 358 // is completed. |
| 358 void Completed(); | 359 void Completed(); |
| 359 | 360 |
| 360 // Start/stop sending periodic updates to our observers | 361 // Start/stop sending periodic updates to our observers |
| 361 void StartProgressTimer(); | 362 void StartProgressTimer(); |
| 362 void StopProgressTimer(); | 363 void StopProgressTimer(); |
| 363 | 364 |
| 364 // Call to install this item as a CRX. Should only be called on | 365 // Call to install this item as a CRX. Should only be called on |
| 365 // items which are CRXes. Use is_extension_install() to check. | 366 // items which are CRXes. Use is_extension_install() to check. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 // only. | 472 // only. |
| 472 bool open_enabled_; | 473 bool open_enabled_; |
| 473 | 474 |
| 474 // DownloadItem observes CRX installs it initiates. | 475 // DownloadItem observes CRX installs it initiates. |
| 475 NotificationRegistrar registrar_; | 476 NotificationRegistrar registrar_; |
| 476 | 477 |
| 477 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 478 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 478 }; | 479 }; |
| 479 | 480 |
| 480 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 481 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |