Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: content/browser/download/download_item_impl.h

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Overridden from DownloadItem. 104 // Overridden from DownloadItem.
105 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 105 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
106 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 106 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
107 virtual void UpdateObservers() OVERRIDE; 107 virtual void UpdateObservers() OVERRIDE;
108 virtual bool CanShowInFolder() OVERRIDE; 108 virtual bool CanShowInFolder() OVERRIDE;
109 virtual bool CanOpenDownload() OVERRIDE; 109 virtual bool CanOpenDownload() OVERRIDE;
110 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 110 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
111 virtual void OpenDownload() OVERRIDE; 111 virtual void OpenDownload() OVERRIDE;
112 virtual void ShowDownloadInShell() OVERRIDE; 112 virtual void ShowDownloadInShell() OVERRIDE;
113 virtual void DangerousDownloadValidated() OVERRIDE; 113 virtual void DangerousDownloadValidated() OVERRIDE;
114 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; 114 virtual void UpdateProgress(int64 bytes_so_far,
115 int64 bytes_per_sec,
116 const std::string& hash_state) OVERRIDE;
115 virtual void Cancel(bool user_cancel) OVERRIDE; 117 virtual void Cancel(bool user_cancel) OVERRIDE;
116 virtual void MarkAsComplete() OVERRIDE; 118 virtual void MarkAsComplete() OVERRIDE;
117 virtual void DelayedDownloadOpened() OVERRIDE; 119 virtual void DelayedDownloadOpened() OVERRIDE;
118 virtual void OnAllDataSaved( 120 virtual void OnAllDataSaved(
119 int64 size, const std::string& final_hash) OVERRIDE; 121 int64 size, const std::string& final_hash) OVERRIDE;
120 virtual void OnDownloadedFileRemoved() OVERRIDE; 122 virtual void OnDownloadedFileRemoved() OVERRIDE;
121 virtual void MaybeCompleteDownload() OVERRIDE; 123 virtual void MaybeCompleteDownload() OVERRIDE;
122 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; 124 virtual void Interrupted(int64 size,
125 const std::string& hash_state,
126 InterruptReason reason) OVERRIDE;
123 virtual void Delete(DeleteReason reason) OVERRIDE; 127 virtual void Delete(DeleteReason reason) OVERRIDE;
124 virtual void Remove() OVERRIDE; 128 virtual void Remove() OVERRIDE;
125 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 129 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
126 virtual int64 CurrentSpeed() const OVERRIDE; 130 virtual int64 CurrentSpeed() const OVERRIDE;
127 virtual int PercentComplete() const OVERRIDE; 131 virtual int PercentComplete() const OVERRIDE;
128 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; 132 virtual void OnPathDetermined(const FilePath& path) OVERRIDE;
129 virtual bool AllDataSaved() const OVERRIDE; 133 virtual bool AllDataSaved() const OVERRIDE;
130 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; 134 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE;
131 virtual void Rename(const FilePath& full_path) OVERRIDE; 135 virtual void Rename(const FilePath& full_path) OVERRIDE;
132 virtual void TogglePause() OVERRIDE; 136 virtual void TogglePause() OVERRIDE;
(...skipping 15 matching lines...) Expand all
148 virtual std::string GetSuggestedFilename() const OVERRIDE; 152 virtual std::string GetSuggestedFilename() const OVERRIDE;
149 virtual std::string GetContentDisposition() const OVERRIDE; 153 virtual std::string GetContentDisposition() const OVERRIDE;
150 virtual std::string GetMimeType() const OVERRIDE; 154 virtual std::string GetMimeType() const OVERRIDE;
151 virtual std::string GetOriginalMimeType() const OVERRIDE; 155 virtual std::string GetOriginalMimeType() const OVERRIDE;
152 virtual std::string GetReferrerCharset() const OVERRIDE; 156 virtual std::string GetReferrerCharset() const OVERRIDE;
153 virtual std::string GetRemoteAddress() const OVERRIDE; 157 virtual std::string GetRemoteAddress() const OVERRIDE;
154 virtual int64 GetTotalBytes() const OVERRIDE; 158 virtual int64 GetTotalBytes() const OVERRIDE;
155 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 159 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
156 virtual const std::string& GetHash() const OVERRIDE; 160 virtual const std::string& GetHash() const OVERRIDE;
157 virtual int64 GetReceivedBytes() const OVERRIDE; 161 virtual int64 GetReceivedBytes() const OVERRIDE;
162 virtual const std::string& GetHashState() const OVERRIDE;
158 virtual int32 GetId() const OVERRIDE; 163 virtual int32 GetId() const OVERRIDE;
159 virtual DownloadId GetGlobalId() const OVERRIDE; 164 virtual DownloadId GetGlobalId() const OVERRIDE;
160 virtual base::Time GetStartTime() const OVERRIDE; 165 virtual base::Time GetStartTime() const OVERRIDE;
161 virtual base::Time GetEndTime() const OVERRIDE; 166 virtual base::Time GetEndTime() const OVERRIDE;
162 virtual void SetDbHandle(int64 handle) OVERRIDE; 167 virtual void SetDbHandle(int64 handle) OVERRIDE;
163 virtual int64 GetDbHandle() const OVERRIDE; 168 virtual int64 GetDbHandle() const OVERRIDE;
164 virtual bool IsPaused() const OVERRIDE; 169 virtual bool IsPaused() const OVERRIDE;
165 virtual bool GetOpenWhenComplete() const OVERRIDE; 170 virtual bool GetOpenWhenComplete() const OVERRIDE;
166 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 171 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
167 virtual bool GetFileExternallyRemoved() const OVERRIDE; 172 virtual bool GetFileExternallyRemoved() const OVERRIDE;
168 virtual SafetyState GetSafetyState() const OVERRIDE; 173 virtual SafetyState GetSafetyState() const OVERRIDE;
169 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; 174 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE;
170 virtual bool IsDangerous() const OVERRIDE; 175 virtual bool IsDangerous() const OVERRIDE;
171 virtual void MarkFileDangerous() OVERRIDE; 176 virtual void MarkFileDangerous() OVERRIDE;
172 virtual void MarkUrlDangerous() OVERRIDE; 177 virtual void MarkUrlDangerous() OVERRIDE;
173 virtual void MarkContentDangerous() OVERRIDE; 178 virtual void MarkContentDangerous() OVERRIDE;
174 virtual bool GetAutoOpened() OVERRIDE; 179 virtual bool GetAutoOpened() OVERRIDE;
175 virtual const FilePath& GetTargetName() const OVERRIDE; 180 virtual const FilePath& GetTargetName() const OVERRIDE;
176 virtual bool PromptUserForSaveLocation() const OVERRIDE; 181 virtual bool PromptUserForSaveLocation() const OVERRIDE;
177 virtual bool IsOtr() const OVERRIDE; 182 virtual bool IsOtr() const OVERRIDE;
178 virtual const FilePath& GetSuggestedPath() const OVERRIDE; 183 virtual const FilePath& GetSuggestedPath() const OVERRIDE;
179 virtual bool IsTemporary() const OVERRIDE; 184 virtual bool IsTemporary() const OVERRIDE;
180 virtual void SetOpened(bool opened) OVERRIDE; 185 virtual void SetOpened(bool opened) OVERRIDE;
181 virtual bool GetOpened() const OVERRIDE; 186 virtual bool GetOpened() const OVERRIDE;
187 virtual const std::string& GetLastModifiedTime() const OVERRIDE;
188 virtual const std::string& GetETag() const OVERRIDE;
182 virtual InterruptReason GetLastReason() const OVERRIDE; 189 virtual InterruptReason GetLastReason() const OVERRIDE;
183 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; 190 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE;
184 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; 191 virtual DownloadStateInfo GetStateInfo() const OVERRIDE;
185 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; 192 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
186 virtual TabContents* GetTabContents() const OVERRIDE; 193 virtual TabContents* GetTabContents() const OVERRIDE;
187 virtual FilePath GetTargetFilePath() const OVERRIDE; 194 virtual FilePath GetTargetFilePath() const OVERRIDE;
188 virtual FilePath GetFileNameToReportUser() const OVERRIDE; 195 virtual FilePath GetFileNameToReportUser() const OVERRIDE;
189 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; 196 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE;
190 virtual bool NeedsRename() const OVERRIDE; 197 virtual bool NeedsRename() const OVERRIDE;
191 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; 198 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE;
192 virtual std::string DebugString(bool verbose) const OVERRIDE; 199 virtual std::string DebugString(bool verbose) const OVERRIDE;
193 virtual void MockDownloadOpenForTesting() OVERRIDE; 200 virtual void MockDownloadOpenForTesting() OVERRIDE;
194 virtual ExternalData* GetExternalData(const void* key) OVERRIDE; 201 virtual ExternalData* GetExternalData(const void* key) OVERRIDE;
195 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE; 202 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE;
196 203
197 private: 204 private:
198 // Construction common to all constructors. |active| should be true for new 205 // Construction common to all constructors. |active| should be true for new
199 // downloads and false for downloads from the history. 206 // downloads and false for downloads from the history.
200 void Init(bool active); 207 void Init(bool active);
201 208
202 // Internal helper for maintaining consistent received and total sizes. 209 // Internal helper for maintaining consistent received and total sizes, and
203 void UpdateSize(int64 size); 210 // hash state.
211 void UpdateProgress(int64 bytes_so_far, const std::string& hash_state);
212
213 // Internal helper for maintaining consistent received and total sizes, and
214 // setting the final hash.
215 // Should only be called from |OnAllDataSaved|.
216 void ProgressComplete(int64 bytes_so_far,
217 const std::string& final_hash);
204 218
205 // Called when the entire download operation (including renaming etc) 219 // Called when the entire download operation (including renaming etc)
206 // is completed. 220 // is completed.
207 void Completed(); 221 void Completed();
208 222
209 // Call to transition state; all state transitions should go through this. 223 // Call to transition state; all state transitions should go through this.
210 void TransitionTo(DownloadState new_state); 224 void TransitionTo(DownloadState new_state);
211 225
212 // Called when safety_state_ should be recomputed from is_dangerous_file 226 // Called when safety_state_ should be recomputed from is_dangerous_file
213 // and is_dangerous_url. 227 // and is_dangerous_url.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 std::string original_mime_type_; 272 std::string original_mime_type_;
259 273
260 // The charset of the referring page where the download request comes from. 274 // The charset of the referring page where the download request comes from.
261 // It's used to construct a suggested filename. 275 // It's used to construct a suggested filename.
262 std::string referrer_charset_; 276 std::string referrer_charset_;
263 277
264 // The remote IP address where the download was fetched from. Copied from 278 // The remote IP address where the download was fetched from. Copied from
265 // DownloadCreateInfo::remote_address. 279 // DownloadCreateInfo::remote_address.
266 std::string remote_address_; 280 std::string remote_address_;
267 281
268 // Total bytes expected 282 // Total bytes expected.
269 int64 total_bytes_; 283 int64 total_bytes_;
270 284
271 // Current received bytes 285 // Current received bytes.
272 int64 received_bytes_; 286 int64 received_bytes_;
273 287
274 // Current speed. Calculated by the DownloadFile. 288 // Current speed. Calculated by the DownloadFile.
275 int64 bytes_per_sec_; 289 int64 bytes_per_sec_;
276 290
277 // Sha256 hash of the content. This might be empty either because 291 // Sha256 hash of the content. This might be empty either because
278 // the download isn't done yet or because the hash isn't needed 292 // the download isn't done yet or because the hash isn't needed
279 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). 293 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false).
280 std::string hash_; 294 std::string hash_;
281 295
296 // A blob containing the state of the hash algorithm. Only valid while the
297 // download is in progress.
298 std::string hash_state_;
299
300 // Server's time stamp for the file.
301 std::string last_modified_time_;
302
303 // Server's ETAG for the file.
304 std::string etag_;
305
282 // Last reason. 306 // Last reason.
283 InterruptReason last_reason_; 307 InterruptReason last_reason_;
284 308
285 // Start time for recording statistics. 309 // Start time for recording statistics.
286 base::TimeTicks start_tick_; 310 base::TimeTicks start_tick_;
287 311
288 // The current state of this download 312 // The current state of this download.
289 DownloadState state_; 313 DownloadState state_;
290 314
291 // The views of this item in the download shelf and download tab 315 // The views of this item in the download shelf and download tab.
292 ObserverList<Observer> observers_; 316 ObserverList<Observer> observers_;
293 317
294 // Time the download was started 318 // Time the download was started.
295 base::Time start_time_; 319 base::Time start_time_;
296 320
297 // Time the download completed 321 // Time the download completed.
298 base::Time end_time_; 322 base::Time end_time_;
299 323
300 // Our persistent store handle 324 // Our persistent store handle.
301 int64 db_handle_; 325 int64 db_handle_;
302 326
303 // Our delegate. 327 // Our delegate.
304 Delegate* delegate_; 328 Delegate* delegate_;
305 329
306 // In progress downloads may be paused by the user, we note it here 330 // In progress downloads may be paused by the user, we note it here.
307 bool is_paused_; 331 bool is_paused_;
308 332
309 // A flag for indicating if the download should be opened at completion. 333 // A flag for indicating if the download should be opened at completion.
310 bool open_when_complete_; 334 bool open_when_complete_;
311 335
312 // A flag for indicating if the downloaded file is externally removed. 336 // A flag for indicating if the downloaded file is externally removed.
313 bool file_externally_removed_; 337 bool file_externally_removed_;
314 338
315 // Indicates if the download is considered potentially safe or dangerous 339 // Indicates if the download is considered potentially safe or dangerous
316 // (executable files are typically considered dangerous). 340 // (executable files are typically considered dangerous).
(...skipping 27 matching lines...) Expand all
344 bool delegate_delayed_complete_; 368 bool delegate_delayed_complete_;
345 369
346 // External Data storage. All objects in the store 370 // External Data storage. All objects in the store
347 // are owned by the DownloadItemImpl. 371 // are owned by the DownloadItemImpl.
348 std::map<const void*, ExternalData*> external_data_map_; 372 std::map<const void*, ExternalData*> external_data_map_;
349 373
350 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 374 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
351 }; 375 };
352 376
353 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 377 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_file_unittest.cc ('k') | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698