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

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: Deal with downloads that are blocked by throttles. 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Embedder is in the process of determining the target of the download. 241 // Embedder is in the process of determining the target of the download.
240 // Since the embedder is sensitive to state transitions during this time, 242 // Since the embedder is sensitive to state transitions during this time,
241 // any DestinationError/DestinationCompleted events are deferred until 243 // any DestinationError/DestinationCompleted events are deferred until
242 // TARGET_RESOLVED_INTERNAL. 244 // TARGET_RESOLVED_INTERNAL.
243 // 245 //
244 // Transitions to: 246 // Transitions to:
245 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback. 247 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback.
246 // CANCELLED_INTERNAL: Cancelled. 248 // CANCELLED_INTERNAL: Cancelled.
247 TARGET_PENDING_INTERNAL, 249 TARGET_PENDING_INTERNAL,
248 250
251 INTERRUPTED_TARGET_PENDING_INTERNAL,
252
249 // Embedder has completed target determination. It is now safe to resolve 253 // Embedder has completed target determination. It is now safe to resolve
250 // the download target as well as process deferred DestinationError events. 254 // the download target as well as process deferred DestinationError events.
251 // This state is differs from TARGET_PENDING_INTERNAL due to it being 255 // This state is differs from TARGET_PENDING_INTERNAL due to it being
252 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from 256 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from
253 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having 257 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having
254 // a valid target. 258 // a valid target.
255 // 259 //
256 // Transitions to: 260 // Transitions to:
257 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming 261 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming
258 // data stream can now be written to the target. 262 // data stream can now be written to the target.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Transitions from: 319 // Transitions from:
316 // <Initial creation> Cancelled persisted downloads. 320 // <Initial creation> Cancelled persisted downloads.
317 // 321 //
318 // Transitions to: 322 // Transitions to:
319 // <none> Terminal state. 323 // <none> Terminal state.
320 CANCELLED_INTERNAL, 324 CANCELLED_INTERNAL,
321 325
322 MAX_DOWNLOAD_INTERNAL_STATE, 326 MAX_DOWNLOAD_INTERNAL_STATE,
323 }; 327 };
324 328
325 // Used with TransitionTo() to indicate whether or not to call
326 // UpdateObservers() after the state transition.
327 enum ShouldUpdateObservers {
328 UPDATE_OBSERVERS,
329 DONT_UPDATE_OBSERVERS
330 };
331
332 // Normal progression of a download ------------------------------------------ 329 // Normal progression of a download ------------------------------------------
333 330
334 // These are listed in approximately chronological order. There are also 331 // These are listed in approximately chronological order. There are also
335 // public methods involved in normal download progression; see 332 // public methods involved in normal download progression; see
336 // the implementation ordering in download_item_impl.cc. 333 // the implementation ordering in download_item_impl.cc.
337 334
338 // Construction common to all constructors. |active| should be true for new 335 // Construction common to all constructors. |active| should be true for new
339 // downloads and false for downloads from the history. 336 // downloads and false for downloads from the history.
340 // |download_type| indicates to the net log system what kind of download 337 // |download_type| indicates to the net log system what kind of download
341 // this is. 338 // this is.
342 void Init(bool active, DownloadType download_type); 339 void Init(bool active, DownloadType download_type);
343 340
341 // Callback from file thread when we initialize the DownloadFile.
342 void OnDownloadFileInitialized(DownloadInterruptReason result);
343
344 // Called to determine the target path. Will cause OnDownloadTargetDetermined
345 // to be called when the target information is available.
346 void DetermineDownloadTarget();
347
344 // Called when the target path has been determined. |target_path| is the 348 // Called when the target path has been determined. |target_path| is the
345 // suggested target path. |disposition| indicates how the target path should 349 // suggested target path. |disposition| indicates how the target path should
346 // be used (see TargetDisposition). |danger_type| is the danger level of 350 // be used (see TargetDisposition). |danger_type| is the danger level of
347 // |target_path| as determined by the caller. |intermediate_path| is the path 351 // |target_path| as determined by the caller. |intermediate_path| is the path
348 // to use to store the download until OnDownloadCompleting() is called. 352 // to use to store the download until OnDownloadCompleting() is called.
349 virtual void OnDownloadTargetDetermined( 353 virtual void OnDownloadTargetDetermined(
350 const base::FilePath& target_path, 354 const base::FilePath& target_path,
351 TargetDisposition disposition, 355 TargetDisposition disposition,
352 DownloadDangerType danger_type, 356 DownloadDangerType danger_type,
353 const base::FilePath& intermediate_path); 357 const base::FilePath& intermediate_path);
354 358
355 // Callback from file thread when we initialize the DownloadFile.
356 void OnDownloadFileInitialized(DownloadInterruptReason result);
357
358 void OnDownloadRenamedToIntermediateName( 359 void OnDownloadRenamedToIntermediateName(
359 DownloadInterruptReason reason, const base::FilePath& full_path); 360 DownloadInterruptReason reason, const base::FilePath& full_path);
360 361
361 // If all pre-requisites have been met, complete download processing, i.e. do 362 // If all pre-requisites have been met, complete download processing, i.e. do
362 // internal cleanup, file rename, and potentially auto-open. (Dangerous 363 // internal cleanup, file rename, and potentially auto-open. (Dangerous
363 // downloads still may block on user acceptance after this point.) 364 // downloads still may block on user acceptance after this point.)
364 void MaybeCompleteDownload(); 365 void MaybeCompleteDownload();
365 366
366 // Called when the download is ready to complete. 367 // Called when the download is ready to complete.
367 // This may perform final rename if necessary and will eventually call 368 // This may perform final rename if necessary and will eventually call
368 // DownloadItem::Completed(). 369 // DownloadItem::Completed().
369 void OnDownloadCompleting(); 370 void OnDownloadCompleting();
370 371
371 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason, 372 void OnDownloadRenamedToFinalName(DownloadInterruptReason reason,
372 const base::FilePath& full_path); 373 const base::FilePath& full_path);
373 374
374 // Called if the embedder took over opening a download, to indicate that 375 // Called if the embedder took over opening a download, to indicate that
375 // the download has been opened. 376 // the download has been opened.
376 void DelayedDownloadOpened(bool auto_opened); 377 void DelayedDownloadOpened(bool auto_opened);
377 378
378 // Called when the entire download operation (including renaming etc) 379 // Called when the entire download operation (including renaming etc)
379 // is completed. 380 // is completed.
380 void Completed(); 381 void Completed();
381 382
382 // Callback invoked when the URLRequest for a download resumption has started.
383 void OnResumeRequestStarted(DownloadItem* item,
384 DownloadInterruptReason interrupt_reason);
385
386 // Helper routines ----------------------------------------------------------- 383 // Helper routines -----------------------------------------------------------
387 384
388 // Indicate that an error has occurred on the download. 385 // Indicate that an error has occurred on the download.
389 void Interrupt(DownloadInterruptReason reason); 386 void Interrupt(DownloadInterruptReason reason);
390 387
391 // Destroy the DownloadFile object. If |destroy_file| is true, the file is 388 // Destroy the DownloadFile object. If |destroy_file| is true, the file is
392 // destroyed with it. Otherwise, DownloadFile::Detach() is called before 389 // destroyed with it. Otherwise, DownloadFile::Detach() is called before
393 // object destruction to prevent file destruction. Destroying the file also 390 // object destruction to prevent file destruction. Destroying the file also
394 // resets |current_path_|. 391 // resets |current_path_|.
395 void ReleaseDownloadFile(bool destroy_file); 392 void ReleaseDownloadFile(bool destroy_file);
396 393
397 // Check if a download is ready for completion. The callback provided 394 // Check if a download is ready for completion. The callback provided
398 // may be called at some point in the future if an external entity 395 // may be called at some point in the future if an external entity
399 // state has change s.t. this routine should be checked again. 396 // state has change s.t. this routine should be checked again.
400 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify); 397 bool IsDownloadReadyForCompletion(const base::Closure& state_change_notify);
401 398
402 // Call to transition state; all state transitions should go through this. 399 // Call to transition state; all state transitions should go through this.
403 // |notify_action| specifies whether or not to call UpdateObservers() after 400 // |notify_action| specifies whether or not to call UpdateObservers() after
404 // the state transition. 401 // the state transition.
405 void TransitionTo(DownloadInternalState new_state, 402 void TransitionTo(DownloadInternalState new_state);
406 ShouldUpdateObservers notify_action);
407 403
408 // Set the |danger_type_| and invoke obserers if necessary. 404 // Set the |danger_type_| and invoke obserers if necessary.
409 void SetDangerType(DownloadDangerType danger_type); 405 void SetDangerType(DownloadDangerType danger_type);
410 406
411 void SetFullPath(const base::FilePath& new_path); 407 void SetFullPath(const base::FilePath& new_path);
412 408
413 void AutoResumeIfValid(); 409 void AutoResumeIfValid();
414 410
415 void ResumeInterruptedDownload(); 411 void ResumeInterruptedDownload();
416 412
413 // Update origin information based on the response to a download resumption
414 // request. Should only be called if the resumption request was successful.
415 virtual void UpdateValidatorsOnResumption(
416 const DownloadCreateInfo& new_create_info);
417
417 static DownloadState InternalToExternalState( 418 static DownloadState InternalToExternalState(
418 DownloadInternalState internal_state); 419 DownloadInternalState internal_state);
419 static DownloadInternalState ExternalToInternalState( 420 static DownloadInternalState ExternalToInternalState(
420 DownloadState external_state); 421 DownloadState external_state);
421 422
422 // Debugging routines -------------------------------------------------------- 423 // Debugging routines --------------------------------------------------------
423 static const char* DebugDownloadStateString(DownloadInternalState state); 424 static const char* DebugDownloadStateString(DownloadInternalState state);
424 static const char* DebugResumeModeString(ResumeMode mode); 425 static const char* DebugResumeModeString(ResumeMode mode);
425 static bool IsValidSavePackageStateTransition(DownloadInternalState from, 426 static bool IsValidSavePackageStateTransition(DownloadInternalState from,
426 DownloadInternalState to); 427 DownloadInternalState to);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 const net::BoundNetLog bound_net_log_; 594 const net::BoundNetLog bound_net_log_;
594 595
595 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 596 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
596 597
597 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 598 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
598 }; 599 };
599 600
600 } // namespace content 601 } // namespace content
601 602
602 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 603 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698