| 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 <stdint.h> |
| 9 |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" |
| 10 #include "content/browser/download/save_types.h" | 12 #include "content/browser/download/save_types.h" |
| 11 #include "content/public/common/referrer.h" | 13 #include "content/public/common/referrer.h" |
| 12 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 13 | 15 |
| 14 namespace content { | 16 namespace content { |
| 15 class SavePackage; | 17 class SavePackage; |
| 16 | 18 |
| 17 // One SaveItem per save file. This is the model class that stores all the | 19 // One SaveItem per save file. This is the model class that stores all the |
| 18 // state for one save file. | 20 // state for one save file. |
| 19 class SaveItem { | 21 class SaveItem { |
| 20 public: | 22 public: |
| 21 enum SaveState { | 23 enum SaveState { |
| 22 WAIT_START, | 24 WAIT_START, |
| 23 IN_PROGRESS, | 25 IN_PROGRESS, |
| 24 COMPLETE, | 26 COMPLETE, |
| 25 CANCELED | 27 CANCELED |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 SaveItem(const GURL& url, | 30 SaveItem(const GURL& url, |
| 29 const Referrer& referrer, | 31 const Referrer& referrer, |
| 30 SavePackage* package, | 32 SavePackage* package, |
| 31 SaveFileCreateInfo::SaveFileSource save_source); | 33 SaveFileCreateInfo::SaveFileSource save_source); |
| 32 | 34 |
| 33 ~SaveItem(); | 35 ~SaveItem(); |
| 34 | 36 |
| 35 void Start(); | 37 void Start(); |
| 36 | 38 |
| 37 // Received a new chunk of data. | 39 // Received a new chunk of data. |
| 38 void Update(int64 bytes_so_far); | 40 void Update(int64_t bytes_so_far); |
| 39 | 41 |
| 40 // Cancel saving item. | 42 // Cancel saving item. |
| 41 void Cancel(); | 43 void Cancel(); |
| 42 | 44 |
| 43 // Saving operation completed. | 45 // Saving operation completed. |
| 44 void Finish(int64 size, bool is_success); | 46 void Finish(int64_t size, bool is_success); |
| 45 | 47 |
| 46 // Rough percent complete, -1 means we don't know (since we didn't receive a | 48 // Rough percent complete, -1 means we don't know (since we didn't receive a |
| 47 // total size). | 49 // total size). |
| 48 int PercentComplete() const; | 50 int PercentComplete() const; |
| 49 | 51 |
| 50 // Update path for SaveItem, the actual file is renamed on the file thread. | 52 // Update path for SaveItem, the actual file is renamed on the file thread. |
| 51 void Rename(const base::FilePath& full_path); | 53 void Rename(const base::FilePath& full_path); |
| 52 | 54 |
| 53 void SetTotalBytes(int64 total_bytes); | 55 void SetTotalBytes(int64_t total_bytes); |
| 54 | 56 |
| 55 // Accessors. | 57 // Accessors. |
| 56 int id() const { return save_item_id_; } | 58 int id() const { return save_item_id_; } |
| 57 SaveState state() const { return state_; } | 59 SaveState state() const { return state_; } |
| 58 const base::FilePath& full_path() const { return full_path_; } | 60 const base::FilePath& full_path() const { return full_path_; } |
| 59 const base::FilePath& file_name() const { return file_name_; } | 61 const base::FilePath& file_name() const { return file_name_; } |
| 60 const GURL& url() const { return url_; } | 62 const GURL& url() const { return url_; } |
| 61 const Referrer& referrer() const { return referrer_; } | 63 const Referrer& referrer() const { return referrer_; } |
| 62 int64 total_bytes() const { return total_bytes_; } | 64 int64_t total_bytes() const { return total_bytes_; } |
| 63 int64 received_bytes() const { return received_bytes_; } | 65 int64_t received_bytes() const { return received_bytes_; } |
| 64 bool has_final_name() const { return has_final_name_; } | 66 bool has_final_name() const { return has_final_name_; } |
| 65 bool success() const { return is_success_; } | 67 bool success() const { return is_success_; } |
| 66 SaveFileCreateInfo::SaveFileSource save_source() const { | 68 SaveFileCreateInfo::SaveFileSource save_source() const { |
| 67 return save_source_; | 69 return save_source_; |
| 68 } | 70 } |
| 69 SavePackage* package() const { return package_; } | 71 SavePackage* package() const { return package_; } |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 // Internal helper for maintaining consistent received and total sizes. | 74 // Internal helper for maintaining consistent received and total sizes. |
| 73 void UpdateSize(int64 size); | 75 void UpdateSize(int64_t size); |
| 74 | 76 |
| 75 // Unique identifier for this SaveItem instance. | 77 // Unique identifier for this SaveItem instance. |
| 76 const int save_item_id_; | 78 const int save_item_id_; |
| 77 | 79 |
| 78 // Full path to the save item file. | 80 // Full path to the save item file. |
| 79 base::FilePath full_path_; | 81 base::FilePath full_path_; |
| 80 | 82 |
| 81 // Short display version of the file. | 83 // Short display version of the file. |
| 82 base::FilePath file_name_; | 84 base::FilePath file_name_; |
| 83 | 85 |
| 84 // The URL for this save item. | 86 // The URL for this save item. |
| 85 GURL url_; | 87 GURL url_; |
| 86 Referrer referrer_; | 88 Referrer referrer_; |
| 87 | 89 |
| 88 // Total bytes expected. | 90 // Total bytes expected. |
| 89 int64 total_bytes_; | 91 int64_t total_bytes_; |
| 90 | 92 |
| 91 // Current received bytes. | 93 // Current received bytes. |
| 92 int64 received_bytes_; | 94 int64_t received_bytes_; |
| 93 | 95 |
| 94 // The current state of this save item. | 96 // The current state of this save item. |
| 95 SaveState state_; | 97 SaveState state_; |
| 96 | 98 |
| 97 // Specifies if this name is a final or not. | 99 // Specifies if this name is a final or not. |
| 98 bool has_final_name_; | 100 bool has_final_name_; |
| 99 | 101 |
| 100 // Flag indicates whether SaveItem has error while in saving process. | 102 // Flag indicates whether SaveItem has error while in saving process. |
| 101 bool is_success_; | 103 bool is_success_; |
| 102 | 104 |
| 103 SaveFileCreateInfo::SaveFileSource save_source_; | 105 SaveFileCreateInfo::SaveFileSource save_source_; |
| 104 | 106 |
| 105 // Our owning object. | 107 // Our owning object. |
| 106 SavePackage* package_; | 108 SavePackage* package_; |
| 107 | 109 |
| 108 DISALLOW_COPY_AND_ASSIGN(SaveItem); | 110 DISALLOW_COPY_AND_ASSIGN(SaveItem); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 } // namespace content | 113 } // namespace content |
| 112 | 114 |
| 113 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ | 115 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_ |
| OLD | NEW |