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

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: Ketchup with upstream. 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 INTERRUPTED_TARGET_PENDING_INTERNAL,
Randy Smith (Not in Mondays) 2016/02/11 22:08:09 (Discussed offline, noting for online record) Need
asanka 2016/02/11 23:57:25 Done.
264
261 // Embedder has completed target determination. It is now safe to resolve 265 // Embedder has completed target determination. It is now safe to resolve
262 // the download target as well as process deferred DestinationError events. 266 // the download target as well as process deferred DestinationError events.
263 // This state is differs from TARGET_PENDING_INTERNAL due to it being 267 // This state is differs from TARGET_PENDING_INTERNAL due to it being
264 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from 268 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from
265 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having 269 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having
266 // a valid target. 270 // a valid target.
267 // 271 //
268 // Transitions to (regular): 272 // Transitions to (regular):
269 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming 273 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming
270 // data stream can now be written to the target. 274 // data stream can now be written to the target.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Transitions to (regular): 342 // Transitions to (regular):
339 // <none> Terminal state. 343 // <none> Terminal state.
340 // 344 //
341 // Transitions to (SavePackage): 345 // Transitions to (SavePackage):
342 // <none> Terminal state. 346 // <none> Terminal state.
343 CANCELLED_INTERNAL, 347 CANCELLED_INTERNAL,
344 348
345 MAX_DOWNLOAD_INTERNAL_STATE, 349 MAX_DOWNLOAD_INTERNAL_STATE,
346 }; 350 };
347 351
348 // Used with TransitionTo() to indicate whether or not to call
349 // UpdateObservers() after the state transition.
350 enum ShouldUpdateObservers {
351 UPDATE_OBSERVERS,
352 DONT_UPDATE_OBSERVERS
353 };
354
355 // Normal progression of a download ------------------------------------------ 352 // Normal progression of a download ------------------------------------------
356 353
357 // These are listed in approximately chronological order. There are also 354 // These are listed in approximately chronological order. There are also
358 // public methods involved in normal download progression; see 355 // public methods involved in normal download progression; see
359 // the implementation ordering in download_item_impl.cc. 356 // the implementation ordering in download_item_impl.cc.
360 357
361 // Construction common to all constructors. |active| should be true for new 358 // Construction common to all constructors. |active| should be true for new
362 // downloads and false for downloads from the history. 359 // downloads and false for downloads from the history.
363 // |download_type| indicates to the net log system what kind of download 360 // |download_type| indicates to the net log system what kind of download
364 // this is. 361 // this is.
365 void Init(bool active, DownloadType download_type); 362 void Init(bool active, DownloadType download_type);
366 363
364 // Callback from file thread when we initialize the DownloadFile.
365 void OnDownloadFileInitialized(DownloadInterruptReason result);
366
367 // Called to determine the target path. Will cause OnDownloadTargetDetermined
368 // to be called when the target information is available.
369 void DetermineDownloadTarget();
370
367 // Called when the target path has been determined. |target_path| is the 371 // Called when the target path has been determined. |target_path| is the
368 // suggested target path. |disposition| indicates how the target path should 372 // suggested target path. |disposition| indicates how the target path should
369 // be used (see TargetDisposition). |danger_type| is the danger level of 373 // be used (see TargetDisposition). |danger_type| is the danger level of
370 // |target_path| as determined by the caller. |intermediate_path| is the path 374 // |target_path| as determined by the caller. |intermediate_path| is the path
371 // to use to store the download until OnDownloadCompleting() is called. 375 // to use to store the download until OnDownloadCompleting() is called.
372 virtual void OnDownloadTargetDetermined( 376 virtual void OnDownloadTargetDetermined(
373 const base::FilePath& target_path, 377 const base::FilePath& target_path,
374 TargetDisposition disposition, 378 TargetDisposition disposition,
375 DownloadDangerType danger_type, 379 DownloadDangerType danger_type,
376 const base::FilePath& intermediate_path); 380 const base::FilePath& intermediate_path);
377 381
378 // Callback from file thread when we initialize the DownloadFile.
379 void OnDownloadFileInitialized(DownloadInterruptReason result);
380
381 void OnDownloadRenamedToIntermediateName( 382 void OnDownloadRenamedToIntermediateName(
382 DownloadInterruptReason reason, const base::FilePath& full_path); 383 DownloadInterruptReason reason, const base::FilePath& full_path);
383 384
384 // If all pre-requisites have been met, complete download processing, i.e. do 385 // If all pre-requisites have been met, complete download processing, i.e. do
385 // internal cleanup, file rename, and potentially auto-open. (Dangerous 386 // internal cleanup, file rename, and potentially auto-open. (Dangerous
386 // downloads still may block on user acceptance after this point.) 387 // downloads still may block on user acceptance after this point.)
387 void MaybeCompleteDownload(); 388 void MaybeCompleteDownload();
388 389
389 // Called when the download is ready to complete. 390 // Called when the download is ready to complete.
390 // This may perform final rename if necessary and will eventually call 391 // This may perform final rename if necessary and will eventually call
391 // DownloadItem::Completed(). 392 // DownloadItem::Completed().
392 void OnDownloadCompleting(); 393 void OnDownloadCompleting();
393 394
394 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, 395 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason,
395 const base::FilePath& full_path); 396 const base::FilePath& full_path);
396 397
397 // Called if the embedder took over opening a download, to indicate that 398 // Called if the embedder took over opening a download, to indicate that
398 // the download has been opened. 399 // the download has been opened.
399 void DelayedDownloadOpened(bool auto_opened); 400 void DelayedDownloadOpened(bool auto_opened);
400 401
401 // Called when the entire download operation (including renaming etc) 402 // Called when the entire download operation (including renaming etc)
402 // is completed. 403 // is completed.
403 void Completed(); 404 void Completed();
404 405
405 // Callback invoked when the URLRequest for a download resumption has started.
406 void OnResumeRequestStarted(DownloadItem* item,
407 DownloadInterruptReason interrupt_reason);
408
409 // Helper routines ----------------------------------------------------------- 406 // Helper routines -----------------------------------------------------------
410 407
411 // Indicate that an error has occurred on the download. 408 // Indicate that an error has occurred on the download.
412 void Interrupt(DownloadInterruptReason reason); 409 void Interrupt(DownloadInterruptReason reason);
413 410
414 // Destroy the DownloadFile object. If |destroy_file| is true, the file is 411 // Destroy the DownloadFile object. If |destroy_file| is true, the file is
415 // destroyed with it. Otherwise, DownloadFile::Detach() is called before 412 // destroyed with it. Otherwise, DownloadFile::Detach() is called before
416 // object destruction to prevent file destruction. Destroying the file also 413 // object destruction to prevent file destruction. Destroying the file also
417 // resets |current_path_|. 414 // resets |current_path_|.
418 void ReleaseDownloadFile(bool destroy_file); 415 void ReleaseDownloadFile(bool destroy_file);
419 416
420 // Check if a download is ready for completion. The callback provided 417 // Check if a download is ready for completion. The callback provided
421 // may be called at some point in the future if an external entity 418 // may be called at some point in the future if an external entity
422 // state has change s.t. this routine should be checked again. 419 // state has change s.t. this routine should be checked again.
423 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); 420 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify);
424 421
425 // Call to transition state; all state transitions should go through this. 422 // Call to transition state; all state transitions should go through this.
426 // |notify_action| specifies whether or not to call UpdateObservers() after 423 // |notify_action| specifies whether or not to call UpdateObservers() after
427 // the state transition. 424 // the state transition.
428 void TransitionTo(DownloadInternalState new_state, 425 void TransitionTo(DownloadInternalState new_state);
429 ShouldUpdateObservers notify_action);
430 426
431 // Set the |danger_type_| and invoke obserers if necessary. 427 // Set the |danger_type_| and invoke obserers if necessary.
432 void SetDangerType(DownloadDangerType danger_type); 428 void SetDangerType(DownloadDangerType danger_type);
433 429
434 void SetFullPath(const base::FilePath& new_path); 430 void SetFullPath(const base::FilePath& new_path);
435 431
436 void AutoResumeIfValid(); 432 void AutoResumeIfValid();
437 433
438 void ResumeInterruptedDownload(); 434 void ResumeInterruptedDownload();
439 435
436 // Update origin information based on the response to a download resumption
437 // request. Should only be called if the resumption request was successful.
438 virtual void UpdateValidatorsOnResumption(
439 const DownloadCreateInfo& new_create_info);
440
440 static DownloadState InternalToExternalState( 441 static DownloadState InternalToExternalState(
441 DownloadInternalState internal_state); 442 DownloadInternalState internal_state);
442 static DownloadInternalState ExternalToInternalState( 443 static DownloadInternalState ExternalToInternalState(
443 DownloadState external_state); 444 DownloadState external_state);
444 445
445 // Debugging routines -------------------------------------------------------- 446 // Debugging routines --------------------------------------------------------
446 static const char* DebugDownloadStateString(DownloadInternalState state); 447 static const char* DebugDownloadStateString(DownloadInternalState state);
447 static const char* DebugResumeModeString(ResumeMode mode); 448 static const char* DebugResumeModeString(ResumeMode mode);
448 static bool IsValidSavePackageStateTransition(DownloadInternalState from, 449 static bool IsValidSavePackageStateTransition(DownloadInternalState from,
449 DownloadInternalState to); 450 DownloadInternalState to);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 const net::BoundNetLog bound_net_log_; 617 const net::BoundNetLog bound_net_log_;
617 618
618 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 619 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
619 620
620 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 621 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
621 }; 622 };
622 623
623 } // namespace content 624 } // namespace content
624 625
625 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 626 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698