| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/browser/download/download_request_handle.h" | 21 #include "content/browser/download/download_request_handle.h" |
| 22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 23 #include "content/public/browser/download_interrupt_reasons.h" | 23 #include "content/public/browser/download_interrupt_reasons.h" |
| 24 #include "content/public/browser/download_item.h" | 24 #include "content/public/browser/download_item.h" |
| 25 #include "net/log/net_log_with_source.h" | 25 #include "net/log/net_log_with_source.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class DownloadFile; | 29 class DownloadFile; |
| 30 class DownloadItemImplDelegate; | 30 class DownloadItemImplDelegate; |
| 31 class DownloadJob; |
| 31 | 32 |
| 32 // See download_item.h for usage. | 33 // See download_item.h for usage. |
| 33 class CONTENT_EXPORT DownloadItemImpl | 34 class CONTENT_EXPORT DownloadItemImpl |
| 34 : public DownloadItem, | 35 : public DownloadItem, |
| 35 public DownloadDestinationObserver { | 36 public DownloadDestinationObserver { |
| 36 public: | 37 public: |
| 37 enum ResumeMode { | 38 enum ResumeMode { |
| 38 RESUME_MODE_INVALID = 0, | 39 RESUME_MODE_INVALID = 0, |
| 39 RESUME_MODE_IMMEDIATE_CONTINUE, | 40 RESUME_MODE_IMMEDIATE_CONTINUE, |
| 40 RESUME_MODE_IMMEDIATE_RESTART, | 41 RESUME_MODE_IMMEDIATE_RESTART, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void DestinationUpdate(int64_t bytes_so_far, int64_t bytes_per_sec) override; | 226 void DestinationUpdate(int64_t bytes_so_far, int64_t bytes_per_sec) override; |
| 226 void DestinationError( | 227 void DestinationError( |
| 227 DownloadInterruptReason reason, | 228 DownloadInterruptReason reason, |
| 228 int64_t bytes_so_far, | 229 int64_t bytes_so_far, |
| 229 std::unique_ptr<crypto::SecureHash> hash_state) override; | 230 std::unique_ptr<crypto::SecureHash> hash_state) override; |
| 230 void DestinationCompleted( | 231 void DestinationCompleted( |
| 231 int64_t total_bytes, | 232 int64_t total_bytes, |
| 232 std::unique_ptr<crypto::SecureHash> hash_state) override; | 233 std::unique_ptr<crypto::SecureHash> hash_state) override; |
| 233 | 234 |
| 234 private: | 235 private: |
| 236 friend class DownloadJob; |
| 237 |
| 235 // Fine grained states of a download. | 238 // Fine grained states of a download. |
| 236 // | 239 // |
| 237 // New downloads can be created in the following states: | 240 // New downloads can be created in the following states: |
| 238 // | 241 // |
| 239 // INITIAL_INTERNAL: All active new downloads. | 242 // INITIAL_INTERNAL: All active new downloads. |
| 240 // | 243 // |
| 241 // COMPLETE_INTERNAL: Downloads restored from persisted state. | 244 // COMPLETE_INTERNAL: Downloads restored from persisted state. |
| 242 // CANCELLED_INTERNAL: - do - | 245 // CANCELLED_INTERNAL: - do - |
| 243 // INTERRUPTED_INTERNAL: - do - | 246 // INTERRUPTED_INTERNAL: - do - |
| 244 // | 247 // |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // These are listed in approximately chronological order. There are also | 391 // These are listed in approximately chronological order. There are also |
| 389 // public methods involved in normal download progression; see | 392 // public methods involved in normal download progression; see |
| 390 // the implementation ordering in download_item_impl.cc. | 393 // the implementation ordering in download_item_impl.cc. |
| 391 | 394 |
| 392 // Construction common to all constructors. |active| should be true for new | 395 // Construction common to all constructors. |active| should be true for new |
| 393 // downloads and false for downloads from the history. | 396 // downloads and false for downloads from the history. |
| 394 // |download_type| indicates to the net log system what kind of download | 397 // |download_type| indicates to the net log system what kind of download |
| 395 // this is. | 398 // this is. |
| 396 void Init(bool active, DownloadType download_type); | 399 void Init(bool active, DownloadType download_type); |
| 397 | 400 |
| 401 // Start a series of events that result in the file being downloaded. |
| 402 void StartDownload(); |
| 403 |
| 398 // Callback from file thread when we initialize the DownloadFile. | 404 // Callback from file thread when we initialize the DownloadFile. |
| 399 void OnDownloadFileInitialized(DownloadInterruptReason result); | 405 void OnDownloadFileInitialized(DownloadInterruptReason result); |
| 400 | 406 |
| 401 // Called to determine the target path. Will cause OnDownloadTargetDetermined | 407 // Called to determine the target path. Will cause OnDownloadTargetDetermined |
| 402 // to be called when the target information is available. | 408 // to be called when the target information is available. |
| 403 void DetermineDownloadTarget(); | 409 void DetermineDownloadTarget(); |
| 404 | 410 |
| 405 // Called when the target path has been determined. |target_path| is the | 411 // Called when the target path has been determined. |target_path| is the |
| 406 // suggested target path. |disposition| indicates how the target path should | 412 // suggested target path. |disposition| indicates how the target path should |
| 407 // be used (see TargetDisposition). |danger_type| is the danger level of | 413 // be used (see TargetDisposition). |danger_type| is the danger level of |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 static const char* DebugResumeModeString(ResumeMode mode); | 504 static const char* DebugResumeModeString(ResumeMode mode); |
| 499 static bool IsValidSavePackageStateTransition(DownloadInternalState from, | 505 static bool IsValidSavePackageStateTransition(DownloadInternalState from, |
| 500 DownloadInternalState to); | 506 DownloadInternalState to); |
| 501 static bool IsValidStateTransition(DownloadInternalState from, | 507 static bool IsValidStateTransition(DownloadInternalState from, |
| 502 DownloadInternalState to); | 508 DownloadInternalState to); |
| 503 | 509 |
| 504 // Will be false for save package downloads retrieved from the history. | 510 // Will be false for save package downloads retrieved from the history. |
| 505 // TODO(rdsmith): Replace with a generalized enum for "download source". | 511 // TODO(rdsmith): Replace with a generalized enum for "download source". |
| 506 const bool is_save_package_download_ = false; | 512 const bool is_save_package_download_ = false; |
| 507 | 513 |
| 508 // The handle to the request information. Used for operations outside the | |
| 509 // download system. | |
| 510 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; | |
| 511 | |
| 512 std::string guid_; | 514 std::string guid_; |
| 513 | 515 |
| 514 uint32_t download_id_ = kInvalidId; | 516 uint32_t download_id_ = kInvalidId; |
| 515 | 517 |
| 516 // Display name for the download. If this is empty, then the display name is | 518 // Display name for the download. If this is empty, then the display name is |
| 517 // considered to be |target_path_.BaseName()|. | 519 // considered to be |target_path_.BaseName()|. |
| 518 base::FilePath display_name_; | 520 base::FilePath display_name_; |
| 519 | 521 |
| 520 // Target path of an in-progress download. We may be downloading to a | 522 // Target path of an in-progress download. We may be downloading to a |
| 521 // temporary or intermediate file (specified by |current_path_|. Once the | 523 // temporary or intermediate file (specified by |current_path_|. Once the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 593 |
| 592 // Time the download was started. | 594 // Time the download was started. |
| 593 base::Time start_time_; | 595 base::Time start_time_; |
| 594 | 596 |
| 595 // Time the download completed. | 597 // Time the download completed. |
| 596 base::Time end_time_; | 598 base::Time end_time_; |
| 597 | 599 |
| 598 // Our delegate. | 600 // Our delegate. |
| 599 DownloadItemImplDelegate* delegate_ = nullptr; | 601 DownloadItemImplDelegate* delegate_ = nullptr; |
| 600 | 602 |
| 601 // In progress downloads may be paused by the user, we note it here. | |
| 602 bool is_paused_ = false; | |
| 603 | |
| 604 // A flag for indicating if the download should be opened at completion. | 603 // A flag for indicating if the download should be opened at completion. |
| 605 bool open_when_complete_ = false; | 604 bool open_when_complete_ = false; |
| 606 | 605 |
| 607 // A flag for indicating if the downloaded file is externally removed. | 606 // A flag for indicating if the downloaded file is externally removed. |
| 608 bool file_externally_removed_ = false; | 607 bool file_externally_removed_ = false; |
| 609 | 608 |
| 610 // True if the download was auto-opened. We set this rather than using | 609 // True if the download was auto-opened. We set this rather than using |
| 611 // an observer as it's frequently possible for the download to be auto opened | 610 // an observer as it's frequently possible for the download to be auto opened |
| 612 // before the observer is added. | 611 // before the observer is added. |
| 613 bool auto_opened_ = false; | 612 bool auto_opened_ = false; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 676 |
| 678 // Server's ETAG for the file. | 677 // Server's ETAG for the file. |
| 679 std::string etag_; | 678 std::string etag_; |
| 680 | 679 |
| 681 // The data slices that have been received so far. | 680 // The data slices that have been received so far. |
| 682 std::vector<DownloadItem::ReceivedSlice> received_slices_; | 681 std::vector<DownloadItem::ReceivedSlice> received_slices_; |
| 683 | 682 |
| 684 // Net log to use for this download. | 683 // Net log to use for this download. |
| 685 const net::NetLogWithSource net_log_; | 684 const net::NetLogWithSource net_log_; |
| 686 | 685 |
| 686 std::unique_ptr<DownloadJob> job_; |
| 687 |
| 687 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 688 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 688 | 689 |
| 689 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 690 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 690 }; | 691 }; |
| 691 | 692 |
| 692 } // namespace content | 693 } // namespace content |
| 693 | 694 |
| 694 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 695 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |