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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // Open the file associated with this download (wait for the download to | 139 // Open the file associated with this download (wait for the download to |
| 140 // complete if it is in progress). | 140 // complete if it is in progress). |
| 141 void OpenDownload(); | 141 void OpenDownload(); |
| 142 | 142 |
| 143 // Show the download via the OS shell. | 143 // Show the download via the OS shell. |
| 144 void ShowDownloadInShell(); | 144 void ShowDownloadInShell(); |
| 145 | 145 |
| 146 // Called when the user has validated the download of a dangerous file. | 146 // Called when the user has validated the download of a dangerous file. |
| 147 void DangerousDownloadValidated(); | 147 void DangerousDownloadValidated(); |
| 148 | 148 |
| 149 // Received a new chunk of data | 149 // Received a new chunk of data. |
| 150 void Update(int64 bytes_so_far); | 150 // |bytes_so_far| is the number of bytes received so far. |
| 151 // |hash_state| is the current hash state. | |
| 152 void Update(int64 bytes_so_far, const std::string& hash_state); | |
| 151 | 153 |
| 152 // Cancel the download operation. We need to distinguish between cancels at | 154 // Cancel the download operation. We need to distinguish between cancels at |
| 153 // exit (DownloadManager destructor) from user interface initiated cancels | 155 // exit (DownloadManager destructor) from user interface initiated cancels |
| 154 // because at exit, the history system may not exist, and any updates to it | 156 // because at exit, the history system may not exist, and any updates to it |
| 155 // require AddRef'ing the DownloadManager in the destructor which results in | 157 // require AddRef'ing the DownloadManager in the destructor which results in |
| 156 // a DCHECK failure. Set |user_cancel| to false when canceling from at | 158 // a DCHECK failure. Set |user_cancel| to false when canceling from at |
| 157 // exit to prevent this crash. This may result in a difference between the | 159 // exit to prevent this crash. This may result in a difference between the |
| 158 // downloaded file's size on disk, and what the history system's last record | 160 // downloaded file's size on disk, and what the history system's last record |
| 159 // of it is. At worst, we'll end up re-downloading a small portion of the file | 161 // of it is. At worst, we'll end up re-downloading a small portion of the file |
| 160 // when resuming a download (assuming the server supports byte ranges). | 162 // when resuming a download (assuming the server supports byte ranges). |
| 161 void Cancel(bool user_cancel); | 163 void Cancel(bool user_cancel); |
| 162 | 164 |
| 163 // Called by external code (SavePackage) using the DownloadItem interface | 165 // Called by external code (SavePackage) using the DownloadItem interface |
| 164 // to display progress when the DownloadItem should be considered complete. | 166 // to display progress when the DownloadItem should be considered complete. |
| 165 void MarkAsComplete(); | 167 void MarkAsComplete(); |
| 166 | 168 |
| 167 // Called by the delegate after it delayed opening the download in | 169 // Called by the delegate after it delayed opening the download in |
| 168 // DownloadManagerDelegate::ShouldOpenDownload. | 170 // DownloadManagerDelegate::ShouldOpenDownload. |
| 169 void DelayedDownloadOpened(); | 171 void DelayedDownloadOpened(); |
| 170 | 172 |
| 171 // Called when all data has been saved. | 173 // Called when all data has been saved. |
| 172 void OnAllDataSaved(int64 size, const std::string& final_hash); | 174 void OnAllDataSaved(int64 size, const std::string& final_hash); |
| 173 | 175 |
| 174 // Called when the downloaded file is removed. | 176 // Called when the downloaded file is removed. |
| 175 void OnDownloadedFileRemoved(); | 177 void OnDownloadedFileRemoved(); |
| 176 | 178 |
| 177 // Download operation had an error. | 179 // Download operation had an error. |
| 178 // |size| is the amount of data received at interruption. | 180 // |size| is the amount of data received at interruption. |
| 181 // |hash_state| is the current hash state at interruption. | |
| 179 // |reason| is the download interrupt reason code that the operation received. | 182 // |reason| is the download interrupt reason code that the operation received. |
| 180 void Interrupted(int64 size, InterruptReason reason); | 183 void Interrupted(int64 size, |
| 184 const std::string& hash_state, | |
| 185 InterruptReason reason); | |
| 181 | 186 |
| 182 // Deletes the file from disk and removes the download from the views and | 187 // Deletes the file from disk and removes the download from the views and |
| 183 // history. |user| should be true if this is the result of the user clicking | 188 // history. |user| should be true if this is the result of the user clicking |
| 184 // the discard button, and false if it is being deleted for other reasons like | 189 // the discard button, and false if it is being deleted for other reasons like |
| 185 // browser shutdown. | 190 // browser shutdown. |
| 186 void Delete(DeleteReason reason); | 191 void Delete(DeleteReason reason); |
| 187 | 192 |
| 188 // Removes the download from the views and history. | 193 // Removes the download from the views and history. |
| 189 void Remove(); | 194 void Remove(); |
| 190 | 195 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 std::string content_disposition() const { return content_disposition_; } | 265 std::string content_disposition() const { return content_disposition_; } |
| 261 std::string mime_type() const { return mime_type_; } | 266 std::string mime_type() const { return mime_type_; } |
| 262 std::string original_mime_type() const { return original_mime_type_; } | 267 std::string original_mime_type() const { return original_mime_type_; } |
| 263 std::string referrer_charset() const { return referrer_charset_; } | 268 std::string referrer_charset() const { return referrer_charset_; } |
| 264 int64 total_bytes() const { return total_bytes_; } | 269 int64 total_bytes() const { return total_bytes_; } |
| 265 void set_total_bytes(int64 total_bytes) { | 270 void set_total_bytes(int64 total_bytes) { |
| 266 total_bytes_ = total_bytes; | 271 total_bytes_ = total_bytes; |
| 267 } | 272 } |
| 268 int64 received_bytes() const { return received_bytes_; } | 273 int64 received_bytes() const { return received_bytes_; } |
| 269 const std::string& hash() const { return hash_; } | 274 const std::string& hash() const { return hash_; } |
| 275 std::string hash_state() const { return hash_state_; } | |
| 270 int32 id() const { return download_id_.local(); } | 276 int32 id() const { return download_id_.local(); } |
| 271 DownloadId global_id() const { return download_id_; } | 277 DownloadId global_id() const { return download_id_; } |
| 272 base::Time start_time() const { return start_time_; } | 278 base::Time start_time() const { return start_time_; } |
| 273 base::Time end_time() const { return end_time_; } | 279 base::Time end_time() const { return end_time_; } |
| 274 void set_db_handle(int64 handle) { db_handle_ = handle; } | 280 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 275 int64 db_handle() const { return db_handle_; } | 281 int64 db_handle() const { return db_handle_; } |
| 276 DownloadManager* download_manager() { return download_manager_; } | 282 DownloadManager* download_manager() { return download_manager_; } |
| 277 bool is_paused() const { return is_paused_; } | 283 bool is_paused() const { return is_paused_; } |
| 278 bool open_when_complete() const { return open_when_complete_; } | 284 bool open_when_complete() const { return open_when_complete_; } |
| 279 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 285 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 290 const FilePath& target_name() const { return state_info_.target_name; } | 296 const FilePath& target_name() const { return state_info_.target_name; } |
| 291 bool prompt_user_for_save_location() const { | 297 bool prompt_user_for_save_location() const { |
| 292 return state_info_.prompt_user_for_save_location; | 298 return state_info_.prompt_user_for_save_location; |
| 293 } | 299 } |
| 294 bool is_otr() const { return is_otr_; } | 300 bool is_otr() const { return is_otr_; } |
| 295 const FilePath& suggested_path() const { return state_info_.suggested_path; } | 301 const FilePath& suggested_path() const { return state_info_.suggested_path; } |
| 296 bool is_temporary() const { return is_temporary_; } | 302 bool is_temporary() const { return is_temporary_; } |
| 297 void set_opened(bool opened) { opened_ = opened; } | 303 void set_opened(bool opened) { opened_ = opened; } |
| 298 bool opened() const { return opened_; } | 304 bool opened() const { return opened_; } |
| 299 | 305 |
| 306 const std::string& last_modified_time() const { return last_modified_time_; } | |
| 307 const std::string& etag() const { return etag_; } | |
| 308 | |
| 300 InterruptReason last_reason() const { return last_reason_; } | 309 InterruptReason last_reason() const { return last_reason_; } |
| 301 | 310 |
| 302 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; | 311 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; |
| 303 DownloadStateInfo state_info() const { return state_info_; } | 312 DownloadStateInfo state_info() const { return state_info_; } |
| 304 | 313 |
| 305 TabContents* GetTabContents() const; | 314 TabContents* GetTabContents() const; |
| 306 | 315 |
| 307 // Returns the final target file path for the download. | 316 // Returns the final target file path for the download. |
| 308 FilePath GetTargetFilePath() const; | 317 FilePath GetTargetFilePath() const; |
| 309 | 318 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 331 | 340 |
| 332 std::string DebugString(bool verbose) const; | 341 std::string DebugString(bool verbose) const; |
| 333 | 342 |
| 334 void MockDownloadOpenForTesting() { open_enabled_ = false; } | 343 void MockDownloadOpenForTesting() { open_enabled_ = false; } |
| 335 | 344 |
| 336 private: | 345 private: |
| 337 // Construction common to all constructors. |active| should be true for new | 346 // Construction common to all constructors. |active| should be true for new |
| 338 // downloads and false for downloads from the history. | 347 // downloads and false for downloads from the history. |
| 339 void Init(bool active); | 348 void Init(bool active); |
| 340 | 349 |
| 350 // Internal helper for maintaining consistent received and total sizes, and | |
| 351 // hash state. | |
| 352 void UpdateSizeAndHashState(int64 bytes_so_far, | |
| 353 const std::string& hash_state); | |
| 354 | |
| 341 // Internal helper for maintaining consistent received and total sizes. | 355 // Internal helper for maintaining consistent received and total sizes. |
| 342 void UpdateSize(int64 size); | 356 // Should only be called from |UpdateSizeAndHashState| and |OnAllDataSaved|. |
| 357 void UpdateSize(int64 bytes_so_far); | |
|
Randy Smith (Not in Mondays)
2011/11/22 17:37:49
Given that the reason we have UpdateSizeAndHashSta
ahendrickson
2011/11/22 23:46:44
Done.
| |
| 343 | 358 |
| 344 // Called when the entire download operation (including renaming etc) | 359 // Called when the entire download operation (including renaming etc) |
| 345 // is completed. | 360 // is completed. |
| 346 void Completed(); | 361 void Completed(); |
| 347 | 362 |
| 348 // Call to transition state; all state transitions should go through this. | 363 // Call to transition state; all state transitions should go through this. |
| 349 void TransitionTo(DownloadState new_state); | 364 void TransitionTo(DownloadState new_state); |
| 350 | 365 |
| 351 // Called when safety_state_ should be recomputed from the DangerType of the | 366 // Called when safety_state_ should be recomputed from the DangerType of the |
| 352 // state info. | 367 // state info. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 409 |
| 395 // The value of the content type header sent with the downloaded item. It | 410 // The value of the content type header sent with the downloaded item. It |
| 396 // may be different from |mime_type_|, which may be set based on heuristics | 411 // may be different from |mime_type_|, which may be set based on heuristics |
| 397 // which may look at the file extension and first few bytes of the file. | 412 // which may look at the file extension and first few bytes of the file. |
| 398 std::string original_mime_type_; | 413 std::string original_mime_type_; |
| 399 | 414 |
| 400 // The charset of the referring page where the download request comes from. | 415 // The charset of the referring page where the download request comes from. |
| 401 // It's used to construct a suggested filename. | 416 // It's used to construct a suggested filename. |
| 402 std::string referrer_charset_; | 417 std::string referrer_charset_; |
| 403 | 418 |
| 404 // Total bytes expected | 419 // Total bytes expected. |
| 405 int64 total_bytes_; | 420 int64 total_bytes_; |
| 406 | 421 |
| 407 // Current received bytes | 422 // Current received bytes. |
| 408 int64 received_bytes_; | 423 int64 received_bytes_; |
| 409 | 424 |
| 410 // Sha256 hash of the content. This might be empty either because | 425 // Sha256 hash of the content. This might be empty either because |
| 411 // the download isn't done yet or because the hash isn't needed | 426 // the download isn't done yet or because the hash isn't needed |
| 412 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). | 427 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). |
| 413 std::string hash_; | 428 std::string hash_; |
| 414 | 429 |
| 430 // A blob containing the state of the hash algorithm. Only valid while the | |
| 431 // hash is being computed. | |
|
Randy Smith (Not in Mondays)
2011/11/22 17:37:49
nit: At this level "while the hash is being comput
ahendrickson
2011/11/22 23:46:44
Done.
| |
| 432 std::string hash_state_; | |
| 433 | |
| 434 // Server's time stamp for the file. | |
| 435 std::string last_modified_time_; | |
| 436 | |
| 437 // Server's ETAG for the file. | |
| 438 std::string etag_; | |
| 439 | |
| 415 // Last reason. | 440 // Last reason. |
| 416 InterruptReason last_reason_; | 441 InterruptReason last_reason_; |
| 417 | 442 |
| 418 // Start time for calculating remaining time | 443 // Start time for calculating remaining time. |
| 419 base::TimeTicks start_tick_; | 444 base::TimeTicks start_tick_; |
| 420 | 445 |
| 421 // The current state of this download | 446 // The current state of this download. |
| 422 DownloadState state_; | 447 DownloadState state_; |
| 423 | 448 |
| 424 // The views of this item in the download shelf and download tab | 449 // The views of this item in the download shelf and download tab. |
| 425 ObserverList<Observer> observers_; | 450 ObserverList<Observer> observers_; |
| 426 | 451 |
| 427 // Time the download was started | 452 // Time the download was started. |
| 428 base::Time start_time_; | 453 base::Time start_time_; |
| 429 | 454 |
| 430 // Time the download completed | 455 // Time the download completed. |
| 431 base::Time end_time_; | 456 base::Time end_time_; |
| 432 | 457 |
| 433 // Our persistent store handle | 458 // Our persistent store handle. |
| 434 int64 db_handle_; | 459 int64 db_handle_; |
| 435 | 460 |
| 436 // Our owning object | 461 // Our owning object. |
| 437 DownloadManager* download_manager_; | 462 DownloadManager* download_manager_; |
| 438 | 463 |
| 439 // In progress downloads may be paused by the user, we note it here | 464 // In progress downloads may be paused by the user, we note it here. |
| 440 bool is_paused_; | 465 bool is_paused_; |
| 441 | 466 |
| 442 // A flag for indicating if the download should be opened at completion. | 467 // A flag for indicating if the download should be opened at completion. |
| 443 bool open_when_complete_; | 468 bool open_when_complete_; |
| 444 | 469 |
| 445 // A flag for indicating if the downloaded file is externally removed. | 470 // A flag for indicating if the downloaded file is externally removed. |
| 446 bool file_externally_removed_; | 471 bool file_externally_removed_; |
| 447 | 472 |
| 448 // Indicates if the download is considered potentially safe or dangerous | 473 // Indicates if the download is considered potentially safe or dangerous |
| 449 // (executable files are typically considered dangerous). | 474 // (executable files are typically considered dangerous). |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 473 // only. | 498 // only. |
| 474 bool open_enabled_; | 499 bool open_enabled_; |
| 475 | 500 |
| 476 // Did the delegate delay calling Complete on this download? | 501 // Did the delegate delay calling Complete on this download? |
| 477 bool delegate_delayed_complete_; | 502 bool delegate_delayed_complete_; |
| 478 | 503 |
| 479 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 504 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 480 }; | 505 }; |
| 481 | 506 |
| 482 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 507 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |