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

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: Updated comment. 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Overridden from DownloadItem. 115 // Overridden from DownloadItem.
116 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 116 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
117 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 117 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
118 virtual void UpdateObservers() OVERRIDE; 118 virtual void UpdateObservers() OVERRIDE;
119 virtual bool CanShowInFolder() OVERRIDE; 119 virtual bool CanShowInFolder() OVERRIDE;
120 virtual bool CanOpenDownload() OVERRIDE; 120 virtual bool CanOpenDownload() OVERRIDE;
121 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 121 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
122 virtual void OpenDownload() OVERRIDE; 122 virtual void OpenDownload() OVERRIDE;
123 virtual void ShowDownloadInShell() OVERRIDE; 123 virtual void ShowDownloadInShell() OVERRIDE;
124 virtual void DangerousDownloadValidated() OVERRIDE; 124 virtual void DangerousDownloadValidated() OVERRIDE;
125 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; 125 virtual void UpdateProgress(int64 bytes_so_far,
126 int64 bytes_per_sec,
127 const std::string& hash_state) OVERRIDE;
126 virtual void Cancel(bool user_cancel) OVERRIDE; 128 virtual void Cancel(bool user_cancel) OVERRIDE;
127 virtual void MarkAsComplete() OVERRIDE; 129 virtual void MarkAsComplete() OVERRIDE;
128 virtual void DelayedDownloadOpened() OVERRIDE; 130 virtual void DelayedDownloadOpened() OVERRIDE;
129 virtual void OnAllDataSaved( 131 virtual void OnAllDataSaved(
130 int64 size, const std::string& final_hash) OVERRIDE; 132 int64 size, const std::string& final_hash) OVERRIDE;
131 virtual void OnDownloadedFileRemoved() OVERRIDE; 133 virtual void OnDownloadedFileRemoved() OVERRIDE;
132 virtual void MaybeCompleteDownload() OVERRIDE; 134 virtual void MaybeCompleteDownload() OVERRIDE;
133 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; 135 virtual void Interrupted(int64 size,
136 const std::string& hash_state,
137 InterruptReason reason) OVERRIDE;
134 virtual void Delete(DeleteReason reason) OVERRIDE; 138 virtual void Delete(DeleteReason reason) OVERRIDE;
135 virtual void Remove() OVERRIDE; 139 virtual void Remove() OVERRIDE;
136 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 140 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
137 virtual int64 CurrentSpeed() const OVERRIDE; 141 virtual int64 CurrentSpeed() const OVERRIDE;
138 virtual int PercentComplete() const OVERRIDE; 142 virtual int PercentComplete() const OVERRIDE;
139 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; 143 virtual void OnPathDetermined(const FilePath& path) OVERRIDE;
140 virtual bool AllDataSaved() const OVERRIDE; 144 virtual bool AllDataSaved() const OVERRIDE;
141 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; 145 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE;
142 virtual void Rename(const FilePath& full_path) OVERRIDE; 146 virtual void Rename(const FilePath& full_path) OVERRIDE;
143 virtual void TogglePause() OVERRIDE; 147 virtual void TogglePause() OVERRIDE;
(...skipping 15 matching lines...) Expand all
159 virtual std::string GetSuggestedFilename() const OVERRIDE; 163 virtual std::string GetSuggestedFilename() const OVERRIDE;
160 virtual std::string GetContentDisposition() const OVERRIDE; 164 virtual std::string GetContentDisposition() const OVERRIDE;
161 virtual std::string GetMimeType() const OVERRIDE; 165 virtual std::string GetMimeType() const OVERRIDE;
162 virtual std::string GetOriginalMimeType() const OVERRIDE; 166 virtual std::string GetOriginalMimeType() const OVERRIDE;
163 virtual std::string GetReferrerCharset() const OVERRIDE; 167 virtual std::string GetReferrerCharset() const OVERRIDE;
164 virtual std::string GetRemoteAddress() const OVERRIDE; 168 virtual std::string GetRemoteAddress() const OVERRIDE;
165 virtual int64 GetTotalBytes() const OVERRIDE; 169 virtual int64 GetTotalBytes() const OVERRIDE;
166 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; 170 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE;
167 virtual const std::string& GetHash() const OVERRIDE; 171 virtual const std::string& GetHash() const OVERRIDE;
168 virtual int64 GetReceivedBytes() const OVERRIDE; 172 virtual int64 GetReceivedBytes() const OVERRIDE;
173 virtual const std::string& GetHashState() const OVERRIDE;
169 virtual int32 GetId() const OVERRIDE; 174 virtual int32 GetId() const OVERRIDE;
170 virtual DownloadId GetGlobalId() const OVERRIDE; 175 virtual DownloadId GetGlobalId() const OVERRIDE;
171 virtual base::Time GetStartTime() const OVERRIDE; 176 virtual base::Time GetStartTime() const OVERRIDE;
172 virtual base::Time GetEndTime() const OVERRIDE; 177 virtual base::Time GetEndTime() const OVERRIDE;
173 virtual void SetDbHandle(int64 handle) OVERRIDE; 178 virtual void SetDbHandle(int64 handle) OVERRIDE;
174 virtual int64 GetDbHandle() const OVERRIDE; 179 virtual int64 GetDbHandle() const OVERRIDE;
175 virtual bool IsPaused() const OVERRIDE; 180 virtual bool IsPaused() const OVERRIDE;
176 virtual bool GetOpenWhenComplete() const OVERRIDE; 181 virtual bool GetOpenWhenComplete() const OVERRIDE;
177 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 182 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
178 virtual bool GetFileExternallyRemoved() const OVERRIDE; 183 virtual bool GetFileExternallyRemoved() const OVERRIDE;
179 virtual SafetyState GetSafetyState() const OVERRIDE; 184 virtual SafetyState GetSafetyState() const OVERRIDE;
180 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; 185 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE;
181 virtual bool IsDangerous() const OVERRIDE; 186 virtual bool IsDangerous() const OVERRIDE;
182 virtual void MarkFileDangerous() OVERRIDE; 187 virtual void MarkFileDangerous() OVERRIDE;
183 virtual void MarkUrlDangerous() OVERRIDE; 188 virtual void MarkUrlDangerous() OVERRIDE;
184 virtual void MarkContentDangerous() OVERRIDE; 189 virtual void MarkContentDangerous() OVERRIDE;
185 virtual bool GetAutoOpened() OVERRIDE; 190 virtual bool GetAutoOpened() OVERRIDE;
186 virtual const FilePath& GetTargetName() const OVERRIDE; 191 virtual const FilePath& GetTargetName() const OVERRIDE;
187 virtual bool PromptUserForSaveLocation() const OVERRIDE; 192 virtual bool PromptUserForSaveLocation() const OVERRIDE;
188 virtual bool IsOtr() const OVERRIDE; 193 virtual bool IsOtr() const OVERRIDE;
189 virtual const FilePath& GetSuggestedPath() const OVERRIDE; 194 virtual const FilePath& GetSuggestedPath() const OVERRIDE;
190 virtual bool IsTemporary() const OVERRIDE; 195 virtual bool IsTemporary() const OVERRIDE;
191 virtual void SetOpened(bool opened) OVERRIDE; 196 virtual void SetOpened(bool opened) OVERRIDE;
192 virtual bool GetOpened() const OVERRIDE; 197 virtual bool GetOpened() const OVERRIDE;
198 virtual const std::string& GetLastModifiedTime() const OVERRIDE;
199 virtual const std::string& GetETag() const OVERRIDE;
193 virtual InterruptReason GetLastReason() const OVERRIDE; 200 virtual InterruptReason GetLastReason() const OVERRIDE;
194 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; 201 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE;
195 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; 202 virtual DownloadStateInfo GetStateInfo() const OVERRIDE;
196 virtual content::BrowserContext* BrowserContext() const OVERRIDE; 203 virtual content::BrowserContext* BrowserContext() const OVERRIDE;
197 virtual TabContents* GetTabContents() const OVERRIDE; 204 virtual TabContents* GetTabContents() const OVERRIDE;
198 virtual FilePath GetTargetFilePath() const OVERRIDE; 205 virtual FilePath GetTargetFilePath() const OVERRIDE;
199 virtual FilePath GetFileNameToReportUser() const OVERRIDE; 206 virtual FilePath GetFileNameToReportUser() const OVERRIDE;
200 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; 207 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE;
201 virtual bool NeedsRename() const OVERRIDE; 208 virtual bool NeedsRename() const OVERRIDE;
202 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; 209 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE;
203 virtual std::string DebugString(bool verbose) const OVERRIDE; 210 virtual std::string DebugString(bool verbose) const OVERRIDE;
204 virtual void MockDownloadOpenForTesting() OVERRIDE; 211 virtual void MockDownloadOpenForTesting() OVERRIDE;
205 virtual ExternalData* GetExternalData(const void* key) OVERRIDE; 212 virtual ExternalData* GetExternalData(const void* key) OVERRIDE;
206 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE; 213 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE;
207 214
208 private: 215 private:
209 // Construction common to all constructors. |active| should be true for new 216 // Construction common to all constructors. |active| should be true for new
210 // downloads and false for downloads from the history. 217 // downloads and false for downloads from the history.
211 void Init(bool active); 218 void Init(bool active);
212 219
213 // Internal helper for maintaining consistent received and total sizes. 220 // Internal helper for maintaining consistent received and total sizes, and
214 void UpdateSize(int64 size); 221 // hash state.
222 void UpdateProgress(int64 bytes_so_far, const std::string& hash_state);
223
224 // Internal helper for maintaining consistent received and total sizes, and
225 // setting the final hash.
226 // Should only be called from |OnAllDataSaved|.
227 void ProgressComplete(int64 bytes_so_far,
228 const std::string& final_hash);
215 229
216 // Called when the entire download operation (including renaming etc) 230 // Called when the entire download operation (including renaming etc)
217 // is completed. 231 // is completed.
218 void Completed(); 232 void Completed();
219 233
220 // Call to transition state; all state transitions should go through this. 234 // Call to transition state; all state transitions should go through this.
221 void TransitionTo(DownloadState new_state); 235 void TransitionTo(DownloadState new_state);
222 236
223 // Called when safety_state_ should be recomputed from is_dangerous_file 237 // Called when safety_state_ should be recomputed from is_dangerous_file
224 // and is_dangerous_url. 238 // and is_dangerous_url.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 std::string original_mime_type_; 283 std::string original_mime_type_;
270 284
271 // The charset of the referring page where the download request comes from. 285 // The charset of the referring page where the download request comes from.
272 // It's used to construct a suggested filename. 286 // It's used to construct a suggested filename.
273 std::string referrer_charset_; 287 std::string referrer_charset_;
274 288
275 // The remote IP address where the download was fetched from. Copied from 289 // The remote IP address where the download was fetched from. Copied from
276 // DownloadCreateInfo::remote_address. 290 // DownloadCreateInfo::remote_address.
277 std::string remote_address_; 291 std::string remote_address_;
278 292
279 // Total bytes expected 293 // Total bytes expected.
280 int64 total_bytes_; 294 int64 total_bytes_;
281 295
282 // Current received bytes 296 // Current received bytes.
283 int64 received_bytes_; 297 int64 received_bytes_;
284 298
285 // Current speed. Calculated by the DownloadFile. 299 // Current speed. Calculated by the DownloadFile.
286 int64 bytes_per_sec_; 300 int64 bytes_per_sec_;
287 301
288 // Sha256 hash of the content. This might be empty either because 302 // Sha256 hash of the content. This might be empty either because
289 // the download isn't done yet or because the hash isn't needed 303 // the download isn't done yet or because the hash isn't needed
290 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). 304 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false).
291 std::string hash_; 305 std::string hash_;
292 306
307 // A blob containing the state of the hash algorithm. Only valid while the
308 // download is in progress.
309 std::string hash_state_;
310
311 // Server's time stamp for the file.
312 std::string last_modified_time_;
313
314 // Server's ETAG for the file.
315 std::string etag_;
316
293 // Last reason. 317 // Last reason.
294 InterruptReason last_reason_; 318 InterruptReason last_reason_;
295 319
296 // Start time for recording statistics. 320 // Start time for recording statistics.
297 base::TimeTicks start_tick_; 321 base::TimeTicks start_tick_;
298 322
299 // The current state of this download 323 // The current state of this download.
300 DownloadState state_; 324 DownloadState state_;
301 325
302 // The views of this item in the download shelf and download tab 326 // The views of this item in the download shelf and download tab.
303 ObserverList<Observer> observers_; 327 ObserverList<Observer> observers_;
304 328
305 // Time the download was started 329 // Time the download was started.
306 base::Time start_time_; 330 base::Time start_time_;
307 331
308 // Time the download completed 332 // Time the download completed.
309 base::Time end_time_; 333 base::Time end_time_;
310 334
311 // Our persistent store handle 335 // Our persistent store handle.
312 int64 db_handle_; 336 int64 db_handle_;
313 337
314 // Our delegate. 338 // Our delegate.
315 Delegate* delegate_; 339 Delegate* delegate_;
316 340
317 // In progress downloads may be paused by the user, we note it here 341 // In progress downloads may be paused by the user, we note it here.
318 bool is_paused_; 342 bool is_paused_;
319 343
320 // A flag for indicating if the download should be opened at completion. 344 // A flag for indicating if the download should be opened at completion.
321 bool open_when_complete_; 345 bool open_when_complete_;
322 346
323 // A flag for indicating if the downloaded file is externally removed. 347 // A flag for indicating if the downloaded file is externally removed.
324 bool file_externally_removed_; 348 bool file_externally_removed_;
325 349
326 // Indicates if the download is considered potentially safe or dangerous 350 // Indicates if the download is considered potentially safe or dangerous
327 // (executable files are typically considered dangerous). 351 // (executable files are typically considered dangerous).
(...skipping 27 matching lines...) Expand all
355 bool delegate_delayed_complete_; 379 bool delegate_delayed_complete_;
356 380
357 // External Data storage. All objects in the store 381 // External Data storage. All objects in the store
358 // are owned by the DownloadItemImpl. 382 // are owned by the DownloadItemImpl.
359 std::map<const void*, ExternalData*> external_data_map_; 383 std::map<const void*, ExternalData*> external_data_map_;
360 384
361 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 385 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
362 }; 386 };
363 387
364 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 388 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698