Chromium Code Reviews| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 void DestinationUpdate(int64_t bytes_so_far, int64_t bytes_per_sec) override; | 222 void DestinationUpdate(int64_t bytes_so_far, int64_t bytes_per_sec) override; |
| 222 void DestinationError( | 223 void DestinationError( |
| 223 DownloadInterruptReason reason, | 224 DownloadInterruptReason reason, |
| 224 int64_t bytes_so_far, | 225 int64_t bytes_so_far, |
| 225 std::unique_ptr<crypto::SecureHash> hash_state) override; | 226 std::unique_ptr<crypto::SecureHash> hash_state) override; |
| 226 void DestinationCompleted( | 227 void DestinationCompleted( |
| 227 int64_t total_bytes, | 228 int64_t total_bytes, |
| 228 std::unique_ptr<crypto::SecureHash> hash_state) override; | 229 std::unique_ptr<crypto::SecureHash> hash_state) override; |
| 229 | 230 |
| 230 private: | 231 private: |
| 232 friend class DownloadJob; | |
| 233 | |
| 231 // Fine grained states of a download. | 234 // Fine grained states of a download. |
| 232 // | 235 // |
| 233 // New downloads can be created in the following states: | 236 // New downloads can be created in the following states: |
| 234 // | 237 // |
| 235 // INITIAL_INTERNAL: All active new downloads. | 238 // INITIAL_INTERNAL: All active new downloads. |
| 236 // | 239 // |
| 237 // COMPLETE_INTERNAL: Downloads restored from persisted state. | 240 // COMPLETE_INTERNAL: Downloads restored from persisted state. |
| 238 // CANCELLED_INTERNAL: - do - | 241 // CANCELLED_INTERNAL: - do - |
| 239 // INTERRUPTED_INTERNAL: - do - | 242 // INTERRUPTED_INTERNAL: - do - |
| 240 // | 243 // |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 // These are listed in approximately chronological order. There are also | 387 // These are listed in approximately chronological order. There are also |
| 385 // public methods involved in normal download progression; see | 388 // public methods involved in normal download progression; see |
| 386 // the implementation ordering in download_item_impl.cc. | 389 // the implementation ordering in download_item_impl.cc. |
| 387 | 390 |
| 388 // Construction common to all constructors. |active| should be true for new | 391 // Construction common to all constructors. |active| should be true for new |
| 389 // downloads and false for downloads from the history. | 392 // downloads and false for downloads from the history. |
| 390 // |download_type| indicates to the net log system what kind of download | 393 // |download_type| indicates to the net log system what kind of download |
| 391 // this is. | 394 // this is. |
| 392 void Init(bool active, DownloadType download_type); | 395 void Init(bool active, DownloadType download_type); |
| 393 | 396 |
| 397 // Start a series of events that result in the file being downloaded. | |
| 398 void StartDownloadProgress(); | |
|
qinmin
2017/02/23 07:26:57
nit: StartDownloadProgress() doesn't sounds like a
xingliu
2017/02/24 23:43:13
Done, changed to StartDownload.
| |
| 399 | |
| 394 // Callback from file thread when we initialize the DownloadFile. | 400 // Callback from file thread when we initialize the DownloadFile. |
| 395 void OnDownloadFileInitialized(DownloadInterruptReason result); | 401 void OnDownloadFileInitialized(DownloadInterruptReason result); |
| 396 | 402 |
| 397 // Called to determine the target path. Will cause OnDownloadTargetDetermined | 403 // Called to determine the target path. Will cause OnDownloadTargetDetermined |
| 398 // to be called when the target information is available. | 404 // to be called when the target information is available. |
| 399 void DetermineDownloadTarget(); | 405 void DetermineDownloadTarget(); |
| 400 | 406 |
| 401 // Called when the target path has been determined. |target_path| is the | 407 // Called when the target path has been determined. |target_path| is the |
| 402 // suggested target path. |disposition| indicates how the target path should | 408 // suggested target path. |disposition| indicates how the target path should |
| 403 // be used (see TargetDisposition). |danger_type| is the danger level of | 409 // be used (see TargetDisposition). |danger_type| is the danger level of |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 static const char* DebugResumeModeString(ResumeMode mode); | 500 static const char* DebugResumeModeString(ResumeMode mode); |
| 495 static bool IsValidSavePackageStateTransition(DownloadInternalState from, | 501 static bool IsValidSavePackageStateTransition(DownloadInternalState from, |
| 496 DownloadInternalState to); | 502 DownloadInternalState to); |
| 497 static bool IsValidStateTransition(DownloadInternalState from, | 503 static bool IsValidStateTransition(DownloadInternalState from, |
| 498 DownloadInternalState to); | 504 DownloadInternalState to); |
| 499 | 505 |
| 500 // Will be false for save package downloads retrieved from the history. | 506 // Will be false for save package downloads retrieved from the history. |
| 501 // TODO(rdsmith): Replace with a generalized enum for "download source". | 507 // TODO(rdsmith): Replace with a generalized enum for "download source". |
| 502 const bool is_save_package_download_ = false; | 508 const bool is_save_package_download_ = false; |
| 503 | 509 |
| 504 // The handle to the request information. Used for operations outside the | |
| 505 // download system. | |
| 506 std::unique_ptr<DownloadRequestHandleInterface> request_handle_; | |
| 507 | |
| 508 std::string guid_; | 510 std::string guid_; |
| 509 | 511 |
| 510 uint32_t download_id_ = kInvalidId; | 512 uint32_t download_id_ = kInvalidId; |
| 511 | 513 |
| 512 // Display name for the download. If this is empty, then the display name is | 514 // Display name for the download. If this is empty, then the display name is |
| 513 // considered to be |target_path_.BaseName()|. | 515 // considered to be |target_path_.BaseName()|. |
| 514 base::FilePath display_name_; | 516 base::FilePath display_name_; |
| 515 | 517 |
| 516 // Target path of an in-progress download. We may be downloading to a | 518 // Target path of an in-progress download. We may be downloading to a |
| 517 // temporary or intermediate file (specified by |current_path_|. Once the | 519 // temporary or intermediate file (specified by |current_path_|. Once the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 589 |
| 588 // Time the download was started. | 590 // Time the download was started. |
| 589 base::Time start_time_; | 591 base::Time start_time_; |
| 590 | 592 |
| 591 // Time the download completed. | 593 // Time the download completed. |
| 592 base::Time end_time_; | 594 base::Time end_time_; |
| 593 | 595 |
| 594 // Our delegate. | 596 // Our delegate. |
| 595 DownloadItemImplDelegate* delegate_ = nullptr; | 597 DownloadItemImplDelegate* delegate_ = nullptr; |
| 596 | 598 |
| 597 // In progress downloads may be paused by the user, we note it here. | |
| 598 bool is_paused_ = false; | |
| 599 | |
| 600 // A flag for indicating if the download should be opened at completion. | 599 // A flag for indicating if the download should be opened at completion. |
| 601 bool open_when_complete_ = false; | 600 bool open_when_complete_ = false; |
| 602 | 601 |
| 603 // A flag for indicating if the downloaded file is externally removed. | 602 // A flag for indicating if the downloaded file is externally removed. |
| 604 bool file_externally_removed_ = false; | 603 bool file_externally_removed_ = false; |
| 605 | 604 |
| 606 // True if the download was auto-opened. We set this rather than using | 605 // True if the download was auto-opened. We set this rather than using |
| 607 // an observer as it's frequently possible for the download to be auto opened | 606 // an observer as it's frequently possible for the download to be auto opened |
| 608 // before the observer is added. | 607 // before the observer is added. |
| 609 bool auto_opened_ = false; | 608 bool auto_opened_ = false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 | 669 |
| 671 // Contents of the Last-Modified header for the most recent server response. | 670 // Contents of the Last-Modified header for the most recent server response. |
| 672 std::string last_modified_time_; | 671 std::string last_modified_time_; |
| 673 | 672 |
| 674 // Server's ETAG for the file. | 673 // Server's ETAG for the file. |
| 675 std::string etag_; | 674 std::string etag_; |
| 676 | 675 |
| 677 // Net log to use for this download. | 676 // Net log to use for this download. |
| 678 const net::NetLogWithSource net_log_; | 677 const net::NetLogWithSource net_log_; |
| 679 | 678 |
| 679 std::unique_ptr<DownloadJob> job_; | |
| 680 | |
| 680 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 681 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 681 | 682 |
| 682 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 683 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 683 }; | 684 }; |
| 684 | 685 |
| 685 } // namespace content | 686 } // namespace content |
| 686 | 687 |
| 687 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 688 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |