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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // Open the file associated with this download (wait for the download to | 150 // Open the file associated with this download (wait for the download to |
| 151 // complete if it is in progress). | 151 // complete if it is in progress). |
| 152 void OpenDownload(); | 152 void OpenDownload(); |
| 153 | 153 |
| 154 // Show the download via the OS shell. | 154 // Show the download via the OS shell. |
| 155 void ShowDownloadInShell(); | 155 void ShowDownloadInShell(); |
| 156 | 156 |
| 157 // Called when the user has validated the download of a dangerous file. | 157 // Called when the user has validated the download of a dangerous file. |
| 158 void DangerousDownloadValidated(); | 158 void DangerousDownloadValidated(); |
| 159 | 159 |
| 160 // Received a new chunk of data | 160 // Received a new chunk of data. |
| 161 void Update(int64 bytes_so_far); | 161 // |bytes_so_far| is the number of bytes received so far. |
| 162 // |partial_hash| is the hash up to this point. It will be an empty string | |
| 163 // if we are not calculating hashes. | |
| 164 void Update(int64 bytes_so_far, const std::string& partial_hash); | |
|
Randy Smith (Not in Mondays)
2011/10/31 18:46:43
Currently, Update is just used to send across size
ahendrickson
2011/11/13 21:15:20
No, Update also sets received_bytes_, which is pas
Randy Smith (Not in Mondays)
2011/11/15 18:35:25
Hmmm. I understand it, but I don't like it; I wan
| |
| 162 | 165 |
| 163 // Cancel the download operation. We need to distinguish between cancels at | 166 // Cancel the download operation. We need to distinguish between cancels at |
| 164 // exit (DownloadManager destructor) from user interface initiated cancels | 167 // exit (DownloadManager destructor) from user interface initiated cancels |
| 165 // 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 |
| 166 // require AddRef'ing the DownloadManager in the destructor which results in | 169 // require AddRef'ing the DownloadManager in the destructor which results in |
| 167 // a DCHECK failure. Set |user_cancel| to false when canceling from at | 170 // a DCHECK failure. Set |user_cancel| to false when canceling from at |
| 168 // 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 |
| 169 // 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 |
| 170 // 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 |
| 171 // when resuming a download (assuming the server supports byte ranges). | 174 // when resuming a download (assuming the server supports byte ranges). |
| 172 void Cancel(bool user_cancel); | 175 void Cancel(bool user_cancel); |
| 173 | 176 |
| 174 // Called by external code (SavePackage) using the DownloadItem interface | 177 // Called by external code (SavePackage) using the DownloadItem interface |
| 175 // to display progress when the DownloadItem should be considered complete. | 178 // to display progress when the DownloadItem should be considered complete. |
| 176 void MarkAsComplete(); | 179 void MarkAsComplete(); |
| 177 | 180 |
| 178 // Called by the delegate after it delayed completing the download in | 181 // Called by the delegate after it delayed completing the download in |
| 179 // DownloadManagerDelegate::ShouldCompleteDownload. | 182 // DownloadManagerDelegate::ShouldCompleteDownload. |
| 180 void CompleteDelayedDownload(); | 183 void CompleteDelayedDownload(); |
| 181 | 184 |
| 182 // Called when all data has been saved. Only has display effects. | 185 // Called when all data has been saved. Only has display effects. |
| 183 void OnAllDataSaved(int64 size); | 186 void OnAllDataSaved(int64 size, const std::string final_hash); |
| 184 | 187 |
| 185 // Called when the downloaded file is removed. | 188 // Called when the downloaded file is removed. |
| 186 void OnDownloadedFileRemoved(); | 189 void OnDownloadedFileRemoved(); |
| 187 | 190 |
| 188 // Download operation had an error. | 191 // Download operation had an error. |
| 189 // |size| is the amount of data received at interruption. | 192 // |size| is the amount of data received at interruption. |
| 193 // |partial_hash| is the current hash value at interruption. | |
| 190 // |reason| is the download interrupt reason code that the operation received. | 194 // |reason| is the download interrupt reason code that the operation received. |
| 191 void Interrupted(int64 size, InterruptReason reason); | 195 void Interrupted(int64 size, |
| 196 const std::string partial_hash, | |
| 197 InterruptReason reason); | |
| 192 | 198 |
| 193 // Deletes the file from disk and removes the download from the views and | 199 // Deletes the file from disk and removes the download from the views and |
| 194 // history. |user| should be true if this is the result of the user clicking | 200 // history. |user| should be true if this is the result of the user clicking |
| 195 // the discard button, and false if it is being deleted for other reasons like | 201 // the discard button, and false if it is being deleted for other reasons like |
| 196 // browser shutdown. | 202 // browser shutdown. |
| 197 void Delete(DeleteReason reason); | 203 void Delete(DeleteReason reason); |
| 198 | 204 |
| 199 // Removes the download from the views and history. | 205 // Removes the download from the views and history. |
| 200 void Remove(); | 206 void Remove(); |
| 201 | 207 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 std::string suggested_filename() const { return suggested_filename_; } | 276 std::string suggested_filename() const { return suggested_filename_; } |
| 271 std::string content_disposition() const { return content_disposition_; } | 277 std::string content_disposition() const { return content_disposition_; } |
| 272 std::string mime_type() const { return mime_type_; } | 278 std::string mime_type() const { return mime_type_; } |
| 273 std::string original_mime_type() const { return original_mime_type_; } | 279 std::string original_mime_type() const { return original_mime_type_; } |
| 274 std::string referrer_charset() const { return referrer_charset_; } | 280 std::string referrer_charset() const { return referrer_charset_; } |
| 275 int64 total_bytes() const { return total_bytes_; } | 281 int64 total_bytes() const { return total_bytes_; } |
| 276 void set_total_bytes(int64 total_bytes) { | 282 void set_total_bytes(int64 total_bytes) { |
| 277 total_bytes_ = total_bytes; | 283 total_bytes_ = total_bytes; |
| 278 } | 284 } |
| 279 int64 received_bytes() const { return received_bytes_; } | 285 int64 received_bytes() const { return received_bytes_; } |
| 286 const std::string& partial_hash() const { return partial_hash_; } | |
| 280 int32 id() const { return download_id_; } | 287 int32 id() const { return download_id_; } |
| 281 DownloadId global_id() const; | 288 DownloadId global_id() const; |
| 282 base::Time start_time() const { return start_time_; } | 289 base::Time start_time() const { return start_time_; } |
| 283 base::Time end_time() const { return end_time_; } | 290 base::Time end_time() const { return end_time_; } |
| 284 void set_db_handle(int64 handle) { db_handle_ = handle; } | 291 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 285 int64 db_handle() const { return db_handle_; } | 292 int64 db_handle() const { return db_handle_; } |
| 286 DownloadManager* download_manager() { return download_manager_; } | 293 DownloadManager* download_manager() { return download_manager_; } |
| 287 bool is_paused() const { return is_paused_; } | 294 bool is_paused() const { return is_paused_; } |
| 288 bool open_when_complete() const { return open_when_complete_; } | 295 bool open_when_complete() const { return open_when_complete_; } |
| 289 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 296 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 290 bool file_externally_removed() const { return file_externally_removed_; } | 297 bool file_externally_removed() const { return file_externally_removed_; } |
| 291 SafetyState safety_state() const { return safety_state_; } | 298 SafetyState safety_state() const { return safety_state_; } |
| 292 // Why |safety_state_| is not SAFE. | 299 // Why |safety_state_| is not SAFE. |
| 293 DangerType GetDangerType() const; | 300 DangerType GetDangerType() const; |
| 294 bool IsDangerous() const; | 301 bool IsDangerous() const; |
| 295 void MarkFileDangerous(); | 302 void MarkFileDangerous(); |
| 296 void MarkUrlDangerous(); | 303 void MarkUrlDangerous(); |
| 297 | 304 |
| 298 bool auto_opened() { return auto_opened_; } | 305 bool auto_opened() { return auto_opened_; } |
| 299 const FilePath& target_name() const { return state_info_.target_name; } | 306 const FilePath& target_name() const { return state_info_.target_name; } |
| 300 bool prompt_user_for_save_location() const { | 307 bool prompt_user_for_save_location() const { |
| 301 return state_info_.prompt_user_for_save_location; | 308 return state_info_.prompt_user_for_save_location; |
| 302 } | 309 } |
| 303 bool is_otr() const { return is_otr_; } | 310 bool is_otr() const { return is_otr_; } |
| 304 const FilePath& suggested_path() const { return state_info_.suggested_path; } | 311 const FilePath& suggested_path() const { return state_info_.suggested_path; } |
| 305 bool is_temporary() const { return is_temporary_; } | 312 bool is_temporary() const { return is_temporary_; } |
| 306 void set_opened(bool opened) { opened_ = opened; } | 313 void set_opened(bool opened) { opened_ = opened; } |
| 307 bool opened() const { return opened_; } | 314 bool opened() const { return opened_; } |
| 308 | 315 |
| 316 const std::string& last_modified_time() const { return last_modified_time_; } | |
| 317 void set_last_modified_time(const std::string& time) { | |
| 318 last_modified_time_ = time; | |
| 319 } | |
| 320 const std::string& etag() const { return etag_; } | |
| 321 void set_etag(const std::string& tag) { etag_ = tag; } | |
| 322 | |
| 309 InterruptReason last_reason() const { return last_reason_; } | 323 InterruptReason last_reason() const { return last_reason_; } |
| 310 | 324 |
| 311 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; | 325 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; |
| 312 DownloadStateInfo state_info() const { return state_info_; } | 326 DownloadStateInfo state_info() const { return state_info_; } |
| 313 const DownloadRequestHandle& request_handle() const { | 327 const DownloadRequestHandle& request_handle() const { |
| 314 return request_handle_; | 328 return request_handle_; |
| 315 } | 329 } |
| 316 | 330 |
| 317 // Returns the final target file path for the download. | 331 // Returns the final target file path for the download. |
| 318 FilePath GetTargetFilePath() const; | 332 FilePath GetTargetFilePath() const; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 344 void MockDownloadOpenForTesting() { open_enabled_ = false; } | 358 void MockDownloadOpenForTesting() { open_enabled_ = false; } |
| 345 | 359 |
| 346 private: | 360 private: |
| 347 // Construction common to all constructors. |active| should be true for new | 361 // Construction common to all constructors. |active| should be true for new |
| 348 // downloads and false for downloads from the history. | 362 // downloads and false for downloads from the history. |
| 349 void Init(bool active); | 363 void Init(bool active); |
| 350 | 364 |
| 351 // Internal helper for maintaining consistent received and total sizes. | 365 // Internal helper for maintaining consistent received and total sizes. |
| 352 void UpdateSize(int64 size); | 366 void UpdateSize(int64 size); |
| 353 | 367 |
| 368 // Internal helper for keeping track of the hash as we receive data. | |
| 369 void UpdateHash(const std::string& partial_hash); | |
| 370 | |
| 354 // Called when the entire download operation (including renaming etc) | 371 // Called when the entire download operation (including renaming etc) |
| 355 // is completed. | 372 // is completed. |
| 356 void Completed(); | 373 void Completed(); |
| 357 | 374 |
| 358 // Start/stop sending periodic updates to our observers | 375 // Start/stop sending periodic updates to our observers |
| 359 void StartProgressTimer(); | 376 void StartProgressTimer(); |
| 360 void StopProgressTimer(); | 377 void StopProgressTimer(); |
| 361 | 378 |
| 362 // Call to transition state; all state transitions should go through this. | 379 // Call to transition state; all state transitions should go through this. |
| 363 void TransitionTo(DownloadState new_state); | 380 void TransitionTo(DownloadState new_state); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 424 |
| 408 // The value of the content type header sent with the downloaded item. It | 425 // The value of the content type header sent with the downloaded item. It |
| 409 // may be different from |mime_type_|, which may be set based on heuristics | 426 // may be different from |mime_type_|, which may be set based on heuristics |
| 410 // which may look at the file extension and first few bytes of the file. | 427 // which may look at the file extension and first few bytes of the file. |
| 411 std::string original_mime_type_; | 428 std::string original_mime_type_; |
| 412 | 429 |
| 413 // The charset of the referring page where the download request comes from. | 430 // The charset of the referring page where the download request comes from. |
| 414 // It's used to construct a suggested filename. | 431 // It's used to construct a suggested filename. |
| 415 std::string referrer_charset_; | 432 std::string referrer_charset_; |
| 416 | 433 |
| 417 // Total bytes expected | 434 // Total bytes expected. |
| 418 int64 total_bytes_; | 435 int64 total_bytes_; |
| 419 | 436 |
| 420 // Current received bytes | 437 // Current received bytes. |
| 421 int64 received_bytes_; | 438 int64 received_bytes_; |
| 422 | 439 |
| 440 // Current hash value. | |
| 441 std::string partial_hash_; | |
| 442 | |
| 443 // Server's time stamp for the file. | |
| 444 std::string last_modified_time_; | |
| 445 | |
| 446 // Server's ETAG for the file. | |
| 447 std::string etag_; | |
| 448 | |
| 423 // Last reason. | 449 // Last reason. |
| 424 InterruptReason last_reason_; | 450 InterruptReason last_reason_; |
| 425 | 451 |
| 426 // Start time for calculating remaining time | 452 // Start time for calculating remaining time. |
| 427 base::TimeTicks start_tick_; | 453 base::TimeTicks start_tick_; |
| 428 | 454 |
| 429 // The current state of this download | 455 // The current state of this download. |
| 430 DownloadState state_; | 456 DownloadState state_; |
| 431 | 457 |
| 432 // The views of this item in the download shelf and download tab | 458 // The views of this item in the download shelf and download tab. |
| 433 ObserverList<Observer> observers_; | 459 ObserverList<Observer> observers_; |
| 434 | 460 |
| 435 // Time the download was started | 461 // Time the download was started. |
| 436 base::Time start_time_; | 462 base::Time start_time_; |
| 437 | 463 |
| 438 // Time the download completed | 464 // Time the download completed. |
| 439 base::Time end_time_; | 465 base::Time end_time_; |
| 440 | 466 |
| 441 // Our persistent store handle | 467 // Our persistent store handle. |
| 442 int64 db_handle_; | 468 int64 db_handle_; |
| 443 | 469 |
| 444 // Timer for regularly updating our observers | 470 // Timer for regularly updating our observers. |
| 445 base::RepeatingTimer<DownloadItem> update_timer_; | 471 base::RepeatingTimer<DownloadItem> update_timer_; |
| 446 | 472 |
| 447 // Our owning object | 473 // Our owning object. |
| 448 DownloadManager* download_manager_; | 474 DownloadManager* download_manager_; |
| 449 | 475 |
| 450 // In progress downloads may be paused by the user, we note it here | 476 // In progress downloads may be paused by the user, we note it here. |
| 451 bool is_paused_; | 477 bool is_paused_; |
| 452 | 478 |
| 453 // A flag for indicating if the download should be opened at completion. | 479 // A flag for indicating if the download should be opened at completion. |
| 454 bool open_when_complete_; | 480 bool open_when_complete_; |
| 455 | 481 |
| 456 // A flag for indicating if the downloaded file is externally removed. | 482 // A flag for indicating if the downloaded file is externally removed. |
| 457 bool file_externally_removed_; | 483 bool file_externally_removed_; |
| 458 | 484 |
| 459 // Indicates if the download is considered potentially safe or dangerous | 485 // Indicates if the download is considered potentially safe or dangerous |
| 460 // (executable files are typically considered dangerous). | 486 // (executable files are typically considered dangerous). |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 484 // only. | 510 // only. |
| 485 bool open_enabled_; | 511 bool open_enabled_; |
| 486 | 512 |
| 487 // Did the delegate delay calling Complete on this download? | 513 // Did the delegate delay calling Complete on this download? |
| 488 bool delegate_delayed_complete_; | 514 bool delegate_delayed_complete_; |
| 489 | 515 |
| 490 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 516 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 491 }; | 517 }; |
| 492 | 518 |
| 493 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 519 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |