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

Side by Side Diff: content/browser/download/download_item.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, 1 month 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 // Each download is represented by a DownloadItem, and all DownloadItems 5 // Each download is represented by a DownloadItem, and all DownloadItems
6 // are owned by the DownloadManager which maintains a global list of all 6 // are owned by the DownloadManager which maintains a global list of all
7 // downloads. DownloadItems are created when a user initiates a download, 7 // downloads. DownloadItems are created when a user initiates a download,
8 // and exist for the duration of the browser life time. 8 // and exist for the duration of the browser life time.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Open the file associated with this download (wait for the download to 156 // Open the file associated with this download (wait for the download to
157 // complete if it is in progress). 157 // complete if it is in progress).
158 void OpenDownload(); 158 void OpenDownload();
159 159
160 // Show the download via the OS shell. 160 // Show the download via the OS shell.
161 void ShowDownloadInShell(); 161 void ShowDownloadInShell();
162 162
163 // Called when the user has validated the download of a dangerous file. 163 // Called when the user has validated the download of a dangerous file.
164 void DangerousDownloadValidated(); 164 void DangerousDownloadValidated();
165 165
166 // Received a new chunk of data 166 // Received a new chunk of data.
167 void Update(int64 bytes_so_far); 167 // |bytes_so_far| is the number of bytes received so far.
168 // |partial_hash| is the hash up to this point. It will be an empty string
169 // if we are not calculating hashes.
170 void Update(int64 bytes_so_far, const std::string& partial_hash);
168 171
169 // Cancel the download operation. We need to distinguish between cancels at 172 // Cancel the download operation. We need to distinguish between cancels at
170 // exit (DownloadManager destructor) from user interface initiated cancels 173 // exit (DownloadManager destructor) from user interface initiated cancels
171 // because at exit, the history system may not exist, and any updates to it 174 // because at exit, the history system may not exist, and any updates to it
172 // require AddRef'ing the DownloadManager in the destructor which results in 175 // require AddRef'ing the DownloadManager in the destructor which results in
173 // a DCHECK failure. Set |user_cancel| to false when canceling from at 176 // a DCHECK failure. Set |user_cancel| to false when canceling from at
174 // exit to prevent this crash. This may result in a difference between the 177 // exit to prevent this crash. This may result in a difference between the
175 // downloaded file's size on disk, and what the history system's last record 178 // downloaded file's size on disk, and what the history system's last record
176 // of it is. At worst, we'll end up re-downloading a small portion of the file 179 // of it is. At worst, we'll end up re-downloading a small portion of the file
177 // when resuming a download (assuming the server supports byte ranges). 180 // when resuming a download (assuming the server supports byte ranges).
178 void Cancel(bool user_cancel); 181 void Cancel(bool user_cancel);
179 182
180 // Called by external code (SavePackage) using the DownloadItem interface 183 // Called by external code (SavePackage) using the DownloadItem interface
181 // to display progress when the DownloadItem should be considered complete. 184 // to display progress when the DownloadItem should be considered complete.
182 void MarkAsComplete(); 185 void MarkAsComplete();
183 186
184 // Called by the delegate after it delayed opening the download in 187 // Called by the delegate after it delayed opening the download in
185 // DownloadManagerDelegate::ShouldOpenDownload. 188 // DownloadManagerDelegate::ShouldOpenDownload.
186 void DelayedDownloadOpened(); 189 void DelayedDownloadOpened();
187 190
188 // Called when all data has been saved. 191 // Called when all data has been saved.
189 void OnAllDataSaved(int64 size, const std::string& final_hash); 192 void OnAllDataSaved(int64 size, const std::string& final_hash);
190 193
191 // Called when the downloaded file is removed. 194 // Called when the downloaded file is removed.
192 void OnDownloadedFileRemoved(); 195 void OnDownloadedFileRemoved();
193 196
194 // Download operation had an error. 197 // Download operation had an error.
195 // |size| is the amount of data received at interruption. 198 // |size| is the amount of data received at interruption.
199 // |partial_hash| is the current hash value at interruption.
196 // |reason| is the download interrupt reason code that the operation received. 200 // |reason| is the download interrupt reason code that the operation received.
197 void Interrupted(int64 size, InterruptReason reason); 201 void Interrupted(int64 size,
202 const std::string partial_hash,
203 InterruptReason reason);
198 204
199 // Deletes the file from disk and removes the download from the views and 205 // Deletes the file from disk and removes the download from the views and
200 // history. |user| should be true if this is the result of the user clicking 206 // history. |user| should be true if this is the result of the user clicking
201 // the discard button, and false if it is being deleted for other reasons like 207 // the discard button, and false if it is being deleted for other reasons like
202 // browser shutdown. 208 // browser shutdown.
203 void Delete(DeleteReason reason); 209 void Delete(DeleteReason reason);
204 210
205 // Removes the download from the views and history. 211 // Removes the download from the views and history.
206 void Remove(); 212 void Remove();
207 213
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 const FilePath& target_name() const { return state_info_.target_name; } 312 const FilePath& target_name() const { return state_info_.target_name; }
307 bool prompt_user_for_save_location() const { 313 bool prompt_user_for_save_location() const {
308 return state_info_.prompt_user_for_save_location; 314 return state_info_.prompt_user_for_save_location;
309 } 315 }
310 bool is_otr() const { return is_otr_; } 316 bool is_otr() const { return is_otr_; }
311 const FilePath& suggested_path() const { return state_info_.suggested_path; } 317 const FilePath& suggested_path() const { return state_info_.suggested_path; }
312 bool is_temporary() const { return is_temporary_; } 318 bool is_temporary() const { return is_temporary_; }
313 void set_opened(bool opened) { opened_ = opened; } 319 void set_opened(bool opened) { opened_ = opened; }
314 bool opened() const { return opened_; } 320 bool opened() const { return opened_; }
315 321
322 const std::string& last_modified_time() const { return last_modified_time_; }
323 void set_last_modified_time(const std::string& time) {
324 last_modified_time_ = time;
325 }
326 const std::string& etag() const { return etag_; }
327 void set_etag(const std::string& tag) { etag_ = tag; }
Randy Smith (Not in Mondays) 2011/11/15 18:45:26 Under what circumstances are the setters used? Ca
ahendrickson 2011/11/16 15:41:08 We need the getters (or an equivalent function) wh
Randy Smith (Not in Mondays) 2011/11/16 18:29:27 So you're not planning to update these values when
ahendrickson 2011/11/19 20:18:03 You're right, and I'll put them back in when they
328
316 InterruptReason last_reason() const { return last_reason_; } 329 InterruptReason last_reason() const { return last_reason_; }
317 330
318 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; 331 DownloadPersistentStoreInfo GetPersistentStoreInfo() const;
319 DownloadStateInfo state_info() const { return state_info_; } 332 DownloadStateInfo state_info() const { return state_info_; }
320 333
321 TabContents* GetTabContents() const; 334 TabContents* GetTabContents() const;
322 335
323 // Returns the final target file path for the download. 336 // Returns the final target file path for the download.
324 FilePath GetTargetFilePath() const; 337 FilePath GetTargetFilePath() const;
325 338
(...skipping 24 matching lines...) Expand all
350 void MockDownloadOpenForTesting() { open_enabled_ = false; } 363 void MockDownloadOpenForTesting() { open_enabled_ = false; }
351 364
352 private: 365 private:
353 // Construction common to all constructors. |active| should be true for new 366 // Construction common to all constructors. |active| should be true for new
354 // downloads and false for downloads from the history. 367 // downloads and false for downloads from the history.
355 void Init(bool active); 368 void Init(bool active);
356 369
357 // Internal helper for maintaining consistent received and total sizes. 370 // Internal helper for maintaining consistent received and total sizes.
358 void UpdateSize(int64 size); 371 void UpdateSize(int64 size);
359 372
373 // Internal helper for keeping track of the hash as we receive data.
374 void UpdateHash(const std::string& partial_hash);
Randy Smith (Not in Mondays) 2011/11/15 18:45:26 Given that we worked out in a different comment th
ahendrickson 2011/11/16 15:41:08 Done.
375
360 // Called when the entire download operation (including renaming etc) 376 // Called when the entire download operation (including renaming etc)
361 // is completed. 377 // is completed.
362 void Completed(); 378 void Completed();
363 379
364 // Call to transition state; all state transitions should go through this. 380 // Call to transition state; all state transitions should go through this.
365 void TransitionTo(DownloadState new_state); 381 void TransitionTo(DownloadState new_state);
366 382
367 // Called when safety_state_ should be recomputed from is_dangerous_file 383 // Called when safety_state_ should be recomputed from is_dangerous_file
368 // and is_dangerous_url. 384 // and is_dangerous_url.
369 void UpdateSafetyState(); 385 void UpdateSafetyState();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 426
411 // The value of the content type header sent with the downloaded item. It 427 // The value of the content type header sent with the downloaded item. It
412 // may be different from |mime_type_|, which may be set based on heuristics 428 // may be different from |mime_type_|, which may be set based on heuristics
413 // which may look at the file extension and first few bytes of the file. 429 // which may look at the file extension and first few bytes of the file.
414 std::string original_mime_type_; 430 std::string original_mime_type_;
415 431
416 // The charset of the referring page where the download request comes from. 432 // The charset of the referring page where the download request comes from.
417 // It's used to construct a suggested filename. 433 // It's used to construct a suggested filename.
418 std::string referrer_charset_; 434 std::string referrer_charset_;
419 435
420 // Total bytes expected 436 // Total bytes expected.
421 int64 total_bytes_; 437 int64 total_bytes_;
422 438
423 // Current received bytes 439 // Current received bytes.
424 int64 received_bytes_; 440 int64 received_bytes_;
425 441
426 // Sha256 hash of the content. This might be empty either because 442 // Sha256 hash of the content. This might be empty either because
427 // the download isn't done yet or because the hash isn't needed 443 // the download hasn't started yet or because the hash isn't needed
428 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). 444 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false).
429 std::string hash_; 445 std::string hash_;
430 446
447 // Server's time stamp for the file.
448 std::string last_modified_time_;
449
450 // Server's ETAG for the file.
451 std::string etag_;
452
431 // Last reason. 453 // Last reason.
432 InterruptReason last_reason_; 454 InterruptReason last_reason_;
433 455
434 // Start time for calculating remaining time 456 // Start time for calculating remaining time.
435 base::TimeTicks start_tick_; 457 base::TimeTicks start_tick_;
436 458
437 // The current state of this download 459 // The current state of this download.
438 DownloadState state_; 460 DownloadState state_;
439 461
440 // The views of this item in the download shelf and download tab 462 // The views of this item in the download shelf and download tab.
441 ObserverList<Observer> observers_; 463 ObserverList<Observer> observers_;
442 464
443 // Time the download was started 465 // Time the download was started.
444 base::Time start_time_; 466 base::Time start_time_;
445 467
446 // Time the download completed 468 // Time the download completed.
447 base::Time end_time_; 469 base::Time end_time_;
448 470
449 // Our persistent store handle 471 // Our persistent store handle.
450 int64 db_handle_; 472 int64 db_handle_;
451 473
452 // Our owning object 474 // Our owning object.
453 DownloadManager* download_manager_; 475 DownloadManager* download_manager_;
454 476
455 // In progress downloads may be paused by the user, we note it here 477 // In progress downloads may be paused by the user, we note it here.
456 bool is_paused_; 478 bool is_paused_;
457 479
458 // A flag for indicating if the download should be opened at completion. 480 // A flag for indicating if the download should be opened at completion.
459 bool open_when_complete_; 481 bool open_when_complete_;
460 482
461 // A flag for indicating if the downloaded file is externally removed. 483 // A flag for indicating if the downloaded file is externally removed.
462 bool file_externally_removed_; 484 bool file_externally_removed_;
463 485
464 // Indicates if the download is considered potentially safe or dangerous 486 // Indicates if the download is considered potentially safe or dangerous
465 // (executable files are typically considered dangerous). 487 // (executable files are typically considered dangerous).
(...skipping 23 matching lines...) Expand all
489 // only. 511 // only.
490 bool open_enabled_; 512 bool open_enabled_;
491 513
492 // Did the delegate delay calling Complete on this download? 514 // Did the delegate delay calling Complete on this download?
493 bool delegate_delayed_complete_; 515 bool delegate_delayed_complete_;
494 516
495 DISALLOW_COPY_AND_ASSIGN(DownloadItem); 517 DISALLOW_COPY_AND_ASSIGN(DownloadItem);
496 }; 518 };
497 519
498 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ 520 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698