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

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

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed content unit tests. Created 8 years, 2 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
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 10 matching lines...) Expand all
21 #include "content/public/browser/download_item.h" 21 #include "content/public/browser/download_item.h"
22 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
25 25
26 class DownloadItemImplDelegate; 26 class DownloadItemImplDelegate;
27 27
28 // See download_item.h for usage. 28 // See download_item.h for usage.
29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { 29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem {
30 public: 30 public:
31 // The maximum number of attempts we will make to resume automatically.
32 static const int kMaxAutoResumeAttempts;
33
31 // Note that it is the responsibility of the caller to ensure that a 34 // Note that it is the responsibility of the caller to ensure that a
32 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor 35 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor
33 // outlives the DownloadItemImpl. 36 // outlives the DownloadItemImpl.
34 37
35 // Constructing from persistent store: 38 // Constructing from persistent store:
36 // |bound_net_log| is constructed externally for our use. 39 // |bound_net_log| is constructed externally for our use.
37 DownloadItemImpl(DownloadItemImplDelegate* delegate, 40 DownloadItemImpl(DownloadItemImplDelegate* delegate,
38 content::DownloadId download_id, 41 content::DownloadId download_id,
39 const content::DownloadPersistentStoreInfo& info, 42 const content::DownloadPersistentStoreInfo& info,
40 const net::BoundNetLog& bound_net_log); 43 const net::BoundNetLog& bound_net_log);
41 44
42 // Constructing for a regular download. 45 // Constructing for a regular download.
43 // |bound_net_log| is constructed externally for our use. 46 // |bound_net_log| is constructed externally for our use.
44 DownloadItemImpl(DownloadItemImplDelegate* delegate, 47 DownloadItemImpl(DownloadItemImplDelegate* delegate,
45 const DownloadCreateInfo& info, 48 const DownloadCreateInfo& info,
46 scoped_ptr<DownloadRequestHandleInterface> request_handle,
Randy Smith (Not in Mondays) 2012/10/15 00:36:08 Why? (This question applies to DownloadItemFactor
47 const net::BoundNetLog& bound_net_log); 49 const net::BoundNetLog& bound_net_log);
48 50
49 // Constructing for the "Save Page As..." feature: 51 // Constructing for the "Save Page As..." feature:
50 // |bound_net_log| is constructed externally for our use. 52 // |bound_net_log| is constructed externally for our use.
51 DownloadItemImpl(DownloadItemImplDelegate* delegate, 53 DownloadItemImpl(DownloadItemImplDelegate* delegate,
52 const FilePath& path, 54 const FilePath& path,
53 const GURL& url, 55 const GURL& url,
54 content::DownloadId download_id, 56 content::DownloadId download_id,
55 const std::string& mime_type, 57 const std::string& mime_type,
56 const net::BoundNetLog& bound_net_log); 58 const net::BoundNetLog& bound_net_log);
(...skipping 10 matching lines...) Expand all
67 virtual void Delete(DeleteReason reason) OVERRIDE; 69 virtual void Delete(DeleteReason reason) OVERRIDE;
68 virtual void Remove() OVERRIDE; 70 virtual void Remove() OVERRIDE;
69 virtual void OpenDownload() OVERRIDE; 71 virtual void OpenDownload() OVERRIDE;
70 virtual void ShowDownloadInShell() OVERRIDE; 72 virtual void ShowDownloadInShell() OVERRIDE;
71 virtual int32 GetId() const OVERRIDE; 73 virtual int32 GetId() const OVERRIDE;
72 virtual content::DownloadId GetGlobalId() const OVERRIDE; 74 virtual content::DownloadId GetGlobalId() const OVERRIDE;
73 virtual int64 GetDbHandle() const OVERRIDE; 75 virtual int64 GetDbHandle() const OVERRIDE;
74 virtual DownloadState GetState() const OVERRIDE; 76 virtual DownloadState GetState() const OVERRIDE;
75 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; 77 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE;
76 virtual bool IsPaused() const OVERRIDE; 78 virtual bool IsPaused() const OVERRIDE;
79 virtual ResumeMode CanResumeInterrupted() const OVERRIDE;
77 virtual bool IsTemporary() const OVERRIDE; 80 virtual bool IsTemporary() const OVERRIDE;
78 virtual bool IsPersisted() const OVERRIDE; 81 virtual bool IsPersisted() const OVERRIDE;
79 virtual bool IsPartialDownload() const OVERRIDE; 82 virtual bool IsPartialDownload() const OVERRIDE;
80 virtual bool IsInProgress() const OVERRIDE; 83 virtual bool IsInProgress() const OVERRIDE;
81 virtual bool IsCancelled() const OVERRIDE; 84 virtual bool IsCancelled() const OVERRIDE;
82 virtual bool IsInterrupted() const OVERRIDE; 85 virtual bool IsInterrupted() const OVERRIDE;
83 virtual bool IsComplete() const OVERRIDE; 86 virtual bool IsComplete() const OVERRIDE;
84 virtual const GURL& GetURL() const OVERRIDE; 87 virtual const GURL& GetURL() const OVERRIDE;
85 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; 88 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE;
86 virtual const GURL& GetOriginalUrl() const OVERRIDE; 89 virtual const GURL& GetOriginalUrl() const OVERRIDE;
(...skipping 23 matching lines...) Expand all
110 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; 113 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE;
111 virtual int64 CurrentSpeed() const OVERRIDE; 114 virtual int64 CurrentSpeed() const OVERRIDE;
112 virtual int PercentComplete() const OVERRIDE; 115 virtual int PercentComplete() const OVERRIDE;
113 virtual bool AllDataSaved() const OVERRIDE; 116 virtual bool AllDataSaved() const OVERRIDE;
114 virtual int64 GetTotalBytes() const OVERRIDE; 117 virtual int64 GetTotalBytes() const OVERRIDE;
115 virtual int64 GetReceivedBytes() const OVERRIDE; 118 virtual int64 GetReceivedBytes() const OVERRIDE;
116 virtual base::Time GetStartTime() const OVERRIDE; 119 virtual base::Time GetStartTime() const OVERRIDE;
117 virtual base::Time GetEndTime() const OVERRIDE; 120 virtual base::Time GetEndTime() const OVERRIDE;
118 virtual bool CanShowInFolder() OVERRIDE; 121 virtual bool CanShowInFolder() OVERRIDE;
119 virtual bool CanOpenDownload() OVERRIDE; 122 virtual bool CanOpenDownload() OVERRIDE;
123 virtual bool CanResumeDownload() const OVERRIDE;
120 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 124 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
121 virtual bool GetOpenWhenComplete() const OVERRIDE; 125 virtual bool GetOpenWhenComplete() const OVERRIDE;
122 virtual bool GetAutoOpened() OVERRIDE; 126 virtual bool GetAutoOpened() OVERRIDE;
123 virtual bool GetOpened() const OVERRIDE; 127 virtual bool GetOpened() const OVERRIDE;
124 virtual content::DownloadPersistentStoreInfo 128 virtual content::DownloadPersistentStoreInfo
125 GetPersistentStoreInfo() const OVERRIDE; 129 GetPersistentStoreInfo() const OVERRIDE;
126 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; 130 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
127 virtual content::WebContents* GetWebContents() const OVERRIDE; 131 virtual content::WebContents* GetWebContents() const OVERRIDE;
128 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; 132 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE;
129 virtual void OnContentCheckCompleted( 133 virtual void OnContentCheckCompleted(
130 content::DownloadDangerType danger_type) OVERRIDE; 134 content::DownloadDangerType danger_type) OVERRIDE;
131 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 135 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
132 virtual void SetIsTemporary(bool temporary) OVERRIDE; 136 virtual void SetIsTemporary(bool temporary) OVERRIDE;
133 virtual void SetOpened(bool opened) OVERRIDE; 137 virtual void SetOpened(bool opened) OVERRIDE;
134 virtual void SetDisplayName(const FilePath& name) OVERRIDE; 138 virtual void SetDisplayName(const FilePath& name) OVERRIDE;
135 virtual std::string DebugString(bool verbose) const OVERRIDE; 139 virtual std::string DebugString(bool verbose) const OVERRIDE;
136 virtual void MockDownloadOpenForTesting() OVERRIDE; 140 virtual void MockDownloadOpenForTesting() OVERRIDE;
141 virtual const net::BoundNetLog& GetBoundNetLog() const OVERRIDE;
142
143 void SetRequest(scoped_ptr<DownloadRequestHandleInterface> request_handle);
144 bool IsResuming() const;
Randy Smith (Not in Mondays) 2012/10/15 00:36:08 This (including the underlying state variable) doe
137 145
138 // All remaining public interfaces virtual to allow for DownloadItemImpl 146 // All remaining public interfaces virtual to allow for DownloadItemImpl
139 // mocks. 147 // mocks.
140 148
141 // Main entry points for regular downloads, in order ------------------------- 149 // Main entry points for regular downloads, in order -------------------------
142 150
143 // TODO(rdsmith): Fold the process that uses these fully into 151 // TODO(rdsmith): Fold the process that uses these fully into
144 // DownloadItemImpl and pass callbacks to the delegate so that all of 152 // DownloadItemImpl and pass callbacks to the delegate so that all of
145 // these can be made private 153 // these can be made private
146 154
(...skipping 25 matching lines...) Expand all
172 180
173 // Cancels the off-thread aspects of the download (such as 181 // Cancels the off-thread aspects of the download (such as
174 // the corresponding URLRequest). 182 // the corresponding URLRequest).
175 // TODO(rdsmith): This should be private and only called from 183 // TODO(rdsmith): This should be private and only called from
176 // DownloadItem::Cancel/Interrupt; it isn't now because we can't 184 // DownloadItem::Cancel/Interrupt; it isn't now because we can't
177 // call those functions from 185 // call those functions from
178 // DownloadManager::FileSelectionCancelled() without doing some 186 // DownloadManager::FileSelectionCancelled() without doing some
179 // rewrites of the DownloadManager queues. 187 // rewrites of the DownloadManager queues.
180 virtual void OffThreadCancel(); 188 virtual void OffThreadCancel();
181 189
190 // Completes the off-thread aspects of the download interruption.
191 virtual void OffThreadInterrupt();
192
182 // Indicate that an error has occurred on the download. 193 // Indicate that an error has occurred on the download.
183 virtual void Interrupt(content::DownloadInterruptReason reason); 194 virtual void Interrupt(content::DownloadInterruptReason reason);
184 195
196 // User has resumed a download after an interruption.
197 // |req_handle| is the new request handle associated with the download.
198 virtual void Resume(scoped_ptr<DownloadRequestHandleInterface> req_handle);
199
185 // DownloadItemImpl routines only needed by SavePackage ---------------------- 200 // DownloadItemImpl routines only needed by SavePackage ----------------------
186 201
187 // Called by SavePackage to set the total number of bytes on the item. 202 // Called by SavePackage to set the total number of bytes on the item.
188 virtual void SetTotalBytes(int64 total_bytes); 203 virtual void SetTotalBytes(int64 total_bytes);
189 204
190 // Indicate progress in saving data to its destination. 205 // Indicate progress in saving data to its destination.
191 // |bytes_so_far| is the number of bytes received so far. 206 // |bytes_so_far| is the number of bytes received so far.
192 // |hash_state| is the current hash state. 207 // |hash_state| is the current hash state.
193 virtual void UpdateProgress(int64 bytes_so_far, 208 virtual void UpdateProgress(int64 bytes_so_far,
194 int64 bytes_per_sec, 209 int64 bytes_per_sec,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const std::string& final_hash); 294 const std::string& final_hash);
280 295
281 // Call to transition state; all state transitions should go through this. 296 // Call to transition state; all state transitions should go through this.
282 void TransitionTo(DownloadInternalState new_state); 297 void TransitionTo(DownloadInternalState new_state);
283 298
284 // Set the |danger_type_| and invoke obserers if necessary. 299 // Set the |danger_type_| and invoke obserers if necessary.
285 void SetDangerType(content::DownloadDangerType danger_type); 300 void SetDangerType(content::DownloadDangerType danger_type);
286 301
287 void SetFullPath(const FilePath& new_path); 302 void SetFullPath(const FilePath& new_path);
288 303
289 // Mapping between internal and external states. 304 void AutoResumeIfValid();
305
290 static DownloadState InternalToExternalState( 306 static DownloadState InternalToExternalState(
291 DownloadInternalState internal_state); 307 DownloadInternalState internal_state);
292 static DownloadInternalState ExternalToInternalState( 308 static DownloadInternalState ExternalToInternalState(
293 DownloadState external_state); 309 DownloadState external_state);
294 310
295 // Debugging routines -------------------------------------------------------- 311 // Debugging routines --------------------------------------------------------
296 static const char* DebugDownloadStateString(DownloadInternalState state); 312 static const char* DebugDownloadStateString(DownloadInternalState state);
313 static const char* DebugResumeModeString(DownloadItem::ResumeMode mode);
297 314
298 // The handle to the request information. Used for operations outside the 315 // The handle to the request information. Used for operations outside the
299 // download system. 316 // download system.
300 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 317 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
301 318
302 // Download ID assigned by DownloadResourceHandler. 319 // Download ID assigned by DownloadResourceHandler.
303 content::DownloadId download_id_; 320 content::DownloadId download_id_;
304 321
305 // Display name for the download. If this is empty, then the display name is 322 // Display name for the download. If this is empty, then the display name is
306 // considered to be |target_path_.BaseName()|. 323 // considered to be |target_path_.BaseName()|.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 425
409 // Our persistent store handle. 426 // Our persistent store handle.
410 int64 db_handle_; 427 int64 db_handle_;
411 428
412 // Our delegate. 429 // Our delegate.
413 DownloadItemImplDelegate* delegate_; 430 DownloadItemImplDelegate* delegate_;
414 431
415 // In progress downloads may be paused by the user, we note it here. 432 // In progress downloads may be paused by the user, we note it here.
416 bool is_paused_; 433 bool is_paused_;
417 434
435 // A download has been resumed.
436 bool is_resuming_;
437
438 // The number of times this download has been resumed automatically.
439 int auto_resume_count_;
440
418 // A flag for indicating if the download should be opened at completion. 441 // A flag for indicating if the download should be opened at completion.
419 bool open_when_complete_; 442 bool open_when_complete_;
420 443
421 // A flag for indicating if the downloaded file is externally removed. 444 // A flag for indicating if the downloaded file is externally removed.
422 bool file_externally_removed_; 445 bool file_externally_removed_;
423 446
424 // Indicates if the download is considered potentially safe or dangerous 447 // Indicates if the download is considered potentially safe or dangerous
425 // (executable files are typically considered dangerous). 448 // (executable files are typically considered dangerous).
426 SafetyState safety_state_; 449 SafetyState safety_state_;
427 450
428 // True if the download was auto-opened. We set this rather than using 451 // True if the download was auto-opened. We set this rather than using
429 // an observer as it's frequently possible for the download to be auto opened 452 // an observer as it's frequently possible for the download to be auto opened
430 // before the observer is added. 453 // before the observer is added.
431 bool auto_opened_; 454 bool auto_opened_;
432 455
456 // The download has been added to the history DB.
433 bool is_persisted_; 457 bool is_persisted_;
434 458
435 // True if the item was downloaded temporarily. 459 // True if the item was downloaded temporarily.
436 bool is_temporary_; 460 bool is_temporary_;
437 461
438 // True if we've saved all the data for the download. 462 // True if we've saved all the data for the download.
439 bool all_data_saved_; 463 bool all_data_saved_;
440 464
441 // Did the user open the item either directly or indirectly (such as by 465 // Did the user open the item either directly or indirectly (such as by
442 // setting always open files of this type)? The shelf also sets this field 466 // setting always open files of this type)? The shelf also sets this field
443 // when the user closes the shelf before the item has been opened but should 467 // when the user closes the shelf before the item has been opened but should
444 // be treated as though the user opened it. 468 // be treated as though the user opened it.
445 bool opened_; 469 bool opened_;
446 470
447 // Do we actually open downloads when requested? For testing purposes only. 471 // Do we actually open downloads when requested? For testing purposes only.
448 bool open_enabled_; 472 bool open_enabled_;
449 473
450 // Did the delegate delay calling Complete on this download? 474 // Did the delegate delay calling Complete on this download?
451 bool delegate_delayed_complete_; 475 bool delegate_delayed_complete_;
452 476
453 // Net log to use for this download. 477 // Net log to use for this download.
454 const net::BoundNetLog bound_net_log_; 478 const net::BoundNetLog bound_net_log_;
455 479
456 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 480 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
457 481
458 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 482 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
459 }; 483 };
460 484
461 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 485 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698