Chromium Code Reviews| Index: chrome/browser/download/download_item.h |
| diff --git a/chrome/browser/download/download_item.h b/chrome/browser/download/download_item.h |
| index 3a6bbd7f649545e25039b9d3762ef3483cd06244..e7cfa70a5b60d87674773b43f581a89445ec675a 100644 |
| --- a/chrome/browser/download/download_item.h |
| +++ b/chrome/browser/download/download_item.h |
| @@ -26,11 +26,13 @@ |
| #include "base/time.h" |
| #include "base/timer.h" |
| #include "chrome/browser/download/download_process_handle.h" |
| +#include "chrome/browser/download/download_state_info.h" |
| +#include "chrome/browser/history/download_history_info.h" |
| #include "googleurl/src/gurl.h" |
| +struct DownloadCreateInfo; |
| class DownloadFileManager; |
| class DownloadManager; |
| -struct DownloadCreateInfo; |
| // One DownloadItem per download. This is the model class that stores all the |
| // state for a download. Multiple views, such as a tab's download shelf and the |
| @@ -41,7 +43,7 @@ class DownloadItem { |
| public: |
| enum DownloadState { |
| // Download is actively progressing. |
| - IN_PROGRESS, |
| + IN_PROGRESS = 0, |
| // Download is completely finished. |
| COMPLETE, |
| @@ -54,7 +56,10 @@ class DownloadItem { |
| REMOVING, |
| // This state indicates that the download has been interrupted. |
| - INTERRUPTED |
| + INTERRUPTED, |
| + |
| + // Maximum value. |
| + MAX_DOWNLOAD_STATE |
| }; |
| enum SafetyState { |
| @@ -101,7 +106,7 @@ class DownloadItem { |
| // Constructing from persistent store: |
| DownloadItem(DownloadManager* download_manager, |
| - const DownloadCreateInfo& info); |
| + const DownloadHistoryInfo& info); |
| // Constructing for a regular download: |
| DownloadItem(DownloadManager* download_manager, |
| @@ -122,7 +127,7 @@ class DownloadItem { |
| // Notifies our observers periodically. |
| void UpdateObservers(); |
| - // Whether it is OK to open this download. |
| + // Returns true if it is OK to open this download. |
| bool CanOpenDownload(); |
| // Tests if a file type should be opened automatically. |
| @@ -191,19 +196,19 @@ class DownloadItem { |
| // total size). |
| int PercentComplete() const; |
| - // Whether or not this download has saved all of its data. |
| + // Called when the final path has been determined. |
| + void OnPathDetermined(const FilePath& path) { history_info_.path = path; } |
| + |
| + // Returns true if this download has saved all of its data. |
| bool all_data_saved() const { return all_data_saved_; } |
| - // Update the fields that may have changed in DownloadCreateInfo as a |
| + // Update the fields that may have changed in DownloadStateInfo as a |
| // result of analyzing the file and figuring out its type, location, etc. |
| // May only be called once. |
| - void SetFileCheckResults(const FilePath& path, |
| - bool is_dangerous_file, |
| - bool is_dangerous_url, |
| - int path_uniquifier, |
| - bool prompt, |
| - bool is_extension_install, |
| - const FilePath& original_name); |
| + void SetFileCheckResults(const DownloadStateInfo& state); |
| + |
| + // Updates the target file. |
| + void UpdateTarget(); |
| // Update the download's path, the actual file is renamed on the download |
| // thread. |
| @@ -239,22 +244,28 @@ class DownloadItem { |
| bool IsComplete() const; |
| // Accessors |
| - DownloadState state() const { return state_; } |
| - FilePath full_path() const { return full_path_; } |
| - void set_path_uniquifier(int uniquifier) { path_uniquifier_ = uniquifier; } |
| - const GURL& url() const { return url_chain_.back(); } |
| - const std::vector<GURL>& url_chain() const { return url_chain_; } |
| - const GURL& original_url() const { return url_chain_.front(); } |
| - const GURL& referrer_url() const { return referrer_url_; } |
| + DownloadState state() const; // TODO(ahendrickson) -- Rename to GetState(). |
|
Randy Smith (Not in Mondays)
2011/05/20 19:49:29
nit: Make the comment explain why. The goal is, i
ahendrickson
2011/05/20 22:12:45
Removed the need.
|
| + FilePath full_path() const { return history_info_.path; } |
| + void set_path_uniquifier(int uniquifier) { |
| + state_info_.path_uniquifier = uniquifier; |
| + } |
| + const GURL& GetURL() const; |
| + const std::vector<GURL>& url_chain() const { return history_info_.url_chain; } |
| + const GURL& original_url() const { return history_info_.url_chain.front(); } |
| + const GURL& referrer_url() const { return history_info_.referrer_url; } |
| + std::string content_disposition() const { return content_disposition_; } |
| std::string mime_type() const { return mime_type_; } |
| std::string original_mime_type() const { return original_mime_type_; } |
| - int64 total_bytes() const { return total_bytes_; } |
| - void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } |
| - int64 received_bytes() const { return received_bytes_; } |
| - int32 id() const { return id_; } |
| - base::Time start_time() const { return start_time_; } |
| - void set_db_handle(int64 handle) { db_handle_ = handle; } |
| - int64 db_handle() const { return db_handle_; } |
| + std::string referrer_charset() const { return referrer_charset_; } |
|
Randy Smith (Not in Mondays)
2011/05/20 19:49:29
This looks like it was added by this CL, but doesn
ahendrickson
2011/05/20 22:12:45
It's part of the request information from Download
|
| + int64 total_bytes() const { return history_info_.total_bytes; } |
| + void set_total_bytes(int64 total_bytes) { |
| + history_info_.total_bytes = total_bytes; |
| + } |
| + int64 received_bytes() const { return history_info_.received_bytes; } |
| + int32 id() const { return history_info_.download_id; } |
| + base::Time start_time() const { return history_info_.start_time; } |
| + void set_db_handle(int64 handle) { history_info_.db_handle = handle; } |
| + int64 db_handle() const { return history_info_.db_handle; } |
| bool is_paused() const { return is_paused_; } |
| bool open_when_complete() const { return open_when_complete_; } |
| void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| @@ -262,16 +273,25 @@ class DownloadItem { |
| void set_safety_state(SafetyState safety_state) { |
| safety_state_ = safety_state; |
| } |
| - DangerType danger_type() { return danger_type_;} |
| + // Why |safety_state_| is not SAFE. |
| + DangerType GetDangerType() const; |
| + bool IsDangerous() const; |
| + void MarkUrlDangerous(); |
| + |
| bool auto_opened() { return auto_opened_; } |
| - FilePath target_name() const { return target_name_; } |
| - bool save_as() const { return save_as_; } |
| + FilePath target_name() const { return state_info_.target_name; } |
| + bool save_as() const { return state_info_.prompt_user_for_save_location; } |
| bool is_otr() const { return is_otr_; } |
| - bool is_extension_install() const { return is_extension_install_; } |
| + bool is_extension_install() const { |
| + return state_info_.is_extension_install; |
| + } |
| + FilePath suggested_path() const { return state_info_.suggested_path; } |
| bool is_temporary() const { return is_temporary_; } |
| void set_opened(bool opened) { opened_ = opened; } |
| bool opened() const { return opened_; } |
| + DownloadHistoryInfo history_info() const { return history_info_; } |
| + DownloadStateInfo state_info() const { return state_info_; } |
| const DownloadProcessHandle& process_handle() const { |
| return process_handle_; |
| } |
| @@ -280,7 +300,7 @@ class DownloadItem { |
| FilePath GetTargetFilePath() const; |
| // Returns the file-name that should be reported to the user, which is |
| - // target_name_ possibly with the uniquifier number. |
| + // target_name possibly with the uniquifier number. |
| FilePath GetFileNameToReportUser() const; |
| // Returns the user-verified target file path for the download. |
| @@ -290,7 +310,7 @@ class DownloadItem { |
| // Returns true if the current file name is not the final target name yet. |
| bool NeedsRename() const { |
| - return target_name_ != full_path_.BaseName(); |
| + return state_info_.target_name != history_info_.path.BaseName(); |
| } |
| std::string DebugString(bool verbose) const; |
| @@ -309,34 +329,31 @@ class DownloadItem { |
| void StartProgressTimer(); |
| void StopProgressTimer(); |
| - // Request ID assigned by the ResourceDispatcherHost. |
| - int32 id_; |
| - |
| - // Full path to the downloaded or downloading file. |
| - FilePath full_path_; |
| + // Information that is saved to the history DB. |
| + DownloadHistoryInfo history_info_; |
| - // A number that should be appended to the path to make it unique, or 0 if the |
| - // path should be used as is. |
| - int path_uniquifier_; |
| + // State information used by the download manager. |
| + DownloadStateInfo state_info_; |
| - // The chain of redirects that leading up to and including the final URL. |
| - std::vector<GURL> url_chain_; |
| + // The handle to the process information. Used for operations outside the |
| + // download system. |
| + DownloadProcessHandle process_handle_; |
| - // The URL of the page that initiated the download. |
| - GURL referrer_url_; |
| + // Information from the request. |
| + // Content-disposition field from the header. |
| + std::string content_disposition_; |
| - // The mimetype of the download |
| + // Mime-type from the header. Subject to change. |
| std::string mime_type_; |
| - // The value of the content type header received when downloading |
| - // this item. |mime_type_| may be different because of type sniffing. |
| + // The value of the content type header sent with the downloaded item. It |
| + // may be different from |mime_type_|, which may be set based on heuristics |
| + // which may look at the file extension and first few bytes of the file. |
| std::string original_mime_type_; |
| - // Total bytes expected |
| - int64 total_bytes_; |
| - |
| - // Current received bytes |
| - int64 received_bytes_; |
| + // The charset of the referring page where the download request comes from. |
| + // It's used to construct a suggested filename. |
| + std::string referrer_charset_; |
| // Last error. |
| int last_os_error_; |
| @@ -344,18 +361,9 @@ class DownloadItem { |
| // Start time for calculating remaining time |
| base::TimeTicks start_tick_; |
| - // The current state of this download |
| - DownloadState state_; |
| - |
| // The views of this item in the download shelf and download tab |
| ObserverList<Observer> observers_; |
| - // Time the download was started |
| - base::Time start_time_; |
| - |
| - // Our persistent store handle |
| - int64 db_handle_; |
| - |
| // Timer for regularly updating our observers |
| base::RepeatingTimer<DownloadItem> update_timer_; |
| @@ -368,36 +376,18 @@ class DownloadItem { |
| // A flag for indicating if the download should be opened at completion. |
| bool open_when_complete_; |
| - // Whether the download is considered potentially safe or dangerous |
| + // Indicates if the download is considered potentially safe or dangerous |
| // (executable files are typically considered dangerous). |
| SafetyState safety_state_; |
| - // Why |safety_state_| is not SAFE. |
| - DangerType danger_type_; |
| - |
| - // Whether the download was auto-opened. We set this rather than using |
| + // True if the download was auto-opened. We set this rather than using |
| // an observer as it's frequently possible for the download to be auto opened |
| // before the observer is added. |
| bool auto_opened_; |
| - // Dangerous downloads or ongoing downloads are given temporary names until |
| - // the user approves them or the downloads finish. |
| - // This stores their final target name. |
| - FilePath target_name_; |
| - |
| - // The handle to the process information. Used for operations outside the |
| - // download system. |
| - DownloadProcessHandle process_handle_; |
| - |
| - // True if the item was downloaded as a result of 'save as...' |
| - bool save_as_; |
| - |
| // True if the download was initiated in an incognito window. |
| bool is_otr_; |
| - // True if the item was downloaded for an extension installation. |
| - bool is_extension_install_; |
| - |
| // True if the item was downloaded temporarily. |
| bool is_temporary_; |