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

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

Issue 11571025: Initial CL for Downloads resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed CanResumeDownload (unused) and updated comment in RDH::BeginDownload. Created 7 years, 11 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 <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace content { 27 namespace content {
28 class DownloadFile; 28 class DownloadFile;
29 class DownloadItemImplDelegate; 29 class DownloadItemImplDelegate;
30 30
31 // See download_item.h for usage. 31 // See download_item.h for usage.
32 class CONTENT_EXPORT DownloadItemImpl 32 class CONTENT_EXPORT DownloadItemImpl
33 : public DownloadItem, 33 : public DownloadItem,
34 public DownloadDestinationObserver { 34 public DownloadDestinationObserver {
35 public: 35 public:
36 enum ResumeMode {
37 RESUME_MODE_INVALID = 0,
38 RESUME_MODE_IMMEDIATE_CONTINUE,
39 RESUME_MODE_IMMEDIATE_RESTART,
40 RESUME_MODE_USER_CONTINUE,
41 RESUME_MODE_USER_RESTART
42 };
43
44 // The maximum number of attempts we will make to resume automatically.
45 static const int kMaxAutoResumeAttempts;
46
36 // Note that it is the responsibility of the caller to ensure that a 47 // Note that it is the responsibility of the caller to ensure that a
37 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor 48 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor
38 // outlives the DownloadItemImpl. 49 // outlives the DownloadItemImpl.
39 50
40 // Constructing from persistent store: 51 // Constructing from persistent store:
41 // |bound_net_log| is constructed externally for our use. 52 // |bound_net_log| is constructed externally for our use.
42 DownloadItemImpl(DownloadItemImplDelegate* delegate, 53 DownloadItemImpl(DownloadItemImplDelegate* delegate,
43 DownloadId download_id, 54 DownloadId download_id,
44 const FilePath& path, 55 const FilePath& path,
45 const GURL& url, 56 const GURL& url,
46 const GURL& referrer_url, 57 const GURL& referrer_url,
47 const base::Time& start_time, 58 const base::Time& start_time,
48 const base::Time& end_time, 59 const base::Time& end_time,
49 int64 received_bytes, 60 int64 received_bytes,
50 int64 total_bytes, 61 int64 total_bytes,
51 DownloadItem::DownloadState state, 62 DownloadItem::DownloadState state,
52 bool opened, 63 bool opened,
53 const net::BoundNetLog& bound_net_log); 64 const net::BoundNetLog& bound_net_log);
54 65
55 // Constructing for a regular download. 66 // Constructing for a regular download.
56 // |bound_net_log| is constructed externally for our use. 67 // |bound_net_log| is constructed externally for our use.
57 DownloadItemImpl(DownloadItemImplDelegate* delegate, 68 DownloadItemImpl(DownloadItemImplDelegate* delegate,
58 const DownloadCreateInfo& info, 69 const DownloadCreateInfo& info,
59 scoped_ptr<DownloadRequestHandleInterface> request_handle,
60 const net::BoundNetLog& bound_net_log); 70 const net::BoundNetLog& bound_net_log);
61 71
62 // Constructing for the "Save Page As..." feature: 72 // Constructing for the "Save Page As..." feature:
63 // |bound_net_log| is constructed externally for our use. 73 // |bound_net_log| is constructed externally for our use.
64 DownloadItemImpl(DownloadItemImplDelegate* delegate, 74 DownloadItemImpl(DownloadItemImplDelegate* delegate,
65 const FilePath& path, 75 const FilePath& path,
66 const GURL& url, 76 const GURL& url,
67 DownloadId download_id, 77 DownloadId download_id,
68 const std::string& mime_type, 78 const std::string& mime_type,
69 const net::BoundNetLog& bound_net_log); 79 const net::BoundNetLog& bound_net_log);
70 80
71 virtual ~DownloadItemImpl(); 81 virtual ~DownloadItemImpl();
72 82
73 // DownloadItem 83 // DownloadItem
74 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; 84 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE;
75 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; 85 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE;
76 virtual void UpdateObservers() OVERRIDE; 86 virtual void UpdateObservers() OVERRIDE;
77 virtual void DangerousDownloadValidated() OVERRIDE; 87 virtual void DangerousDownloadValidated() OVERRIDE;
78 virtual void TogglePause() OVERRIDE; 88 virtual void TogglePause() OVERRIDE;
89 virtual void ResumeInterruptedDownload() OVERRIDE;
79 virtual void Cancel(bool user_cancel) OVERRIDE; 90 virtual void Cancel(bool user_cancel) OVERRIDE;
80 virtual void Delete(DeleteReason reason) OVERRIDE; 91 virtual void Delete(DeleteReason reason) OVERRIDE;
81 virtual void Remove() OVERRIDE; 92 virtual void Remove() OVERRIDE;
82 virtual void OpenDownload() OVERRIDE; 93 virtual void OpenDownload() OVERRIDE;
83 virtual void ShowDownloadInShell() OVERRIDE; 94 virtual void ShowDownloadInShell() OVERRIDE;
84 virtual int32 GetId() const OVERRIDE; 95 virtual int32 GetId() const OVERRIDE;
85 virtual DownloadId GetGlobalId() const OVERRIDE; 96 virtual DownloadId GetGlobalId() const OVERRIDE;
86 virtual DownloadState GetState() const OVERRIDE; 97 virtual DownloadState GetState() const OVERRIDE;
87 virtual DownloadInterruptReason GetLastReason() const OVERRIDE; 98 virtual DownloadInterruptReason GetLastReason() const OVERRIDE;
88 virtual bool IsPaused() const OVERRIDE; 99 virtual bool IsPaused() const OVERRIDE;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 149 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
139 virtual void SetIsTemporary(bool temporary) OVERRIDE; 150 virtual void SetIsTemporary(bool temporary) OVERRIDE;
140 virtual void SetOpened(bool opened) OVERRIDE; 151 virtual void SetOpened(bool opened) OVERRIDE;
141 virtual void SetDisplayName(const FilePath& name) OVERRIDE; 152 virtual void SetDisplayName(const FilePath& name) OVERRIDE;
142 virtual std::string DebugString(bool verbose) const OVERRIDE; 153 virtual std::string DebugString(bool verbose) const OVERRIDE;
143 virtual void MockDownloadOpenForTesting() OVERRIDE; 154 virtual void MockDownloadOpenForTesting() OVERRIDE;
144 155
145 // All remaining public interfaces virtual to allow for DownloadItemImpl 156 // All remaining public interfaces virtual to allow for DownloadItemImpl
146 // mocks. 157 // mocks.
147 158
148 // Main entry points for regular downloads, in order ------------------------- 159 virtual ResumeMode GetResumeMode() const;
149 160
150 // TODO(rdsmith): Fold the process that uses these fully into 161 // State transition operations on regular downloads --------------------------
151 // DownloadItemImpl and pass callbacks to the delegate so that all of
152 // these other than Start() can be made private.
153 162
154 // Start the download 163 // Start the download.
155 virtual void Start(scoped_ptr<DownloadFile> download_file); 164 // |download_file| is the associated file on the storage medium.
165 // |req_handle| is the new request handle associated with the download.
166 virtual void Start(scoped_ptr<DownloadFile> download_file,
167 scoped_ptr<DownloadRequestHandleInterface> req_handle);
156 168
157 // Needed because of interwining with DownloadManagerImpl -------------------- 169 // Needed because of intertwining with DownloadManagerImpl -------------------
158 170
159 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, 171 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl,
160 // removing these from the public interface. 172 // removing these from the public interface.
161 173
162 // Notify observers that this item is being removed by the user. 174 // Notify observers that this item is being removed by the user.
163 virtual void NotifyRemoved(); 175 virtual void NotifyRemoved();
164 176
165 virtual void OnDownloadedFileRemoved(); 177 virtual void OnDownloadedFileRemoved();
166 178
167 // Provide a weak pointer reference to a DownloadDestinationObserver 179 // Provide a weak pointer reference to a DownloadDestinationObserver
168 // for use by download destinations. 180 // for use by download destinations.
169 base::WeakPtr<DownloadDestinationObserver> DestinationObserverAsWeakPtr(); 181 virtual base::WeakPtr<DownloadDestinationObserver>
182 DestinationObserverAsWeakPtr();
170 183
171 // For dispatching on whether we're dealing with a SavePackage download. 184 // Get the download's BoundNetLog.
185 virtual const net::BoundNetLog& GetBoundNetLog() const;
172 186
173 // DownloadItemImpl routines only needed by SavePackage ---------------------- 187 // DownloadItemImpl routines only needed by SavePackage ----------------------
174 188
175 // Called by SavePackage to set the total number of bytes on the item. 189 // Called by SavePackage to set the total number of bytes on the item.
176 virtual void SetTotalBytes(int64 total_bytes); 190 virtual void SetTotalBytes(int64 total_bytes);
177 191
178 // Indicate progress in saving data to its destination. 192 // Indicate progress in saving data to its destination.
179 // |bytes_so_far| is the number of bytes received so far. 193 // |bytes_so_far| is the number of bytes received so far.
180 // |hash_state| is the current hash state. 194 // |hash_state| is the current hash state.
181 virtual void UpdateProgress(int64 bytes_so_far, 195 virtual void UpdateProgress(int64 bytes_so_far,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 bool IsDownloadReadyForCompletion(); 306 bool IsDownloadReadyForCompletion();
293 307
294 // Call to transition state; all state transitions should go through this. 308 // Call to transition state; all state transitions should go through this.
295 void TransitionTo(DownloadInternalState new_state); 309 void TransitionTo(DownloadInternalState new_state);
296 310
297 // Set the |danger_type_| and invoke obserers if necessary. 311 // Set the |danger_type_| and invoke obserers if necessary.
298 void SetDangerType(DownloadDangerType danger_type); 312 void SetDangerType(DownloadDangerType danger_type);
299 313
300 void SetFullPath(const FilePath& new_path); 314 void SetFullPath(const FilePath& new_path);
301 315
302 // Mapping between internal and external states. 316 void AutoResumeIfValid();
317
303 static DownloadState InternalToExternalState( 318 static DownloadState InternalToExternalState(
304 DownloadInternalState internal_state); 319 DownloadInternalState internal_state);
305 static DownloadInternalState ExternalToInternalState( 320 static DownloadInternalState ExternalToInternalState(
306 DownloadState external_state); 321 DownloadState external_state);
307 322
308 // Debugging routines -------------------------------------------------------- 323 // Debugging routines --------------------------------------------------------
309 static const char* DebugDownloadStateString(DownloadInternalState state); 324 static const char* DebugDownloadStateString(DownloadInternalState state);
325 static const char* DebugResumeModeString(ResumeMode mode);
310 326
311 // Will be false for save package downloads retrieved from the history. 327 // Will be false for save package downloads retrieved from the history.
312 // TODO(rdsmith): Replace with a generalized enum for "download source". 328 // TODO(rdsmith): Replace with a generalized enum for "download source".
313 const bool is_save_package_download_; 329 const bool is_save_package_download_;
314 330
315 // The handle to the request information. Used for operations outside the 331 // The handle to the request information. Used for operations outside the
316 // download system. 332 // download system.
317 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 333 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
318 334
319 // Download ID assigned by DownloadResourceHandler. 335 // Download ID assigned by DownloadResourceHandler.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 434
419 // Time the download completed. 435 // Time the download completed.
420 base::Time end_time_; 436 base::Time end_time_;
421 437
422 // Our delegate. 438 // Our delegate.
423 DownloadItemImplDelegate* delegate_; 439 DownloadItemImplDelegate* delegate_;
424 440
425 // In progress downloads may be paused by the user, we note it here. 441 // In progress downloads may be paused by the user, we note it here.
426 bool is_paused_; 442 bool is_paused_;
427 443
444 // The number of times this download has been resumed automatically.
445 int auto_resume_count_;
446
428 // A flag for indicating if the download should be opened at completion. 447 // A flag for indicating if the download should be opened at completion.
429 bool open_when_complete_; 448 bool open_when_complete_;
430 449
431 // A flag for indicating if the downloaded file is externally removed. 450 // A flag for indicating if the downloaded file is externally removed.
432 bool file_externally_removed_; 451 bool file_externally_removed_;
433 452
434 // Indicates if the download is considered potentially safe or dangerous 453 // Indicates if the download is considered potentially safe or dangerous
435 // (executable files are typically considered dangerous). 454 // (executable files are typically considered dangerous).
436 SafetyState safety_state_; 455 SafetyState safety_state_;
437 456
(...skipping 30 matching lines...) Expand all
468 const net::BoundNetLog bound_net_log_; 487 const net::BoundNetLog bound_net_log_;
469 488
470 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 489 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
471 490
472 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 491 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
473 }; 492 };
474 493
475 } // namespace content 494 } // namespace content
476 495
477 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 496 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698