| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void RemoveObserver(Observer* observer); | 128 void RemoveObserver(Observer* observer); |
| 129 | 129 |
| 130 // Notifies our observers periodically. | 130 // Notifies our observers periodically. |
| 131 void UpdateObservers(); | 131 void UpdateObservers(); |
| 132 | 132 |
| 133 // NotificationObserver implementation. | 133 // NotificationObserver implementation. |
| 134 virtual void Observe(NotificationType type, | 134 virtual void Observe(NotificationType type, |
| 135 const NotificationSource& source, | 135 const NotificationSource& source, |
| 136 const NotificationDetails& details); | 136 const NotificationDetails& details); |
| 137 | 137 |
| 138 // Returns true if it is OK to open this download. | 138 // Returns true if it is OK to open a folder which this file is inside. |
| 139 bool CanShowInFolder(); |
| 140 |
| 141 // Returns true if it is OK to register the type of this file so that |
| 142 // it opens automatically. |
| 139 bool CanOpenDownload(); | 143 bool CanOpenDownload(); |
| 140 | 144 |
| 141 // Tests if a file type should be opened automatically. | 145 // Tests if a file type should be opened automatically. |
| 142 bool ShouldOpenFileBasedOnExtension(); | 146 bool ShouldOpenFileBasedOnExtension(); |
| 143 | 147 |
| 144 // Registers this file extension for automatic opening upon download | 148 // Registers this file extension for automatic opening upon download |
| 145 // completion if 'open' is true, or prevents the extension from automatic | 149 // completion if 'open' is true, or prevents the extension from automatic |
| 146 // opening if 'open' is false. | 150 // opening if 'open' is false. |
| 147 void OpenFilesBasedOnExtension(bool open); | 151 void OpenFilesBasedOnExtension(bool open); |
| 148 | 152 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 163 // exit (DownloadManager destructor) from user interface initiated cancels | 167 // exit (DownloadManager destructor) from user interface initiated cancels |
| 164 // because at exit, the history system may not exist, and any updates to it | 168 // because at exit, the history system may not exist, and any updates to it |
| 165 // require AddRef'ing the DownloadManager in the destructor which results in | 169 // require AddRef'ing the DownloadManager in the destructor which results in |
| 166 // a DCHECK failure. Set 'update_history' to false when canceling from at | 170 // a DCHECK failure. Set 'update_history' to false when canceling from at |
| 167 // exit to prevent this crash. This may result in a difference between the | 171 // exit to prevent this crash. This may result in a difference between the |
| 168 // downloaded file's size on disk, and what the history system's last record | 172 // downloaded file's size on disk, and what the history system's last record |
| 169 // of it is. At worst, we'll end up re-downloading a small portion of the file | 173 // of it is. At worst, we'll end up re-downloading a small portion of the file |
| 170 // when resuming a download (assuming the server supports byte ranges). | 174 // when resuming a download (assuming the server supports byte ranges). |
| 171 void Cancel(bool update_history); | 175 void Cancel(bool update_history); |
| 172 | 176 |
| 173 // Called when all data has been saved. Only has display effects. | |
| 174 void OnAllDataSaved(int64 size); | |
| 175 | |
| 176 // Called by external code (SavePackage) using the DownloadItem interface | 177 // Called by external code (SavePackage) using the DownloadItem interface |
| 177 // to display progress when the DownloadItem should be considered complete. | 178 // to display progress when the DownloadItem should be considered complete. |
| 178 void MarkAsComplete(); | 179 void MarkAsComplete(); |
| 179 | 180 |
| 181 // Called when all data has been saved. Only has display effects. |
| 182 void OnAllDataSaved(int64 size); |
| 183 |
| 184 // Called when the downloaded file is removed. |
| 185 void OnDownloadedFileRemoved(); |
| 186 |
| 180 // Download operation had an error. | 187 // Download operation had an error. |
| 181 // |size| is the amount of data received so far, and |os_error| is the error | 188 // |size| is the amount of data received so far, and |os_error| is the error |
| 182 // code that the operation received. | 189 // code that the operation received. |
| 183 void Interrupted(int64 size, int os_error); | 190 void Interrupted(int64 size, int os_error); |
| 184 | 191 |
| 185 // Deletes the file from disk and removes the download from the views and | 192 // Deletes the file from disk and removes the download from the views and |
| 186 // history. |user| should be true if this is the result of the user clicking | 193 // history. |user| should be true if this is the result of the user clicking |
| 187 // the discard button, and false if it is being deleted for other reasons like | 194 // the discard button, and false if it is being deleted for other reasons like |
| 188 // browser shutdown. | 195 // browser shutdown. |
| 189 void Delete(DeleteReason reason); | 196 void Delete(DeleteReason reason); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 total_bytes_ = total_bytes; | 278 total_bytes_ = total_bytes; |
| 272 } | 279 } |
| 273 int64 received_bytes() const { return received_bytes_; } | 280 int64 received_bytes() const { return received_bytes_; } |
| 274 int32 id() const { return download_id_; } | 281 int32 id() const { return download_id_; } |
| 275 base::Time start_time() const { return start_time_; } | 282 base::Time start_time() const { return start_time_; } |
| 276 void set_db_handle(int64 handle) { db_handle_ = handle; } | 283 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 277 int64 db_handle() const { return db_handle_; } | 284 int64 db_handle() const { return db_handle_; } |
| 278 bool is_paused() const { return is_paused_; } | 285 bool is_paused() const { return is_paused_; } |
| 279 bool open_when_complete() const { return open_when_complete_; } | 286 bool open_when_complete() const { return open_when_complete_; } |
| 280 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 287 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 288 bool file_externally_removed() const { return file_externally_removed_; } |
| 281 SafetyState safety_state() const { return safety_state_; } | 289 SafetyState safety_state() const { return safety_state_; } |
| 282 void set_safety_state(SafetyState safety_state) { | 290 void set_safety_state(SafetyState safety_state) { |
| 283 safety_state_ = safety_state; | 291 safety_state_ = safety_state; |
| 284 } | 292 } |
| 285 // Why |safety_state_| is not SAFE. | 293 // Why |safety_state_| is not SAFE. |
| 286 DangerType GetDangerType() const; | 294 DangerType GetDangerType() const; |
| 287 bool IsDangerous() const; | 295 bool IsDangerous() const; |
| 288 void MarkFileDangerous(); | 296 void MarkFileDangerous(); |
| 289 void MarkUrlDangerous(); | 297 void MarkUrlDangerous(); |
| 290 | 298 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 433 |
| 426 // Our owning object | 434 // Our owning object |
| 427 DownloadManager* download_manager_; | 435 DownloadManager* download_manager_; |
| 428 | 436 |
| 429 // In progress downloads may be paused by the user, we note it here | 437 // In progress downloads may be paused by the user, we note it here |
| 430 bool is_paused_; | 438 bool is_paused_; |
| 431 | 439 |
| 432 // A flag for indicating if the download should be opened at completion. | 440 // A flag for indicating if the download should be opened at completion. |
| 433 bool open_when_complete_; | 441 bool open_when_complete_; |
| 434 | 442 |
| 443 // A flag for indicating if the downloaded file is externally removed. |
| 444 bool file_externally_removed_; |
| 445 |
| 435 // Indicates if the download is considered potentially safe or dangerous | 446 // Indicates if the download is considered potentially safe or dangerous |
| 436 // (executable files are typically considered dangerous). | 447 // (executable files are typically considered dangerous). |
| 437 SafetyState safety_state_; | 448 SafetyState safety_state_; |
| 438 | 449 |
| 439 // True if the download was auto-opened. We set this rather than using | 450 // True if the download was auto-opened. We set this rather than using |
| 440 // an observer as it's frequently possible for the download to be auto opened | 451 // an observer as it's frequently possible for the download to be auto opened |
| 441 // before the observer is added. | 452 // before the observer is added. |
| 442 bool auto_opened_; | 453 bool auto_opened_; |
| 443 | 454 |
| 444 // True if the download was initiated in an incognito window. | 455 // True if the download was initiated in an incognito window. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 460 // only. | 471 // only. |
| 461 bool open_enabled_; | 472 bool open_enabled_; |
| 462 | 473 |
| 463 // DownloadItem observes CRX installs it initiates. | 474 // DownloadItem observes CRX installs it initiates. |
| 464 NotificationRegistrar registrar_; | 475 NotificationRegistrar registrar_; |
| 465 | 476 |
| 466 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 477 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 467 }; | 478 }; |
| 468 | 479 |
| 469 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 480 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |