| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 virtual void OnDownloadFileCompleted(DownloadItem* download) = 0; | 58 virtual void OnDownloadFileCompleted(DownloadItem* download) = 0; |
| 59 | 59 |
| 60 // Called when a downloaded file has been opened. | 60 // Called when a downloaded file has been opened. |
| 61 virtual void OnDownloadOpened(DownloadItem* download) = 0; | 61 virtual void OnDownloadOpened(DownloadItem* download) = 0; |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 virtual ~Observer() {} | 64 virtual ~Observer() {} |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // Constructing from persistent store: | 67 // Constructing from persistent store: |
| 68 explicit DownloadItem(const DownloadCreateInfo& info); | 68 DownloadItem(DownloadManager* download_manager, |
| 69 const DownloadCreateInfo& info); |
| 69 | 70 |
| 70 // Constructing from user action: | 71 // Constructing for a regular download: |
| 71 DownloadItem(int32 download_id, | 72 DownloadItem(DownloadManager* download_manager, |
| 73 const DownloadCreateInfo& info, |
| 74 bool is_otr); |
| 75 |
| 76 // Constructing for the "Save Page As..." feature: |
| 77 DownloadItem(DownloadManager* download_manager, |
| 72 const FilePath& path, | 78 const FilePath& path, |
| 73 int path_uniquifier, | |
| 74 const GURL& url, | 79 const GURL& url, |
| 75 const GURL& referrer_url, | 80 bool is_otr); |
| 76 const std::string& mime_type, | |
| 77 const std::string& original_mime_type, | |
| 78 const FilePath& original_name, | |
| 79 const base::Time start_time, | |
| 80 int64 download_size, | |
| 81 int render_process_id, | |
| 82 int request_id, | |
| 83 bool is_dangerous, | |
| 84 bool save_as, | |
| 85 bool is_otr, | |
| 86 bool is_extension_install, | |
| 87 bool is_temporary); | |
| 88 | 81 |
| 89 ~DownloadItem(); | 82 ~DownloadItem(); |
| 90 | 83 |
| 91 void Init(bool start_timer); | |
| 92 | |
| 93 // Public API | |
| 94 | |
| 95 void AddObserver(Observer* observer); | 84 void AddObserver(Observer* observer); |
| 96 void RemoveObserver(Observer* observer); | 85 void RemoveObserver(Observer* observer); |
| 97 | 86 |
| 98 // Notifies our observers periodically. | 87 // Notifies our observers periodically. |
| 99 void UpdateObservers(); | 88 void UpdateObservers(); |
| 100 | 89 |
| 101 // Notifies our observers the downloaded file has been completed. | 90 // Notifies our observers the downloaded file has been completed. |
| 102 void NotifyObserversDownloadFileCompleted(); | 91 void NotifyObserversDownloadFileCompleted(); |
| 103 | 92 |
| 104 // Notifies our observers the downloaded file has been opened. | 93 // Whether it is OK to open this download. |
| 105 void NotifyObserversDownloadOpened(); | 94 bool CanOpenDownload(); |
| 95 |
| 96 // Tests if a file type should be opened automatically. |
| 97 bool ShouldOpenFileBasedOnExtension(); |
| 98 |
| 99 // Registers this file extension for automatic opening upon download |
| 100 // completion if 'open' is true, or prevents the extension from automatic |
| 101 // opening if 'open' is false. |
| 102 void OpenFilesBasedOnExtension(bool open); |
| 103 |
| 104 // Open the file associated with this download (wait for the download to |
| 105 // complete if it is in progress). |
| 106 void OpenDownload(); |
| 107 |
| 108 // Show the download via the OS shell. |
| 109 void ShowDownloadInShell(); |
| 110 |
| 111 // Called when the user has validated the download of a dangerous file. |
| 112 void DangerousDownloadValidated(); |
| 106 | 113 |
| 107 // Received a new chunk of data | 114 // Received a new chunk of data |
| 108 void Update(int64 bytes_so_far); | 115 void Update(int64 bytes_so_far); |
| 109 | 116 |
| 110 // Cancel the download operation. We need to distinguish between cancels at | 117 // Cancel the download operation. We need to distinguish between cancels at |
| 111 // exit (DownloadManager destructor) from user interface initiated cancels | 118 // exit (DownloadManager destructor) from user interface initiated cancels |
| 112 // because at exit, the history system may not exist, and any updates to it | 119 // because at exit, the history system may not exist, and any updates to it |
| 113 // require AddRef'ing the DownloadManager in the destructor which results in | 120 // require AddRef'ing the DownloadManager in the destructor which results in |
| 114 // a DCHECK failure. Set 'update_history' to false when canceling from at | 121 // a DCHECK failure. Set 'update_history' to false when canceling from at |
| 115 // exit to prevent this crash. This may result in a difference between the | 122 // exit to prevent this crash. This may result in a difference between the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 GURL referrer_url() const { return referrer_url_; } | 163 GURL referrer_url() const { return referrer_url_; } |
| 157 std::string mime_type() const { return mime_type_; } | 164 std::string mime_type() const { return mime_type_; } |
| 158 std::string original_mime_type() const { return original_mime_type_; } | 165 std::string original_mime_type() const { return original_mime_type_; } |
| 159 int64 total_bytes() const { return total_bytes_; } | 166 int64 total_bytes() const { return total_bytes_; } |
| 160 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } | 167 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } |
| 161 int64 received_bytes() const { return received_bytes_; } | 168 int64 received_bytes() const { return received_bytes_; } |
| 162 int32 id() const { return id_; } | 169 int32 id() const { return id_; } |
| 163 base::Time start_time() const { return start_time_; } | 170 base::Time start_time() const { return start_time_; } |
| 164 void set_db_handle(int64 handle) { db_handle_ = handle; } | 171 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 165 int64 db_handle() const { return db_handle_; } | 172 int64 db_handle() const { return db_handle_; } |
| 166 DownloadManager* manager() const { return manager_; } | |
| 167 void set_manager(DownloadManager* manager) { manager_ = manager; } | |
| 168 bool is_paused() const { return is_paused_; } | 173 bool is_paused() const { return is_paused_; } |
| 169 void set_is_paused(bool pause) { is_paused_ = pause; } | 174 void set_is_paused(bool pause) { is_paused_ = pause; } |
| 170 bool open_when_complete() const { return open_when_complete_; } | 175 bool open_when_complete() const { return open_when_complete_; } |
| 171 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 176 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 172 int render_process_id() const { return render_process_id_; } | 177 int render_process_id() const { return render_process_id_; } |
| 173 int request_id() const { return request_id_; } | 178 int request_id() const { return request_id_; } |
| 174 SafetyState safety_state() const { return safety_state_; } | 179 SafetyState safety_state() const { return safety_state_; } |
| 175 void set_safety_state(SafetyState safety_state) { | 180 void set_safety_state(SafetyState safety_state) { |
| 176 safety_state_ = safety_state; | 181 safety_state_ = safety_state; |
| 177 } | 182 } |
| 178 bool auto_opened() { return auto_opened_; } | 183 bool auto_opened() { return auto_opened_; } |
| 179 void set_auto_opened(bool auto_opened) { auto_opened_ = auto_opened; } | 184 void set_auto_opened(bool auto_opened) { auto_opened_ = auto_opened; } |
| 180 FilePath original_name() const { return original_name_; } | 185 FilePath original_name() const { return original_name_; } |
| 181 bool save_as() const { return save_as_; } | 186 bool save_as() const { return save_as_; } |
| 182 bool is_otr() const { return is_otr_; } | 187 bool is_otr() const { return is_otr_; } |
| 183 bool is_extension_install() const { return is_extension_install_; } | 188 bool is_extension_install() const { return is_extension_install_; } |
| 184 bool name_finalized() const { return name_finalized_; } | 189 bool name_finalized() const { return name_finalized_; } |
| 185 bool is_temporary() const { return is_temporary_; } | 190 bool is_temporary() const { return is_temporary_; } |
| 186 bool need_final_rename() const { return need_final_rename_; } | 191 bool need_final_rename() const { return need_final_rename_; } |
| 187 void set_need_final_rename(bool need_final_rename) { | 192 void set_need_final_rename(bool need_final_rename) { |
| 188 need_final_rename_ = need_final_rename; | 193 need_final_rename_ = need_final_rename; |
| 189 } | 194 } |
| 190 | 195 |
| 191 // Returns the file-name that should be reported to the user, which is | 196 // Returns the file-name that should be reported to the user, which is |
| 192 // file_name_ for safe downloads and original_name_ for dangerous ones with | 197 // file_name_ for safe downloads and original_name_ for dangerous ones with |
| 193 // the uniquifier number. | 198 // the uniquifier number. |
| 194 FilePath GetFileName() const; | 199 FilePath GetFileName() const; |
| 195 | 200 |
| 196 private: | 201 private: |
| 202 void Init(bool start_timer); |
| 203 |
| 197 // Internal helper for maintaining consistent received and total sizes. | 204 // Internal helper for maintaining consistent received and total sizes. |
| 198 void UpdateSize(int64 size); | 205 void UpdateSize(int64 size); |
| 199 | 206 |
| 200 // Start/stop sending periodic updates to our observers | 207 // Start/stop sending periodic updates to our observers |
| 201 void StartProgressTimer(); | 208 void StartProgressTimer(); |
| 202 void StopProgressTimer(); | 209 void StopProgressTimer(); |
| 203 | 210 |
| 204 // Request ID assigned by the ResourceDispatcherHost. | 211 // Request ID assigned by the ResourceDispatcherHost. |
| 205 int32 id_; | 212 int32 id_; |
| 206 | 213 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // Time the download was started | 252 // Time the download was started |
| 246 base::Time start_time_; | 253 base::Time start_time_; |
| 247 | 254 |
| 248 // Our persistent store handle | 255 // Our persistent store handle |
| 249 int64 db_handle_; | 256 int64 db_handle_; |
| 250 | 257 |
| 251 // Timer for regularly updating our observers | 258 // Timer for regularly updating our observers |
| 252 base::RepeatingTimer<DownloadItem> update_timer_; | 259 base::RepeatingTimer<DownloadItem> update_timer_; |
| 253 | 260 |
| 254 // Our owning object | 261 // Our owning object |
| 255 DownloadManager* manager_; | 262 DownloadManager* download_manager_; |
| 256 | 263 |
| 257 // In progress downloads may be paused by the user, we note it here | 264 // In progress downloads may be paused by the user, we note it here |
| 258 bool is_paused_; | 265 bool is_paused_; |
| 259 | 266 |
| 260 // A flag for indicating if the download should be opened at completion. | 267 // A flag for indicating if the download should be opened at completion. |
| 261 bool open_when_complete_; | 268 bool open_when_complete_; |
| 262 | 269 |
| 263 // Whether the download is considered potentially safe or dangerous | 270 // Whether the download is considered potentially safe or dangerous |
| 264 // (executable files are typically considered dangerous). | 271 // (executable files are typically considered dangerous). |
| 265 SafetyState safety_state_; | 272 SafetyState safety_state_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 292 // True if the item was downloaded temporarily. | 299 // True if the item was downloaded temporarily. |
| 293 bool is_temporary_; | 300 bool is_temporary_; |
| 294 | 301 |
| 295 // True if the file needs final rename. | 302 // True if the file needs final rename. |
| 296 bool need_final_rename_; | 303 bool need_final_rename_; |
| 297 | 304 |
| 298 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 305 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 299 }; | 306 }; |
| 300 | 307 |
| 301 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 308 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |