Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: content/browser/download/download_item_impl.h

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment updates Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 int64_t received_bytes, 66 int64_t received_bytes,
67 int64_t total_bytes, 67 int64_t total_bytes,
68 DownloadItem::DownloadState state, 68 DownloadItem::DownloadState state,
69 DownloadDangerType danger_type, 69 DownloadDangerType danger_type,
70 DownloadInterruptReason interrupt_reason, 70 DownloadInterruptReason interrupt_reason,
71 bool opened, 71 bool opened,
72 const net::BoundNetLog& bound_net_log); 72 const net::BoundNetLog& bound_net_log);
73 73
74 // Constructing for a regular download. 74 // Constructing for a regular download.
75 // |bound_net_log| is constructed externally for our use. 75 // |bound_net_log| is constructed externally for our use.
76 // TODO(asanka): Get rid of the DownloadCreateInfo parameter since active
77 // downloads end up at Start() immediately after creation.
76 DownloadItemImpl(DownloadItemImplDelegate* delegate, 78 DownloadItemImpl(DownloadItemImplDelegate* delegate,
77 uint32_t id, 79 uint32_t id,
78 const DownloadCreateInfo& info, 80 const DownloadCreateInfo& info,
79 const net::BoundNetLog& bound_net_log); 81 const net::BoundNetLog& bound_net_log);
80 82
81 // Constructing for the "Save Page As..." feature: 83 // Constructing for the "Save Page As..." feature:
82 // |bound_net_log| is constructed externally for our use. 84 // |bound_net_log| is constructed externally for our use.
83 DownloadItemImpl(DownloadItemImplDelegate* delegate, 85 DownloadItemImpl(DownloadItemImplDelegate* delegate,
84 uint32_t id, 86 uint32_t id,
85 const base::FilePath& path, 87 const base::FilePath& path,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 std::string DebugString(bool verbose) const override; 162 std::string DebugString(bool verbose) const override;
161 163
162 // All remaining public interfaces virtual to allow for DownloadItemImpl 164 // All remaining public interfaces virtual to allow for DownloadItemImpl
163 // mocks. 165 // mocks.
164 166
165 // Determines the resume mode for an interrupted download. Requires 167 // Determines the resume mode for an interrupted download. Requires
166 // last_reason_ to be set, but doesn't require the download to be in 168 // last_reason_ to be set, but doesn't require the download to be in
167 // INTERRUPTED state. 169 // INTERRUPTED state.
168 virtual ResumeMode GetResumeMode() const; 170 virtual ResumeMode GetResumeMode() const;
169 171
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 -------------------------- 172 // State transition operations on regular downloads --------------------------
176 173
177 // Start the download. 174 // Start the download.
178 // |download_file| is the associated file on the storage medium. 175 // |download_file| is the associated file on the storage medium.
179 // |req_handle| is the new request handle associated with the download. 176 // |req_handle| is the new request handle associated with the download.
177 // |new_create_info| is a DownloadCreateInfo containing the new response
178 // parameters. It may be different from the DownloadCreateInfo used to create
179 // the DownloadItem if Start() is being called in response for a download
180 // resumption request.
180 virtual void Start(scoped_ptr<DownloadFile> download_file, 181 virtual void Start(scoped_ptr<DownloadFile> download_file,
181 scoped_ptr<DownloadRequestHandleInterface> req_handle); 182 scoped_ptr<DownloadRequestHandleInterface> req_handle,
183 const DownloadCreateInfo& new_create_info);
182 184
183 // Needed because of intertwining with DownloadManagerImpl ------------------- 185 // Needed because of intertwining with DownloadManagerImpl -------------------
184 186
185 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, 187 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl,
186 // removing these from the public interface. 188 // removing these from the public interface.
187 189
188 // Notify observers that this item is being removed by the user. 190 // Notify observers that this item is being removed by the user.
189 virtual void NotifyRemoved(); 191 virtual void NotifyRemoved();
190 192
191 virtual void OnDownloadedFileRemoved(); 193 virtual void OnDownloadedFileRemoved();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // TARGET_RESOLVED_INTERNAL. 253 // TARGET_RESOLVED_INTERNAL.
252 // 254 //
253 // Transitions to (regular): 255 // Transitions to (regular):
254 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback. 256 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback.
255 // CANCELLED_INTERNAL: Cancelled. 257 // CANCELLED_INTERNAL: Cancelled.
256 // 258 //
257 // Transitions to (SavePackage): 259 // Transitions to (SavePackage):
258 // <n/a> SavePackage downloads never reach this state. 260 // <n/a> SavePackage downloads never reach this state.
259 TARGET_PENDING_INTERNAL, 261 TARGET_PENDING_INTERNAL,
260 262
263 // Embedder is in the process of determining the target of the download, and
264 // the download is in an interrupted state. The externally this state is
265 // exposed as interrupted, so that target determination can take it into
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 Comment out of date.
asanka 2016/02/12 23:34:47 Done.
266 // account.
267 //
268 // Transitions to (regular):
269 // INTERRUPTED_INTERNAL: Once the target is determined, the download
270 // is marked as interrupted.
271 // CANCELLED_INTERNAL: Cancelled.
272 //
273 // Transitions to (SavePackage):
274 // <n/a> SavePackage downloads never reach this state.
275 INTERRUPTED_TARGET_PENDING_INTERNAL,
276
261 // Embedder has completed target determination. It is now safe to resolve 277 // Embedder has completed target determination. It is now safe to resolve
262 // the download target as well as process deferred DestinationError events. 278 // the download target as well as process deferred DestinationError events.
263 // This state is differs from TARGET_PENDING_INTERNAL due to it being 279 // This state is differs from TARGET_PENDING_INTERNAL due to it being
264 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from 280 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from
265 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having 281 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having
266 // a valid target. This state is transient (i.e. DownloadItemImpl will 282 // a valid target. This state is transient (i.e. DownloadItemImpl will
267 // transition out of it before yielding execution). It's only purpose in 283 // transition out of it before yielding execution). It's only purpose in
268 // life is to ensure the integrity of state transitions. 284 // life is to ensure the integrity of state transitions.
269 // 285 //
270 // Transitions to (regular): 286 // Transitions to (regular):
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Transitions to (regular): 356 // Transitions to (regular):
341 // <none> Terminal state. 357 // <none> Terminal state.
342 // 358 //
343 // Transitions to (SavePackage): 359 // Transitions to (SavePackage):
344 // <none> Terminal state. 360 // <none> Terminal state.
345 CANCELLED_INTERNAL, 361 CANCELLED_INTERNAL,
346 362
347 MAX_DOWNLOAD_INTERNAL_STATE, 363 MAX_DOWNLOAD_INTERNAL_STATE,
348 }; 364 };
349 365
350 // Used with TransitionTo() to indicate whether or not to call
351 // UpdateObservers() after the state transition.
352 enum ShouldUpdateObservers {
353 UPDATE_OBSERVERS,
354 DONT_UPDATE_OBSERVERS
355 };
356
357 // Normal progression of a download ------------------------------------------ 366 // Normal progression of a download ------------------------------------------
358 367
359 // These are listed in approximately chronological order. There are also 368 // These are listed in approximately chronological order. There are also
360 // public methods involved in normal download progression; see 369 // public methods involved in normal download progression; see
361 // the implementation ordering in download_item_impl.cc. 370 // the implementation ordering in download_item_impl.cc.
362 371
363 // Construction common to all constructors. |active| should be true for new 372 // Construction common to all constructors. |active| should be true for new
364 // downloads and false for downloads from the history. 373 // downloads and false for downloads from the history.
365 // |download_type| indicates to the net log system what kind of download 374 // |download_type| indicates to the net log system what kind of download
366 // this is. 375 // this is.
367 void Init(bool active, DownloadType download_type); 376 void Init(bool active, DownloadType download_type);
368 377
378 // Callback from file thread when we initialize the DownloadFile.
379 void OnDownloadFileInitialized(DownloadInterruptReason result);
380
381 // Called to determine the target path. Will cause OnDownloadTargetDetermined
382 // to be called when the target information is available.
383 void DetermineDownloadTarget();
384
369 // Called when the target path has been determined. |target_path| is the 385 // Called when the target path has been determined. |target_path| is the
370 // suggested target path. |disposition| indicates how the target path should 386 // suggested target path. |disposition| indicates how the target path should
371 // be used (see TargetDisposition). |danger_type| is the danger level of 387 // be used (see TargetDisposition). |danger_type| is the danger level of
372 // |target_path| as determined by the caller. |intermediate_path| is the path 388 // |target_path| as determined by the caller. |intermediate_path| is the path
373 // to use to store the download until OnDownloadCompleting() is called. 389 // to use to store the download until OnDownloadCompleting() is called.
374 virtual void OnDownloadTargetDetermined( 390 virtual void OnDownloadTargetDetermined(
375 const base::FilePath& target_path, 391 const base::FilePath& target_path,
376 TargetDisposition disposition, 392 TargetDisposition disposition,
377 DownloadDangerType danger_type, 393 DownloadDangerType danger_type,
378 const base::FilePath& intermediate_path); 394 const base::FilePath& intermediate_path);
379 395
380 // Callback from file thread when we initialize the DownloadFile.
381 void OnDownloadFileInitialized(DownloadInterruptReason result);
382
383 void OnDownloadRenamedToIntermediateName( 396 void OnDownloadRenamedToIntermediateName(
384 DownloadInterruptReason reason, const base::FilePath& full_path); 397 DownloadInterruptReason reason, const base::FilePath& full_path);
385 398
386 // If all pre-requisites have been met, complete download processing, i.e. do 399 // If all pre-requisites have been met, complete download processing, i.e. do
387 // internal cleanup, file rename, and potentially auto-open. (Dangerous 400 // internal cleanup, file rename, and potentially auto-open. (Dangerous
388 // downloads still may block on user acceptance after this point.) 401 // downloads still may block on user acceptance after this point.)
389 void MaybeCompleteDownload(); 402 void MaybeCompleteDownload();
390 403
391 // Called when the download is ready to complete. 404 // Called when the download is ready to complete.
392 // This may perform final rename if necessary and will eventually call 405 // This may perform final rename if necessary and will eventually call
393 // DownloadItem::Completed(). 406 // DownloadItem::Completed().
394 void OnDownloadCompleting(); 407 void OnDownloadCompleting();
395 408
396 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, 409 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason,
397 const base::FilePath& full_path); 410 const base::FilePath& full_path);
398 411
399 // Called if the embedder took over opening a download, to indicate that 412 // Called if the embedder took over opening a download, to indicate that
400 // the download has been opened. 413 // the download has been opened.
401 void DelayedDownloadOpened(bool auto_opened); 414 void DelayedDownloadOpened(bool auto_opened);
402 415
403 // Called when the entire download operation (including renaming etc.) 416 // Called when the entire download operation (including renaming etc.)
404 // is completed. 417 // is completed.
405 void Completed(); 418 void Completed();
406 419
407 // Callback invoked when the URLRequest for a download resumption has started.
408 void OnResumeRequestStarted(DownloadItem* item,
409 DownloadInterruptReason interrupt_reason);
410
411 // Helper routines ----------------------------------------------------------- 420 // Helper routines -----------------------------------------------------------
412 421
413 // Indicate that an error has occurred on the download. 422 // Indicate that an error has occurred on the download.
414 void Interrupt(DownloadInterruptReason reason); 423 void Interrupt(DownloadInterruptReason reason);
415 424
416 // Destroy the DownloadFile object. If |destroy_file| is true, the file is 425 // Destroy the DownloadFile object. If |destroy_file| is true, the file is
417 // destroyed with it. Otherwise, DownloadFile::Detach() is called before 426 // destroyed with it. Otherwise, DownloadFile::Detach() is called before
418 // object destruction to prevent file destruction. Destroying the file also 427 // object destruction to prevent file destruction. Destroying the file also
419 // resets |current_path_|. 428 // resets |current_path_|.
420 void ReleaseDownloadFile(bool destroy_file); 429 void ReleaseDownloadFile(bool destroy_file);
421 430
422 // Check if a download is ready for completion. The callback provided 431 // Check if a download is ready for completion. The callback provided
423 // may be called at some point in the future if an external entity 432 // may be called at some point in the future if an external entity
424 // state has change s.t. this routine should be checked again. 433 // state has change s.t. this routine should be checked again.
425 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); 434 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify);
426 435
427 // Call to transition state; all state transitions should go through this. 436 // Call to transition state; all state transitions should go through this.
428 // |notify_action| specifies whether or not to call UpdateObservers() after 437 // |notify_action| specifies whether or not to call UpdateObservers() after
429 // the state transition. 438 // the state transition.
430 void TransitionTo(DownloadInternalState new_state, 439 void TransitionTo(DownloadInternalState new_state);
431 ShouldUpdateObservers notify_action);
432 440
433 // Set the |danger_type_| and invoke observers if necessary. 441 // Set the |danger_type_| and invoke observers if necessary.
434 void SetDangerType(DownloadDangerType danger_type); 442 void SetDangerType(DownloadDangerType danger_type);
435 443
436 void SetFullPath(const base::FilePath& new_path); 444 void SetFullPath(const base::FilePath& new_path);
437 445
438 void AutoResumeIfValid(); 446 void AutoResumeIfValid();
439 447
440 void ResumeInterruptedDownload(); 448 void ResumeInterruptedDownload();
441 449
450 // Update origin information based on the response to a download resumption
451 // request. Should only be called if the resumption request was successful.
452 virtual void UpdateValidatorsOnResumption(
453 const DownloadCreateInfo& new_create_info);
454
442 static DownloadState InternalToExternalState( 455 static DownloadState InternalToExternalState(
443 DownloadInternalState internal_state); 456 DownloadInternalState internal_state);
444 static DownloadInternalState ExternalToInternalState( 457 static DownloadInternalState ExternalToInternalState(
445 DownloadState external_state); 458 DownloadState external_state);
446 459
447 // Debugging routines -------------------------------------------------------- 460 // Debugging routines --------------------------------------------------------
448 static const char* DebugDownloadStateString(DownloadInternalState state); 461 static const char* DebugDownloadStateString(DownloadInternalState state);
449 static const char* DebugResumeModeString(ResumeMode mode); 462 static const char* DebugResumeModeString(ResumeMode mode);
450 static bool IsValidSavePackageStateTransition(DownloadInternalState from, 463 static bool IsValidSavePackageStateTransition(DownloadInternalState from,
451 DownloadInternalState to); 464 DownloadInternalState to);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 const net::BoundNetLog bound_net_log_; 631 const net::BoundNetLog bound_net_log_;
619 632
620 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 633 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
621 634
622 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 635 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
623 }; 636 };
624 637
625 } // namespace content 638 } // namespace content
626 639
627 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 640 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698