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

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: Ready for review. 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;
100 virtual bool CanResumeInterrupted() const OVERRIDE;
89 virtual bool IsTemporary() const OVERRIDE; 101 virtual bool IsTemporary() const OVERRIDE;
90 virtual bool IsPartialDownload() const OVERRIDE; 102 virtual bool IsPartialDownload() const OVERRIDE;
91 virtual bool IsInProgress() const OVERRIDE; 103 virtual bool IsInProgress() const OVERRIDE;
92 virtual bool IsCancelled() const OVERRIDE; 104 virtual bool IsCancelled() const OVERRIDE;
93 virtual bool IsInterrupted() const OVERRIDE; 105 virtual bool IsInterrupted() const OVERRIDE;
94 virtual bool IsComplete() const OVERRIDE; 106 virtual bool IsComplete() const OVERRIDE;
95 virtual const GURL& GetURL() const OVERRIDE; 107 virtual const GURL& GetURL() const OVERRIDE;
96 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; 108 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE;
97 virtual const GURL& GetOriginalUrl() const OVERRIDE; 109 virtual const GURL& GetOriginalUrl() const OVERRIDE;
98 virtual const GURL& GetReferrerUrl() const OVERRIDE; 110 virtual const GURL& GetReferrerUrl() const OVERRIDE;
(...skipping 22 matching lines...) Expand all
121 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 133 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
122 virtual int64 CurrentSpeed() const OVERRIDE; 134 virtual int64 CurrentSpeed() const OVERRIDE;
123 virtual int PercentComplete() const OVERRIDE; 135 virtual int PercentComplete() const OVERRIDE;
124 virtual bool AllDataSaved() const OVERRIDE; 136 virtual bool AllDataSaved() const OVERRIDE;
125 virtual int64 GetTotalBytes() const OVERRIDE; 137 virtual int64 GetTotalBytes() const OVERRIDE;
126 virtual int64 GetReceivedBytes() const OVERRIDE; 138 virtual int64 GetReceivedBytes() const OVERRIDE;
127 virtual base::Time GetStartTime() const OVERRIDE; 139 virtual base::Time GetStartTime() const OVERRIDE;
128 virtual base::Time GetEndTime() const OVERRIDE; 140 virtual base::Time GetEndTime() const OVERRIDE;
129 virtual bool CanShowInFolder() OVERRIDE; 141 virtual bool CanShowInFolder() OVERRIDE;
130 virtual bool CanOpenDownload() OVERRIDE; 142 virtual bool CanOpenDownload() OVERRIDE;
143 virtual bool CanResumeDownload() const OVERRIDE;
131 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 144 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
132 virtual bool GetOpenWhenComplete() const OVERRIDE; 145 virtual bool GetOpenWhenComplete() const OVERRIDE;
133 virtual bool GetAutoOpened() OVERRIDE; 146 virtual bool GetAutoOpened() OVERRIDE;
134 virtual bool GetOpened() const OVERRIDE; 147 virtual bool GetOpened() const OVERRIDE;
135 virtual BrowserContext* GetBrowserContext() const OVERRIDE; 148 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
136 virtual WebContents* GetWebContents() const OVERRIDE; 149 virtual WebContents* GetWebContents() const OVERRIDE;
137 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; 150 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE;
138 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 151 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
139 virtual void SetIsTemporary(bool temporary) OVERRIDE; 152 virtual void SetIsTemporary(bool temporary) OVERRIDE;
140 virtual void SetOpened(bool opened) OVERRIDE; 153 virtual void SetOpened(bool opened) OVERRIDE;
141 virtual void SetDisplayName(const FilePath& name) OVERRIDE; 154 virtual void SetDisplayName(const FilePath& name) OVERRIDE;
142 virtual std::string DebugString(bool verbose) const OVERRIDE; 155 virtual std::string DebugString(bool verbose) const OVERRIDE;
143 virtual void MockDownloadOpenForTesting() OVERRIDE; 156 virtual void MockDownloadOpenForTesting() OVERRIDE;
144 157
145 // All remaining public interfaces virtual to allow for DownloadItemImpl 158 // All remaining public interfaces virtual to allow for DownloadItemImpl
146 // mocks. 159 // mocks.
147 160
148 // Main entry points for regular downloads, in order ------------------------- 161 virtual ResumeMode GetResumeMode() const;
149 162
150 // TODO(rdsmith): Fold the process that uses these fully into 163 // 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 164
154 // Start the download 165 // Start the download.
155 virtual void Start(scoped_ptr<DownloadFile> download_file); 166 // |download_file| is the associated file on the storage medium.
167 // |req_handle| is the new request handle associated with the download.
168 virtual void Start(scoped_ptr<DownloadFile> download_file,
169 scoped_ptr<DownloadRequestHandleInterface> req_handle);
156 170
157 // Needed because of interwining with DownloadManagerImpl -------------------- 171 // Needed because of intertwining with DownloadManagerImpl -------------------
158 172
159 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, 173 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl,
160 // removing these from the public interface. 174 // removing these from the public interface.
161 175
162 // Notify observers that this item is being removed by the user. 176 // Notify observers that this item is being removed by the user.
163 virtual void NotifyRemoved(); 177 virtual void NotifyRemoved();
164 178
165 virtual void OnDownloadedFileRemoved(); 179 virtual void OnDownloadedFileRemoved();
166 180
167 // Provide a weak pointer reference to a DownloadDestinationObserver 181 // Provide a weak pointer reference to a DownloadDestinationObserver
168 // for use by download destinations. 182 // for use by download destinations.
169 base::WeakPtr<DownloadDestinationObserver> DestinationObserverAsWeakPtr(); 183 virtual base::WeakPtr<DownloadDestinationObserver>
184 DestinationObserverAsWeakPtr();
170 185
171 // For dispatching on whether we're dealing with a SavePackage download. 186 // Get the download's BoundNetLog.
187 virtual const net::BoundNetLog& GetBoundNetLog() const;
172 188
173 // DownloadItemImpl routines only needed by SavePackage ---------------------- 189 // DownloadItemImpl routines only needed by SavePackage ----------------------
174 190
175 // Called by SavePackage to set the total number of bytes on the item. 191 // Called by SavePackage to set the total number of bytes on the item.
176 virtual void SetTotalBytes(int64 total_bytes); 192 virtual void SetTotalBytes(int64 total_bytes);
177 193
178 // Indicate progress in saving data to its destination. 194 // Indicate progress in saving data to its destination.
179 // |bytes_so_far| is the number of bytes received so far. 195 // |bytes_so_far| is the number of bytes received so far.
180 // |hash_state| is the current hash state. 196 // |hash_state| is the current hash state.
181 virtual void UpdateProgress(int64 bytes_so_far, 197 virtual void UpdateProgress(int64 bytes_so_far,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 bool IsDownloadReadyForCompletion(); 308 bool IsDownloadReadyForCompletion();
293 309
294 // Call to transition state; all state transitions should go through this. 310 // Call to transition state; all state transitions should go through this.
295 void TransitionTo(DownloadInternalState new_state); 311 void TransitionTo(DownloadInternalState new_state);
296 312
297 // Set the |danger_type_| and invoke obserers if necessary. 313 // Set the |danger_type_| and invoke obserers if necessary.
298 void SetDangerType(DownloadDangerType danger_type); 314 void SetDangerType(DownloadDangerType danger_type);
299 315
300 void SetFullPath(const FilePath& new_path); 316 void SetFullPath(const FilePath& new_path);
301 317
302 // Mapping between internal and external states. 318 void AutoResumeIfValid();
319
303 static DownloadState InternalToExternalState( 320 static DownloadState InternalToExternalState(
304 DownloadInternalState internal_state); 321 DownloadInternalState internal_state);
305 static DownloadInternalState ExternalToInternalState( 322 static DownloadInternalState ExternalToInternalState(
306 DownloadState external_state); 323 DownloadState external_state);
307 324
308 // Debugging routines -------------------------------------------------------- 325 // Debugging routines --------------------------------------------------------
309 static const char* DebugDownloadStateString(DownloadInternalState state); 326 static const char* DebugDownloadStateString(DownloadInternalState state);
327 static const char* DebugResumeModeString(ResumeMode mode);
310 328
311 // Will be false for save package downloads retrieved from the history. 329 // Will be false for save package downloads retrieved from the history.
312 // TODO(rdsmith): Replace with a generalized enum for "download source". 330 // TODO(rdsmith): Replace with a generalized enum for "download source".
313 const bool is_save_package_download_; 331 const bool is_save_package_download_;
314 332
315 // The handle to the request information. Used for operations outside the 333 // The handle to the request information. Used for operations outside the
316 // download system. 334 // download system.
317 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 335 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
318 336
319 // Download ID assigned by DownloadResourceHandler. 337 // Download ID assigned by DownloadResourceHandler.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 436
419 // Time the download completed. 437 // Time the download completed.
420 base::Time end_time_; 438 base::Time end_time_;
421 439
422 // Our delegate. 440 // Our delegate.
423 DownloadItemImplDelegate* delegate_; 441 DownloadItemImplDelegate* delegate_;
424 442
425 // In progress downloads may be paused by the user, we note it here. 443 // In progress downloads may be paused by the user, we note it here.
426 bool is_paused_; 444 bool is_paused_;
427 445
446 // The number of times this download has been resumed automatically.
447 int auto_resume_count_;
448
428 // A flag for indicating if the download should be opened at completion. 449 // A flag for indicating if the download should be opened at completion.
429 bool open_when_complete_; 450 bool open_when_complete_;
430 451
431 // A flag for indicating if the downloaded file is externally removed. 452 // A flag for indicating if the downloaded file is externally removed.
432 bool file_externally_removed_; 453 bool file_externally_removed_;
433 454
434 // Indicates if the download is considered potentially safe or dangerous 455 // Indicates if the download is considered potentially safe or dangerous
435 // (executable files are typically considered dangerous). 456 // (executable files are typically considered dangerous).
436 SafetyState safety_state_; 457 SafetyState safety_state_;
437 458
(...skipping 30 matching lines...) Expand all
468 const net::BoundNetLog bound_net_log_; 489 const net::BoundNetLog bound_net_log_;
469 490
470 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 491 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
471 492
472 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 493 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
473 }; 494 };
474 495
475 } // namespace content 496 } // namespace content
476 497
477 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 498 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698