| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SAVE_ITEM_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "content/browser/download/save_types.h" | 10 #include "content/browser/download/save_types.h" |
| 11 #include "content/public/common/referrer.h" | 11 #include "content/public/common/referrer.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 class SavePackage; | 15 class SavePackage; |
| 16 | 16 |
| 17 // One SaveItem per save file. This is the model class that stores all the | 17 // One SaveItem per save file. This is the model class that stores all the |
| 18 // state for one save file. | 18 // state for one save file. |
| 19 class SaveItem { | 19 class SaveItem { |
| 20 public: | 20 public: |
| 21 enum SaveState { | 21 enum SaveState { WAIT_START, IN_PROGRESS, COMPLETING, COMPLETE, CANCELED }; |
| 22 WAIT_START, | |
| 23 IN_PROGRESS, | |
| 24 COMPLETE, | |
| 25 CANCELED | |
| 26 }; | |
| 27 | 22 |
| 28 SaveItem(const GURL& url, | 23 SaveItem(const GURL& url, |
| 29 const Referrer& referrer, | |
| 30 SavePackage* package, | 24 SavePackage* package, |
| 31 SaveFileCreateInfo::SaveFileSource save_source); | 25 SaveFileCreateInfo::SaveFileSource save_source); |
| 32 | 26 |
| 33 ~SaveItem(); | 27 ~SaveItem(); |
| 34 | 28 |
| 35 void Start(); | 29 void Start(); |
| 36 | 30 |
| 37 // Received a new chunk of data. | 31 // Received a new chunk of data. |
| 38 void Update(int64 bytes_so_far); | 32 void Update(int64 bytes_so_far); |
| 39 | 33 |
| 40 // Cancel saving item. | 34 // Cancel saving item. |
| 41 void Cancel(); | 35 void Cancel(); |
| 42 | 36 |
| 43 // Saving operation completed. | 37 // Saving operation completed. |
| 44 void Finish(int64 size, bool is_success); | 38 void Finish(int64 size, bool is_success); |
| 45 | 39 |
| 46 // Rough percent complete, -1 means we don't know (since we didn't receive a | 40 // Rough percent complete, -1 means we don't know (since we didn't receive a |
| 47 // total size). | 41 // total size). |
| 48 int PercentComplete() const; | 42 int PercentComplete() const; |
| 49 | 43 |
| 50 // Update path for SaveItem, the actual file is renamed on the file thread. | 44 // Update path for SaveItem, the actual file is renamed on the file thread. |
| 51 void Rename(const base::FilePath& full_path); | 45 void Rename(const base::FilePath& full_path); |
| 52 | 46 |
| 53 void SetSaveId(int32 save_id); | 47 void SetSaveId(int32 save_id); |
| 54 | 48 |
| 55 void SetTotalBytes(int64 total_bytes); | 49 void SetTotalBytes(int64 total_bytes); |
| 56 | 50 |
| 51 void MarkAsCompleting(); |
| 52 |
| 57 // Accessors. | 53 // Accessors. |
| 58 SaveState state() const { return state_; } | 54 SaveState state() const { return state_; } |
| 59 const base::FilePath& full_path() const { return full_path_; } | 55 const base::FilePath& full_path() const { return full_path_; } |
| 60 const base::FilePath& file_name() const { return file_name_; } | 56 const base::FilePath& file_name() const { return file_name_; } |
| 61 const GURL& url() const { return url_; } | 57 const GURL& url() const { return url_; } |
| 62 const Referrer& referrer() const { return referrer_; } | 58 const Referrer& referrer() const { return referrer_; } |
| 63 int64 total_bytes() const { return total_bytes_; } | 59 int64 total_bytes() const { return total_bytes_; } |
| 64 int64 received_bytes() const { return received_bytes_; } | 60 int64 received_bytes() const { return received_bytes_; } |
| 65 int32 save_id() const { return save_id_; } | 61 int32 save_id() const { return save_id_; } |
| 66 bool has_final_name() const { return has_final_name_; } | 62 bool has_final_name() const { return has_final_name_; } |
| 67 bool success() const { return is_success_; } | 63 bool success() const { return is_success_; } |
| 68 SaveFileCreateInfo::SaveFileSource save_source() const { | 64 SaveFileCreateInfo::SaveFileSource save_source() const { |
| 69 return save_source_; | 65 return save_source_; |
| 70 } | 66 } |
| 71 SavePackage* package() const { return package_; } | 67 SavePackage* package() const { return package_; } |
| 72 | 68 |
| 69 // Setters. |
| 70 void set_referrer(const Referrer& referrer) { referrer_ = referrer; } |
| 71 |
| 73 private: | 72 private: |
| 74 // Internal helper for maintaining consistent received and total sizes. | 73 // Internal helper for maintaining consistent received and total sizes. |
| 75 void UpdateSize(int64 size); | 74 void UpdateSize(int64 size); |
| 76 | 75 |
| 77 // Request ID assigned by the ResourceDispatcherHost. | 76 // Request ID assigned by the ResourceDispatcherHost. |
| 78 int32 save_id_; | 77 int32 save_id_; |
| 79 | 78 |
| 80 // Full path to the save item file. | 79 // Full path to the save item file. |
| 81 base::FilePath full_path_; | 80 base::FilePath full_path_; |
| 82 | 81 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 106 | 105 |
| 107 // Our owning object. | 106 // Our owning object. |
| 108 SavePackage* package_; | 107 SavePackage* package_; |
| 109 | 108 |
| 110 DISALLOW_COPY_AND_ASSIGN(SaveItem); | 109 DISALLOW_COPY_AND_ASSIGN(SaveItem); |
| 111 }; | 110 }; |
| 112 | 111 |
| 113 } // namespace content | 112 } // namespace content |
| 114 | 113 |
| 115 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ | 114 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ |
| OLD | NEW |