| 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_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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 int64 bytes_per_sec, | 203 int64 bytes_per_sec, |
| 204 const std::string& hash_state); | 204 const std::string& hash_state); |
| 205 | 205 |
| 206 virtual void OnAllDataSaved(const std::string& final_hash); | 206 virtual void OnAllDataSaved(const std::string& final_hash); |
| 207 | 207 |
| 208 // Called by SavePackage to display progress when the DownloadItem | 208 // Called by SavePackage to display progress when the DownloadItem |
| 209 // should be considered complete. | 209 // should be considered complete. |
| 210 virtual void MarkAsComplete(); | 210 virtual void MarkAsComplete(); |
| 211 | 211 |
| 212 private: | 212 private: |
| 213 // Fine grained states of a download. | 213 // Fine grained states of a download. Note that active downloads are created |
| 214 // in IN_PROGRESS_INTERNAL state. However, downloads creates via history can |
| 215 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and |
| 216 // INTERRUPTED_INTERNAL. |
| 217 |
| 214 enum DownloadInternalState { | 218 enum DownloadInternalState { |
| 215 // Unless otherwise specified, state transitions are linear forward | 219 // Includes both before and after file name determination, and paused |
| 216 // in this list. | 220 // downloads. |
| 217 | |
| 218 // Includes both before and after file name determination. | |
| 219 // TODO(rdsmith): Put in state variable for file name determination. | 221 // TODO(rdsmith): Put in state variable for file name determination. |
| 222 // Transitions from: |
| 223 // <Initial creation> Active downloads are created in this state. |
| 224 // RESUMING_INTERNAL |
| 225 // Transitions to: |
| 226 // COMPLETING_INTERNAL On final rename completion. |
| 227 // CANCELLED_INTERNAL On cancel. |
| 228 // INTERRUPTED_INTERNAL On interrupt. |
| 229 // COMPLETE_INTERNAL On SavePackage download completion. |
| 220 IN_PROGRESS_INTERNAL, | 230 IN_PROGRESS_INTERNAL, |
| 221 | 231 |
| 222 // Between commit point (dispatch of download file release) and completed. | 232 // Between commit point (dispatch of download file release) and completed. |
| 223 // Embedder may be opening the file in this state. Note that the | 233 // Embedder may be opening the file in this state. |
| 224 // DownloadItem may be deleted (by shutdown) or interrupted (e.g. due to a | 234 // Transitions from: |
| 225 // failure during AnnotateWithSourceInformation()) in this state. | 235 // IN_PROGRESS_INTERNAL |
| 236 // Transitions to: |
| 237 // COMPLETE_INTERNAL On successful completion. |
| 226 COMPLETING_INTERNAL, | 238 COMPLETING_INTERNAL, |
| 227 | 239 |
| 228 // After embedder has had a chance to auto-open. User may now open | 240 // After embedder has had a chance to auto-open. User may now open |
| 229 // or auto-open based on extension. | 241 // or auto-open based on extension. |
| 242 // Transitions from: |
| 243 // COMPLETING_INTERNAL |
| 244 // IN_PROGRESS_INTERNAL SavePackage only. |
| 245 // <Initial creation> Completed persisted downloads. |
| 246 // Transitions to: |
| 247 // <none> Terminal state. |
| 230 COMPLETE_INTERNAL, | 248 COMPLETE_INTERNAL, |
| 231 | 249 |
| 232 // User has cancelled the download. | 250 // User has cancelled the download. |
| 233 // Only incoming transition IN_PROGRESS-> | 251 // Transitions from: |
| 252 // IN_PROGRESS_INTERNAL |
| 253 // INTERRUPTED_INTERNAL |
| 254 // RESUMING_INTERNAL |
| 255 // <Initial creation> Canceleld persisted downloads. |
| 256 // Transitions to: |
| 257 // <none> Terminal state. |
| 234 CANCELLED_INTERNAL, | 258 CANCELLED_INTERNAL, |
| 235 | 259 |
| 236 // An error has interrupted the download. | 260 // An error has interrupted the download. |
| 237 // Only incoming transition IN_PROGRESS-> | 261 // Transitions from: |
| 262 // IN_PROGRESS_INTERNAL |
| 263 // RESUMING_INTERNAL |
| 264 // <Initial creation> Interrupted persisted downloads. |
| 265 // Transitions to: |
| 266 // RESUMING_INTERNAL On resumption. |
| 238 INTERRUPTED_INTERNAL, | 267 INTERRUPTED_INTERNAL, |
| 239 | 268 |
| 269 // A request to resume this interrupted download is in progress. |
| 270 // Transitions from: |
| 271 // INTERRUPTED_INTERNAL |
| 272 // Transitions to: |
| 273 // IN_PROGRESS_INTERNAL Once a server response is received from a |
| 274 // resumption. |
| 275 // INTERRUPTED_INTERNAL If the resumption request fails. |
| 276 // CANCELLED_INTERNAL On cancel. |
| 277 RESUMING_INTERNAL, |
| 278 |
| 240 MAX_DOWNLOAD_INTERNAL_STATE, | 279 MAX_DOWNLOAD_INTERNAL_STATE, |
| 241 }; | 280 }; |
| 242 | 281 |
| 243 // DownloadDestinationObserver | 282 // DownloadDestinationObserver |
| 244 virtual void DestinationUpdate(int64 bytes_so_far, | 283 virtual void DestinationUpdate(int64 bytes_so_far, |
| 245 int64 bytes_per_sec, | 284 int64 bytes_per_sec, |
| 246 const std::string& hash_state) OVERRIDE; | 285 const std::string& hash_state) OVERRIDE; |
| 247 virtual void DestinationError(DownloadInterruptReason reason) OVERRIDE; | 286 virtual void DestinationError(DownloadInterruptReason reason) OVERRIDE; |
| 248 virtual void DestinationCompleted(const std::string& final_hash) OVERRIDE; | 287 virtual void DestinationCompleted(const std::string& final_hash) OVERRIDE; |
| 249 | 288 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 const base::FilePath& full_path); | 329 const base::FilePath& full_path); |
| 291 | 330 |
| 292 // Called if the embedder took over opening a download, to indicate that | 331 // Called if the embedder took over opening a download, to indicate that |
| 293 // the download has been opened. | 332 // the download has been opened. |
| 294 void DelayedDownloadOpened(bool auto_opened); | 333 void DelayedDownloadOpened(bool auto_opened); |
| 295 | 334 |
| 296 // Called when the entire download operation (including renaming etc) | 335 // Called when the entire download operation (including renaming etc) |
| 297 // is completed. | 336 // is completed. |
| 298 void Completed(); | 337 void Completed(); |
| 299 | 338 |
| 339 // Callback invoked when the URLRequest for a download resumption has started. |
| 340 void OnResumeRequestStarted(DownloadItem* item, net::Error error); |
| 341 |
| 300 // Helper routines ----------------------------------------------------------- | 342 // Helper routines ----------------------------------------------------------- |
| 301 | 343 |
| 302 // Indicate that an error has occurred on the download. | 344 // Indicate that an error has occurred on the download. |
| 303 void Interrupt(DownloadInterruptReason reason); | 345 void Interrupt(DownloadInterruptReason reason); |
| 304 | 346 |
| 305 // Destroy the DownloadFile object. If |destroy_file| is true, the file is | 347 // Destroy the DownloadFile object. If |destroy_file| is true, the file is |
| 306 // destroyed with it. Otherwise, DownloadFile::Detach() is called before | 348 // destroyed with it. Otherwise, DownloadFile::Detach() is called before |
| 307 // object destruction to prevent file destruction. Destroying the file also | 349 // object destruction to prevent file destruction. Destroying the file also |
| 308 // resets |current_path_|. | 350 // resets |current_path_|. |
| 309 void ReleaseDownloadFile(bool destroy_file); | 351 void ReleaseDownloadFile(bool destroy_file); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 const net::BoundNetLog bound_net_log_; | 537 const net::BoundNetLog bound_net_log_; |
| 496 | 538 |
| 497 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 539 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 498 | 540 |
| 499 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 541 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 500 }; | 542 }; |
| 501 | 543 |
| 502 } // namespace content | 544 } // namespace content |
| 503 | 545 |
| 504 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 546 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |