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 #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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 // Overridden from DownloadItem. | 57 // Overridden from DownloadItem. |
| 58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 60 virtual void UpdateObservers() OVERRIDE; | 60 virtual void UpdateObservers() OVERRIDE; |
| 61 virtual bool CanShowInFolder() OVERRIDE; | 61 virtual bool CanShowInFolder() OVERRIDE; |
| 62 virtual bool CanOpenDownload() OVERRIDE; | 62 virtual bool CanOpenDownload() OVERRIDE; |
| 63 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 63 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 64 virtual void OpenDownload() OVERRIDE; | 64 virtual void OpenDownload() OVERRIDE; |
| 65 virtual void ShowDownloadInShell() OVERRIDE; | 65 virtual void ShowDownloadInShell() OVERRIDE; |
| 66 virtual void DangerousDownloadValidated() OVERRIDE; | 66 virtual void DangerousDownloadValidated() OVERRIDE; |
| 67 virtual void Update(int64 bytes_so_far) OVERRIDE; | 67 virtual void Update(int64 bytes_so_far, |
| 68 const std::string& hash_state) OVERRIDE; | |
| 68 virtual void Cancel(bool user_cancel) OVERRIDE; | 69 virtual void Cancel(bool user_cancel) OVERRIDE; |
| 69 virtual void MarkAsComplete() OVERRIDE; | 70 virtual void MarkAsComplete() OVERRIDE; |
| 70 virtual void DelayedDownloadOpened() OVERRIDE; | 71 virtual void DelayedDownloadOpened() OVERRIDE; |
| 71 virtual void OnAllDataSaved( | 72 virtual void OnAllDataSaved( |
| 72 int64 size, const std::string& final_hash) OVERRIDE; | 73 int64 size, const std::string& final_hash) OVERRIDE; |
| 73 virtual void OnDownloadedFileRemoved() OVERRIDE; | 74 virtual void OnDownloadedFileRemoved() OVERRIDE; |
| 74 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; | 75 virtual void Interrupted(int64 size, |
| 76 const std::string& hash_state, | |
| 77 InterruptReason reason) OVERRIDE; | |
| 75 virtual void Delete(DeleteReason reason) OVERRIDE; | 78 virtual void Delete(DeleteReason reason) OVERRIDE; |
| 76 virtual void Remove() OVERRIDE; | 79 virtual void Remove() OVERRIDE; |
| 77 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; | 80 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; |
| 78 virtual int64 CurrentSpeed() const OVERRIDE; | 81 virtual int64 CurrentSpeed() const OVERRIDE; |
| 79 virtual int PercentComplete() const OVERRIDE; | 82 virtual int PercentComplete() const OVERRIDE; |
| 80 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; | 83 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; |
| 81 virtual bool AllDataSaved() const OVERRIDE; | 84 virtual bool AllDataSaved() const OVERRIDE; |
| 82 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; | 85 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; |
| 83 virtual void Rename(const FilePath& full_path) OVERRIDE; | 86 virtual void Rename(const FilePath& full_path) OVERRIDE; |
| 84 virtual void TogglePause() OVERRIDE; | 87 virtual void TogglePause() OVERRIDE; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 99 virtual const GURL& GetReferrerUrl() const OVERRIDE; | 102 virtual const GURL& GetReferrerUrl() const OVERRIDE; |
| 100 virtual std::string GetSuggestedFilename() const OVERRIDE; | 103 virtual std::string GetSuggestedFilename() const OVERRIDE; |
| 101 virtual std::string GetContentDisposition() const OVERRIDE; | 104 virtual std::string GetContentDisposition() const OVERRIDE; |
| 102 virtual std::string GetMimeType() const OVERRIDE; | 105 virtual std::string GetMimeType() const OVERRIDE; |
| 103 virtual std::string GetOriginalMimeType() const OVERRIDE; | 106 virtual std::string GetOriginalMimeType() const OVERRIDE; |
| 104 virtual std::string GetReferrerCharset() const OVERRIDE; | 107 virtual std::string GetReferrerCharset() const OVERRIDE; |
| 105 virtual int64 GetTotalBytes() const OVERRIDE; | 108 virtual int64 GetTotalBytes() const OVERRIDE; |
| 106 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 109 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
| 107 virtual const std::string& GetHash() const OVERRIDE; | 110 virtual const std::string& GetHash() const OVERRIDE; |
| 108 virtual int64 GetReceivedBytes() const OVERRIDE; | 111 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 112 virtual const std::string& GetHashState() const OVERRIDE; | |
| 109 virtual int32 GetId() const OVERRIDE; | 113 virtual int32 GetId() const OVERRIDE; |
| 110 virtual DownloadId GetGlobalId() const OVERRIDE; | 114 virtual DownloadId GetGlobalId() const OVERRIDE; |
| 111 virtual base::Time GetStartTime() const OVERRIDE; | 115 virtual base::Time GetStartTime() const OVERRIDE; |
| 112 virtual base::Time GetEndTime() const OVERRIDE; | 116 virtual base::Time GetEndTime() const OVERRIDE; |
| 113 virtual void SetDbHandle(int64 handle) OVERRIDE; | 117 virtual void SetDbHandle(int64 handle) OVERRIDE; |
| 114 virtual int64 GetDbHandle() const OVERRIDE; | 118 virtual int64 GetDbHandle() const OVERRIDE; |
| 115 virtual DownloadManager* GetDownloadManager() OVERRIDE; | 119 virtual DownloadManager* GetDownloadManager() OVERRIDE; |
| 116 virtual bool IsPaused() const OVERRIDE; | 120 virtual bool IsPaused() const OVERRIDE; |
| 117 virtual bool GetOpenWhenComplete() const OVERRIDE; | 121 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 118 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 122 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 119 virtual bool GetFileExternallyRemoved() const OVERRIDE; | 123 virtual bool GetFileExternallyRemoved() const OVERRIDE; |
| 120 virtual SafetyState GetSafetyState() const OVERRIDE; | 124 virtual SafetyState GetSafetyState() const OVERRIDE; |
| 121 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; | 125 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; |
| 122 virtual bool IsDangerous() const OVERRIDE; | 126 virtual bool IsDangerous() const OVERRIDE; |
| 123 virtual void MarkFileDangerous() OVERRIDE; | 127 virtual void MarkFileDangerous() OVERRIDE; |
| 124 virtual void MarkUrlDangerous() OVERRIDE; | 128 virtual void MarkUrlDangerous() OVERRIDE; |
| 125 virtual void MarkContentDangerous() OVERRIDE; | 129 virtual void MarkContentDangerous() OVERRIDE; |
| 126 virtual bool GetAutoOpened() OVERRIDE; | 130 virtual bool GetAutoOpened() OVERRIDE; |
| 127 virtual const FilePath& GetTargetName() const OVERRIDE; | 131 virtual const FilePath& GetTargetName() const OVERRIDE; |
| 128 virtual bool PromptUserForSaveLocation() const OVERRIDE; | 132 virtual bool PromptUserForSaveLocation() const OVERRIDE; |
| 129 virtual bool IsOtr() const OVERRIDE; | 133 virtual bool IsOtr() const OVERRIDE; |
| 130 virtual const FilePath& GetSuggestedPath() const OVERRIDE; | 134 virtual const FilePath& GetSuggestedPath() const OVERRIDE; |
| 131 virtual bool IsTemporary() const OVERRIDE; | 135 virtual bool IsTemporary() const OVERRIDE; |
| 132 virtual void SetOpened(bool opened) OVERRIDE; | 136 virtual void SetOpened(bool opened) OVERRIDE; |
| 133 virtual bool GetOpened() const OVERRIDE; | 137 virtual bool GetOpened() const OVERRIDE; |
| 138 virtual const std::string& GetLastModifiedTime() const OVERRIDE; | |
| 139 virtual const std::string& GetETag() const OVERRIDE; | |
| 134 virtual InterruptReason GetLastReason() const OVERRIDE; | 140 virtual InterruptReason GetLastReason() const OVERRIDE; |
| 135 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; | 141 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; |
| 136 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; | 142 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; |
| 137 virtual TabContents* GetTabContents() const OVERRIDE; | 143 virtual TabContents* GetTabContents() const OVERRIDE; |
| 138 virtual FilePath GetTargetFilePath() const OVERRIDE; | 144 virtual FilePath GetTargetFilePath() const OVERRIDE; |
| 139 virtual FilePath GetFileNameToReportUser() const OVERRIDE; | 145 virtual FilePath GetFileNameToReportUser() const OVERRIDE; |
| 140 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; | 146 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; |
| 141 virtual bool NeedsRename() const OVERRIDE; | 147 virtual bool NeedsRename() const OVERRIDE; |
| 142 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; | 148 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; |
| 143 virtual std::string DebugString(bool verbose) const OVERRIDE; | 149 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 144 virtual void MockDownloadOpenForTesting() OVERRIDE; | 150 virtual void MockDownloadOpenForTesting() OVERRIDE; |
| 145 | 151 |
| 146 private: | 152 private: |
| 147 // Construction common to all constructors. |active| should be true for new | 153 // Construction common to all constructors. |active| should be true for new |
| 148 // downloads and false for downloads from the history. | 154 // downloads and false for downloads from the history. |
| 149 void Init(bool active); | 155 void Init(bool active); |
| 150 | 156 |
| 157 // Internal helper for maintaining consistent received and total sizes, and | |
| 158 // hash state. | |
| 159 void UpdateProgress(int64 bytes_so_far, const std::string& hash_state); | |
| 160 | |
| 151 // Internal helper for maintaining consistent received and total sizes. | 161 // Internal helper for maintaining consistent received and total sizes. |
|
Randy Smith (Not in Mondays)
2011/11/23 19:25:13
nit: Also hash state (conceptually, though you mig
ahendrickson
2011/12/20 00:04:14
Done.
| |
| 152 void UpdateSize(int64 size); | 162 // Should only be called from |OnAllDataSaved|. |
| 163 void ProgressComplete(int64 bytes_so_far, | |
| 164 const std::string& final_hash); | |
| 153 | 165 |
| 154 // Called when the entire download operation (including renaming etc) | 166 // Called when the entire download operation (including renaming etc) |
| 155 // is completed. | 167 // is completed. |
| 156 void Completed(); | 168 void Completed(); |
| 157 | 169 |
| 158 // Call to transition state; all state transitions should go through this. | 170 // Call to transition state; all state transitions should go through this. |
| 159 void TransitionTo(DownloadState new_state); | 171 void TransitionTo(DownloadState new_state); |
| 160 | 172 |
| 161 // Called when safety_state_ should be recomputed from is_dangerous_file | 173 // Called when safety_state_ should be recomputed from is_dangerous_file |
| 162 // and is_dangerous_url. | 174 // and is_dangerous_url. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 215 |
| 204 // The value of the content type header sent with the downloaded item. It | 216 // The value of the content type header sent with the downloaded item. It |
| 205 // may be different from |mime_type_|, which may be set based on heuristics | 217 // may be different from |mime_type_|, which may be set based on heuristics |
| 206 // which may look at the file extension and first few bytes of the file. | 218 // which may look at the file extension and first few bytes of the file. |
| 207 std::string original_mime_type_; | 219 std::string original_mime_type_; |
| 208 | 220 |
| 209 // The charset of the referring page where the download request comes from. | 221 // The charset of the referring page where the download request comes from. |
| 210 // It's used to construct a suggested filename. | 222 // It's used to construct a suggested filename. |
| 211 std::string referrer_charset_; | 223 std::string referrer_charset_; |
| 212 | 224 |
| 213 // Total bytes expected | 225 // Total bytes expected. |
| 214 int64 total_bytes_; | 226 int64 total_bytes_; |
| 215 | 227 |
| 216 // Current received bytes | 228 // Current received bytes. |
| 217 int64 received_bytes_; | 229 int64 received_bytes_; |
| 218 | 230 |
| 219 // Sha256 hash of the content. This might be empty either because | 231 // Sha256 hash of the content. This might be empty either because |
| 220 // the download isn't done yet or because the hash isn't needed | 232 // the download isn't done yet or because the hash isn't needed |
| 221 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). | 233 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). |
| 222 std::string hash_; | 234 std::string hash_; |
| 223 | 235 |
| 236 // A blob containing the state of the hash algorithm. Only valid while the | |
| 237 // download is in progress. | |
| 238 std::string hash_state_; | |
| 239 | |
| 240 // Server's time stamp for the file. | |
| 241 std::string last_modified_time_; | |
| 242 | |
| 243 // Server's ETAG for the file. | |
| 244 std::string etag_; | |
| 245 | |
| 224 // Last reason. | 246 // Last reason. |
| 225 InterruptReason last_reason_; | 247 InterruptReason last_reason_; |
| 226 | 248 |
| 227 // Start time for calculating remaining time | 249 // Start time for calculating remaining time. |
| 228 base::TimeTicks start_tick_; | 250 base::TimeTicks start_tick_; |
| 229 | 251 |
| 230 // The current state of this download | 252 // The current state of this download. |
| 231 DownloadState state_; | 253 DownloadState state_; |
| 232 | 254 |
| 233 // The views of this item in the download shelf and download tab | 255 // The views of this item in the download shelf and download tab. |
| 234 ObserverList<Observer> observers_; | 256 ObserverList<Observer> observers_; |
| 235 | 257 |
| 236 // Time the download was started | 258 // Time the download was started. |
| 237 base::Time start_time_; | 259 base::Time start_time_; |
| 238 | 260 |
| 239 // Time the download completed | 261 // Time the download completed. |
| 240 base::Time end_time_; | 262 base::Time end_time_; |
| 241 | 263 |
| 242 // Our persistent store handle | 264 // Our persistent store handle. |
| 243 int64 db_handle_; | 265 int64 db_handle_; |
| 244 | 266 |
| 245 // Our owning object | 267 // Our owning object. |
| 246 DownloadManager* download_manager_; | 268 DownloadManager* download_manager_; |
| 247 | 269 |
| 248 // In progress downloads may be paused by the user, we note it here | 270 // In progress downloads may be paused by the user, we note it here. |
| 249 bool is_paused_; | 271 bool is_paused_; |
| 250 | 272 |
| 251 // A flag for indicating if the download should be opened at completion. | 273 // A flag for indicating if the download should be opened at completion. |
| 252 bool open_when_complete_; | 274 bool open_when_complete_; |
| 253 | 275 |
| 254 // A flag for indicating if the downloaded file is externally removed. | 276 // A flag for indicating if the downloaded file is externally removed. |
| 255 bool file_externally_removed_; | 277 bool file_externally_removed_; |
| 256 | 278 |
| 257 // Indicates if the download is considered potentially safe or dangerous | 279 // Indicates if the download is considered potentially safe or dangerous |
| 258 // (executable files are typically considered dangerous). | 280 // (executable files are typically considered dangerous). |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 282 // only. | 304 // only. |
| 283 bool open_enabled_; | 305 bool open_enabled_; |
| 284 | 306 |
| 285 // Did the delegate delay calling Complete on this download? | 307 // Did the delegate delay calling Complete on this download? |
| 286 bool delegate_delayed_complete_; | 308 bool delegate_delayed_complete_; |
| 287 | 309 |
| 288 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 310 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 289 }; | 311 }; |
| 290 | 312 |
| 291 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 313 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |