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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 std::string DebugString(bool verbose) const override; | 160 std::string DebugString(bool verbose) const override; |
| 161 | 161 |
| 162 // All remaining public interfaces virtual to allow for DownloadItemImpl | 162 // All remaining public interfaces virtual to allow for DownloadItemImpl |
| 163 // mocks. | 163 // mocks. |
| 164 | 164 |
| 165 // Determines the resume mode for an interrupted download. Requires | 165 // Determines the resume mode for an interrupted download. Requires |
| 166 // last_reason_ to be set, but doesn't require the download to be in | 166 // last_reason_ to be set, but doesn't require the download to be in |
| 167 // INTERRUPTED state. | 167 // INTERRUPTED state. |
| 168 virtual ResumeMode GetResumeMode() const; | 168 virtual ResumeMode GetResumeMode() const; |
| 169 | 169 |
| 170 // Notify the download item that new origin information is available due to a | |
| 171 // resumption request receiving a response. | |
| 172 virtual void MergeOriginInfoOnResume( | |
| 173 const DownloadCreateInfo& new_create_info); | |
| 174 | |
| 175 // State transition operations on regular downloads -------------------------- | 170 // State transition operations on regular downloads -------------------------- |
| 176 | 171 |
| 177 // Start the download. | 172 // Start the download. |
| 178 // |download_file| is the associated file on the storage medium. | 173 // |download_file| is the associated file on the storage medium. |
| 179 // |req_handle| is the new request handle associated with the download. | 174 // |req_handle| is the new request handle associated with the download. |
| 175 // |new_create_info| is a DownloadCreateInfo containing the new response | |
| 176 // parameters. It may be different from the DownloadCreateInfo used to create | |
| 177 // the DownloadItem if Start() is being called in response for a download | |
| 178 // resumption request. | |
| 180 virtual void Start(scoped_ptr<DownloadFile> download_file, | 179 virtual void Start(scoped_ptr<DownloadFile> download_file, |
| 181 scoped_ptr<DownloadRequestHandleInterface> req_handle); | 180 scoped_ptr<DownloadRequestHandleInterface> req_handle, |
| 181 const DownloadCreateInfo& new_create_info); | |
| 182 | 182 |
| 183 // Needed because of intertwining with DownloadManagerImpl ------------------- | 183 // Needed because of intertwining with DownloadManagerImpl ------------------- |
| 184 | 184 |
| 185 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, | 185 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, |
| 186 // removing these from the public interface. | 186 // removing these from the public interface. |
| 187 | 187 |
| 188 // Notify observers that this item is being removed by the user. | 188 // Notify observers that this item is being removed by the user. |
| 189 virtual void NotifyRemoved(); | 189 virtual void NotifyRemoved(); |
| 190 | 190 |
| 191 virtual void OnDownloadedFileRemoved(); | 191 virtual void OnDownloadedFileRemoved(); |
| (...skipping 19 matching lines...) Expand all 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 IN_PROGRESS_INTERNAL state. Failed downloads are created in |
| 222 // INTERRUPTED_INTERNAL state. However, downloads creates via history can | |
| 222 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and | 223 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and |
| 223 // INTERRUPTED_INTERNAL. | 224 // INTERRUPTED_INTERNAL. |
| 224 | 225 |
| 225 enum DownloadInternalState { | 226 enum DownloadInternalState { |
| 226 // Includes both before and after file name determination, and paused | 227 // Includes both before and after file name determination, and paused |
| 227 // downloads. | 228 // downloads. |
| 228 // TODO(rdsmith): Put in state variable for file name determination. | 229 // TODO(rdsmith): Put in state variable for file name determination. |
| 229 // Transitions from: | 230 // Transitions from: |
| 230 // <Initial creation> Active downloads are created in this state. | 231 // <Initial creation> Active downloads are created in this state. |
| 231 // RESUMING_INTERNAL | 232 // RESUMING_INTERNAL |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 262 // <Initial creation> Canceleld persisted downloads. | 263 // <Initial creation> Canceleld persisted downloads. |
| 263 // Transitions to: | 264 // Transitions to: |
| 264 // <none> Terminal state. | 265 // <none> Terminal state. |
| 265 CANCELLED_INTERNAL, | 266 CANCELLED_INTERNAL, |
| 266 | 267 |
| 267 // An error has interrupted the download. | 268 // An error has interrupted the download. |
| 268 // Transitions from: | 269 // Transitions from: |
| 269 // IN_PROGRESS_INTERNAL | 270 // IN_PROGRESS_INTERNAL |
| 270 // RESUMING_INTERNAL | 271 // RESUMING_INTERNAL |
| 271 // <Initial creation> Interrupted persisted downloads. | 272 // <Initial creation> Interrupted persisted downloads. |
| 273 // <Initial creation> Failed new downloads. | |
| 272 // Transitions to: | 274 // Transitions to: |
| 273 // RESUMING_INTERNAL On resumption. | 275 // RESUMING_INTERNAL On resumption. |
| 274 INTERRUPTED_INTERNAL, | 276 INTERRUPTED_INTERNAL, |
| 275 | 277 |
| 276 // A request to resume this interrupted download is in progress. | 278 // A request to resume this interrupted download is in progress. |
| 277 // Transitions from: | 279 // Transitions from: |
| 278 // INTERRUPTED_INTERNAL | 280 // INTERRUPTED_INTERNAL |
| 279 // Transitions to: | 281 // Transitions to: |
| 280 // IN_PROGRESS_INTERNAL Once a server response is received from a | 282 // IN_PROGRESS_INTERNAL Once a server response is received from a |
| 281 // resumption. | 283 // resumption. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 298 // These are listed in approximately chronological order. There are also | 300 // These are listed in approximately chronological order. There are also |
| 299 // public methods involved in normal download progression; see | 301 // public methods involved in normal download progression; see |
| 300 // the implementation ordering in download_item_impl.cc. | 302 // the implementation ordering in download_item_impl.cc. |
| 301 | 303 |
| 302 // Construction common to all constructors. |active| should be true for new | 304 // Construction common to all constructors. |active| should be true for new |
| 303 // downloads and false for downloads from the history. | 305 // downloads and false for downloads from the history. |
| 304 // |download_type| indicates to the net log system what kind of download | 306 // |download_type| indicates to the net log system what kind of download |
| 305 // this is. | 307 // this is. |
| 306 void Init(bool active, DownloadType download_type); | 308 void Init(bool active, DownloadType download_type); |
| 307 | 309 |
| 310 // Callback from file thread when we initialize the DownloadFile. | |
| 311 void OnDownloadFileInitialized(DownloadInterruptReason result); | |
| 312 | |
| 313 // Called to determine the target path. Will cause OnDownloadTargetDetermined | |
| 314 // to be called when the target information is available. | |
| 315 void DetermineDownloadTarget(); | |
| 316 | |
| 308 // Called when the target path has been determined. |target_path| is the | 317 // Called when the target path has been determined. |target_path| is the |
| 309 // suggested target path. |disposition| indicates how the target path should | 318 // suggested target path. |disposition| indicates how the target path should |
| 310 // be used (see TargetDisposition). |danger_type| is the danger level of | 319 // be used (see TargetDisposition). |danger_type| is the danger level of |
| 311 // |target_path| as determined by the caller. |intermediate_path| is the path | 320 // |target_path| as determined by the caller. |intermediate_path| is the path |
| 312 // to use to store the download until OnDownloadCompleting() is called. | 321 // to use to store the download until OnDownloadCompleting() is called. |
| 313 virtual void OnDownloadTargetDetermined( | 322 virtual void OnDownloadTargetDetermined( |
| 314 const base::FilePath& target_path, | 323 const base::FilePath& target_path, |
| 315 TargetDisposition disposition, | 324 TargetDisposition disposition, |
| 316 DownloadDangerType danger_type, | 325 DownloadDangerType danger_type, |
| 317 const base::FilePath& intermediate_path); | 326 const base::FilePath& intermediate_path); |
| 318 | 327 |
| 319 // Callback from file thread when we initialize the DownloadFile. | |
| 320 void OnDownloadFileInitialized(DownloadInterruptReason result); | |
| 321 | |
| 322 void OnDownloadRenamedToIntermediateName( | 328 void OnDownloadRenamedToIntermediateName( |
| 323 DownloadInterruptReason reason, const base::FilePath& full_path); | 329 DownloadInterruptReason reason, const base::FilePath& full_path); |
| 324 | 330 |
| 325 // If all pre-requisites have been met, complete download processing, i.e. do | 331 // If all pre-requisites have been met, complete download processing, i.e. do |
| 326 // internal cleanup, file rename, and potentially auto-open. (Dangerous | 332 // internal cleanup, file rename, and potentially auto-open. (Dangerous |
| 327 // downloads still may block on user acceptance after this point.) | 333 // downloads still may block on user acceptance after this point.) |
| 328 void MaybeCompleteDownload(); | 334 void MaybeCompleteDownload(); |
| 329 | 335 |
| 330 // Called when the download is ready to complete. | 336 // Called when the download is ready to complete. |
| 331 // This may perform final rename if necessary and will eventually call | 337 // This may perform final rename if necessary and will eventually call |
| 332 // DownloadItem::Completed(). | 338 // DownloadItem::Completed(). |
| 333 void OnDownloadCompleting(); | 339 void OnDownloadCompleting(); |
| 334 | 340 |
| 335 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, | 341 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, |
| 336 const base::FilePath& full_path); | 342 const base::FilePath& full_path); |
| 337 | 343 |
| 338 // Called if the embedder took over opening a download, to indicate that | 344 // Called if the embedder took over opening a download, to indicate that |
| 339 // the download has been opened. | 345 // the download has been opened. |
| 340 void DelayedDownloadOpened(bool auto_opened); | 346 void DelayedDownloadOpened(bool auto_opened); |
| 341 | 347 |
| 342 // Called when the entire download operation (including renaming etc) | 348 // Called when the entire download operation (including renaming etc) |
| 343 // is completed. | 349 // is completed. |
| 344 void Completed(); | 350 void Completed(); |
| 345 | 351 |
| 346 // Callback invoked when the URLRequest for a download resumption has started. | |
| 347 void OnResumeRequestStarted(DownloadItem* item, | |
| 348 DownloadInterruptReason interrupt_reason); | |
| 349 | |
| 350 // Helper routines ----------------------------------------------------------- | 352 // Helper routines ----------------------------------------------------------- |
| 351 | 353 |
| 352 // Indicate that an error has occurred on the download. | 354 // Indicate that an error has occurred on the download. |
| 353 void Interrupt(DownloadInterruptReason reason); | 355 void Interrupt(DownloadInterruptReason reason, |
| 356 ShouldUpdateObservers should_update_observers); | |
|
Randy Smith (Not in Mondays)
2016/02/10 21:48:45
I'll just note that I thought of the internal/exte
asanka
2016/02/11 03:43:07
Good point. I removed the ShouldUpdateObservers lo
Randy Smith (Not in Mondays)
2016/02/11 22:08:08
*nod* I had forgotten that TransitionTo() had tha
asanka
2016/02/11 23:57:25
I think the problem is that having things like Tra
Randy Smith (Not in Mondays)
2016/02/12 18:01:18
SGTM. I'd like to be careful (at some point; I d
| |
| 354 | 357 |
| 355 // Destroy the DownloadFile object. If |destroy_file| is true, the file is | 358 // Destroy the DownloadFile object. If |destroy_file| is true, the file is |
| 356 // destroyed with it. Otherwise, DownloadFile::Detach() is called before | 359 // destroyed with it. Otherwise, DownloadFile::Detach() is called before |
| 357 // object destruction to prevent file destruction. Destroying the file also | 360 // object destruction to prevent file destruction. Destroying the file also |
| 358 // resets |current_path_|. | 361 // resets |current_path_|. |
| 359 void ReleaseDownloadFile(bool destroy_file); | 362 void ReleaseDownloadFile(bool destroy_file); |
| 360 | 363 |
| 361 // Check if a download is ready for completion. The callback provided | 364 // Check if a download is ready for completion. The callback provided |
| 362 // may be called at some point in the future if an external entity | 365 // may be called at some point in the future if an external entity |
| 363 // state has change s.t. this routine should be checked again. | 366 // state has change s.t. this routine should be checked again. |
| 364 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); | 367 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); |
| 365 | 368 |
| 366 // Call to transition state; all state transitions should go through this. | 369 // Call to transition state; all state transitions should go through this. |
| 367 // |notify_action| specifies whether or not to call UpdateObservers() after | 370 // |notify_action| specifies whether or not to call UpdateObservers() after |
| 368 // the state transition. | 371 // the state transition. |
| 369 void TransitionTo(DownloadInternalState new_state, | 372 void TransitionTo(DownloadInternalState new_state, |
| 370 ShouldUpdateObservers notify_action); | 373 ShouldUpdateObservers notify_action); |
|
Randy Smith (Not in Mondays)
2016/02/11 22:08:08
This makes me architecturally happy but concerned
asanka
2016/02/11 23:57:25
Hmm. I can revert if the change makes the CL harde
Randy Smith (Not in Mondays)
2016/02/12 18:01:18
I think we decided offline to let this be.
| |
| 371 | 374 |
| 372 // Set the |danger_type_| and invoke obserers if necessary. | 375 // Set the |danger_type_| and invoke obserers if necessary. |
| 373 void SetDangerType(DownloadDangerType danger_type); | 376 void SetDangerType(DownloadDangerType danger_type); |
| 374 | 377 |
| 375 void SetFullPath(const base::FilePath& new_path); | 378 void SetFullPath(const base::FilePath& new_path); |
| 376 | 379 |
| 377 void AutoResumeIfValid(); | 380 void AutoResumeIfValid(); |
| 378 | 381 |
| 379 void ResumeInterruptedDownload(); | 382 void ResumeInterruptedDownload(); |
| 380 | 383 |
| 384 void InvokeDelegateForResumption(); | |
| 385 | |
| 386 // Update origin information based on the response to a download resumption | |
| 387 // request. Should only be called if the resumption request was successful. | |
| 388 virtual void UpdateValidatorsOnResumption( | |
| 389 const DownloadCreateInfo& new_create_info); | |
| 390 | |
| 381 static DownloadState InternalToExternalState( | 391 static DownloadState InternalToExternalState( |
| 382 DownloadInternalState internal_state); | 392 DownloadInternalState internal_state); |
| 383 static DownloadInternalState ExternalToInternalState( | 393 static DownloadInternalState ExternalToInternalState( |
| 384 DownloadState external_state); | 394 DownloadState external_state); |
| 385 | 395 |
| 386 // Debugging routines -------------------------------------------------------- | 396 // Debugging routines -------------------------------------------------------- |
| 387 static const char* DebugDownloadStateString(DownloadInternalState state); | 397 static const char* DebugDownloadStateString(DownloadInternalState state); |
| 388 static const char* DebugResumeModeString(ResumeMode mode); | 398 static const char* DebugResumeModeString(ResumeMode mode); |
| 389 | 399 |
| 390 // Will be false for save package downloads retrieved from the history. | 400 // Will be false for save package downloads retrieved from the history. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 const net::BoundNetLog bound_net_log_; | 563 const net::BoundNetLog bound_net_log_; |
| 554 | 564 |
| 555 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 565 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 556 | 566 |
| 557 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 567 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 558 }; | 568 }; |
| 559 | 569 |
| 560 } // namespace content | 570 } // namespace content |
| 561 | 571 |
| 562 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 572 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |