Chromium Code Reviews| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 211 |
| 212 // DownloadDestinationObserver | 212 // DownloadDestinationObserver |
| 213 void DestinationUpdate(int64_t bytes_so_far, | 213 void DestinationUpdate(int64_t bytes_so_far, |
| 214 int64_t bytes_per_sec, | 214 int64_t bytes_per_sec, |
| 215 const std::string& hash_state) override; | 215 const std::string& hash_state) override; |
| 216 void DestinationError(DownloadInterruptReason reason) override; | 216 void DestinationError(DownloadInterruptReason reason) override; |
| 217 void DestinationCompleted(const std::string& final_hash) override; | 217 void DestinationCompleted(const std::string& final_hash) override; |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 // Fine grained states of a download. Note that active downloads are created | 220 // Fine grained states of a download. Note that active downloads are created |
| 221 // in IN_PROGRESS_INTERNAL state. However, downloads creates via history can | 221 // in INITIAL_INTERNAL state. However, downloads creates via history can be |
| 222 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and | 222 // created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and INTERRUPTED_INTERNAL. |
| 223 // INTERRUPTED_INTERNAL. | 223 // |
| 224 // On debug builds, state transitions can be verified via | |
| 225 // IsValidStateTransition(). | |
| 224 | 226 |
| 225 enum DownloadInternalState { | 227 enum DownloadInternalState { |
| 226 // Includes both before and after file name determination, and paused | 228 // Initial state. Regular downloads are created in this state until the |
| 227 // downloads. | 229 // Start() call is received. |
| 228 // TODO(rdsmith): Put in state variable for file name determination. | 230 // |
| 229 // Transitions from: | 231 // Transitions from: |
| 230 // <Initial creation> Active downloads are created in this state. | 232 // <Initial creation>: Active downloads are created in this state. |
| 231 // RESUMING_INTERNAL | 233 // |
| 232 // Transitions to: | 234 // Transitions to: |
| 233 // COMPLETING_INTERNAL On final rename completion. | 235 // TARGET_PENDING_INTERNAL: After a successful Start() call. |
| 234 // CANCELLED_INTERNAL On cancel. | 236 // INTERRUPTED_INTERNAL: Afater a failed Start() call. |
| 235 // INTERRUPTED_INTERNAL On interrupt. | 237 INITIAL_INTERNAL, |
| 236 // COMPLETE_INTERNAL On SavePackage download completion. | 238 |
| 239 // Embedder is in the process of determining the target of the download. | |
| 240 // Since the embedder is sensitive to state transitions during this time, | |
| 241 // any DestinationError/DestinationCompleted events are deferred until | |
| 242 // TARGET_RESOLVED_INTERNAL. | |
| 243 // | |
| 244 // Transitions to: | |
| 245 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback. | |
| 246 // CANCELLED_INTERNAL: Cancelled. | |
| 247 TARGET_PENDING_INTERNAL, | |
| 248 | |
| 249 // Embedder has completed target determination. It is now safe to resolve | |
| 250 // the download target as well as process deferred DestinationError events. | |
| 251 // This state is differs from TARGET_PENDING_INTERNAL due to it being | |
| 252 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from | |
| 253 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having | |
| 254 // a valid target. | |
| 255 // | |
| 256 // Transitions to: | |
| 257 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming | |
| 258 // data stream can now be written to the target. | |
| 259 // INTERRUPTED_INTERNAL: Either the target determination or one of the | |
| 260 // deferred signals indicated that the download | |
| 261 // should be interrupted. | |
| 262 // CANCELLED_INTERNAL: User cancelled the download or there was a | |
| 263 // deferred Cancel() call. | |
| 264 TARGET_RESOLVED_INTERNAL, | |
| 265 | |
| 266 // Download target is known and the data can be transferred from our source | |
| 267 // to our sink. | |
| 268 // | |
| 269 // Transitions from: | |
|
Randy Smith (Not in Mondays)
2016/02/11 17:19:18
I'm not sure how you're using this comment slot.
asanka
2016/02/11 21:12:05
Yeah. That was confusing. I removed the "Transitio
| |
| 270 // <Initial creation>: Only for SavePackage downloads. Curses! | |
|
Randy Smith (Not in Mondays)
2016/02/11 17:19:18
I'm not clear whether or not the transitions descr
asanka
2016/02/11 21:12:05
I clarified the SavePackage transitions in the com
Randy Smith (Not in Mondays)
2016/02/12 17:37:02
I was musing about suggesting commenting the meani
asanka
2016/02/12 20:21:24
Acknowledged.
| |
| 271 // | |
| 272 // Transitions to: | |
| 273 // COMPLETING_INTERNAL: On final rename completion. | |
| 274 // CANCELLED_INTERNAL: On cancel. | |
| 275 // INTERRUPTED_INTERNAL: On interrupt. | |
| 237 IN_PROGRESS_INTERNAL, | 276 IN_PROGRESS_INTERNAL, |
| 238 | 277 |
| 239 // Between commit point (dispatch of download file release) and completed. | 278 // Between commit point (dispatch of download file release) and completed. |
| 240 // Embedder may be opening the file in this state. | 279 // Embedder may be opening the file in this state. |
| 241 // Transitions from: | 280 // |
| 242 // IN_PROGRESS_INTERNAL | |
| 243 // Transitions to: | 281 // Transitions to: |
| 244 // COMPLETE_INTERNAL On successful completion. | 282 // COMPLETE_INTERNAL: On successful completion. |
| 245 COMPLETING_INTERNAL, | 283 COMPLETING_INTERNAL, |
| 246 | 284 |
| 247 // After embedder has had a chance to auto-open. User may now open | 285 // After embedder has had a chance to auto-open. User may now open |
| 248 // or auto-open based on extension. | 286 // or auto-open based on extension. |
| 287 // | |
| 249 // Transitions from: | 288 // Transitions from: |
| 250 // COMPLETING_INTERNAL | 289 // <Initial creation> Completed persisted downloads. |
| 251 // IN_PROGRESS_INTERNAL SavePackage only. | 290 // |
| 252 // <Initial creation> Completed persisted downloads. | |
| 253 // Transitions to: | 291 // Transitions to: |
| 254 // <none> Terminal state. | 292 // <none> Terminal state. |
| 255 COMPLETE_INTERNAL, | 293 COMPLETE_INTERNAL, |
| 256 | 294 |
| 295 // An error has interrupted the download. | |
| 296 // | |
| 297 // Transitions from: | |
| 298 // <Initial creation> Interrupted persisted downloads. | |
| 299 // | |
| 300 // Transitions to: | |
| 301 // RESUMING_INTERNAL: On resumption. | |
| 302 INTERRUPTED_INTERNAL, | |
| 303 | |
| 304 // A request to resume this interrupted download is in progress. | |
| 305 // | |
| 306 // Transitions to: | |
| 307 // TARGET_PENDING_INTERNAL: Once a server response is received from a | |
| 308 // resumption. | |
| 309 // CANCELLED_INTERNAL: On cancel. | |
| 310 RESUMING_INTERNAL, | |
| 311 | |
| 257 // User has cancelled the download. | 312 // User has cancelled the download. |
| 313 // TODO(asanka): Merge interrupted and cancelled states. | |
| 314 // | |
| 258 // Transitions from: | 315 // Transitions from: |
| 259 // IN_PROGRESS_INTERNAL | 316 // <Initial creation> Cancelled persisted downloads. |
| 260 // INTERRUPTED_INTERNAL | 317 // |
| 261 // RESUMING_INTERNAL | |
| 262 // <Initial creation> Canceleld persisted downloads. | |
| 263 // Transitions to: | 318 // Transitions to: |
| 264 // <none> Terminal state. | 319 // <none> Terminal state. |
| 265 CANCELLED_INTERNAL, | 320 CANCELLED_INTERNAL, |
| 266 | 321 |
| 267 // An error has interrupted the download. | |
| 268 // Transitions from: | |
| 269 // IN_PROGRESS_INTERNAL | |
| 270 // RESUMING_INTERNAL | |
| 271 // <Initial creation> Interrupted persisted downloads. | |
| 272 // Transitions to: | |
| 273 // RESUMING_INTERNAL On resumption. | |
| 274 INTERRUPTED_INTERNAL, | |
| 275 | |
| 276 // A request to resume this interrupted download is in progress. | |
| 277 // Transitions from: | |
| 278 // INTERRUPTED_INTERNAL | |
| 279 // Transitions to: | |
| 280 // IN_PROGRESS_INTERNAL Once a server response is received from a | |
| 281 // resumption. | |
| 282 // INTERRUPTED_INTERNAL If the resumption request fails. | |
| 283 // CANCELLED_INTERNAL On cancel. | |
| 284 RESUMING_INTERNAL, | |
| 285 | |
| 286 MAX_DOWNLOAD_INTERNAL_STATE, | 322 MAX_DOWNLOAD_INTERNAL_STATE, |
| 287 }; | 323 }; |
| 288 | 324 |
| 289 // Used with TransitionTo() to indicate whether or not to call | 325 // Used with TransitionTo() to indicate whether or not to call |
| 290 // UpdateObservers() after the state transition. | 326 // UpdateObservers() after the state transition. |
| 291 enum ShouldUpdateObservers { | 327 enum ShouldUpdateObservers { |
| 292 UPDATE_OBSERVERS, | 328 UPDATE_OBSERVERS, |
| 293 DONT_UPDATE_OBSERVERS | 329 DONT_UPDATE_OBSERVERS |
| 294 }; | 330 }; |
| 295 | 331 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 void ResumeInterruptedDownload(); | 415 void ResumeInterruptedDownload(); |
| 380 | 416 |
| 381 static DownloadState InternalToExternalState( | 417 static DownloadState InternalToExternalState( |
| 382 DownloadInternalState internal_state); | 418 DownloadInternalState internal_state); |
| 383 static DownloadInternalState ExternalToInternalState( | 419 static DownloadInternalState ExternalToInternalState( |
| 384 DownloadState external_state); | 420 DownloadState external_state); |
| 385 | 421 |
| 386 // Debugging routines -------------------------------------------------------- | 422 // Debugging routines -------------------------------------------------------- |
| 387 static const char* DebugDownloadStateString(DownloadInternalState state); | 423 static const char* DebugDownloadStateString(DownloadInternalState state); |
| 388 static const char* DebugResumeModeString(ResumeMode mode); | 424 static const char* DebugResumeModeString(ResumeMode mode); |
| 425 static bool IsValidSavePackageStateTransition(DownloadInternalState from, | |
| 426 DownloadInternalState to); | |
| 427 static bool IsValidStateTransition(DownloadInternalState from, | |
| 428 DownloadInternalState to); | |
| 389 | 429 |
| 390 // Will be false for save package downloads retrieved from the history. | 430 // Will be false for save package downloads retrieved from the history. |
| 391 // TODO(rdsmith): Replace with a generalized enum for "download source". | 431 // TODO(rdsmith): Replace with a generalized enum for "download source". |
| 392 const bool is_save_package_download_; | 432 const bool is_save_package_download_; |
| 393 | 433 |
| 394 // The handle to the request information. Used for operations outside the | 434 // The handle to the request information. Used for operations outside the |
| 395 // download system. | 435 // download system. |
| 396 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | 436 scoped_ptr<DownloadRequestHandleInterface> request_handle_; |
| 397 | 437 |
| 398 uint32_t download_id_; | 438 uint32_t download_id_; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 const net::BoundNetLog bound_net_log_; | 593 const net::BoundNetLog bound_net_log_; |
| 554 | 594 |
| 555 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 595 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 556 | 596 |
| 557 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 597 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 558 }; | 598 }; |
| 559 | 599 |
| 560 } // namespace content | 600 } // namespace content |
| 561 | 601 |
| 562 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 602 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |