| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 public DownloadDestinationObserver { | 34 public DownloadDestinationObserver { |
| 35 public: | 35 public: |
| 36 // Note that it is the responsibility of the caller to ensure that a | 36 // Note that it is the responsibility of the caller to ensure that a |
| 37 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor | 37 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor |
| 38 // outlives the DownloadItemImpl. | 38 // outlives the DownloadItemImpl. |
| 39 | 39 |
| 40 // Constructing from persistent store: | 40 // Constructing from persistent store: |
| 41 // |bound_net_log| is constructed externally for our use. | 41 // |bound_net_log| is constructed externally for our use. |
| 42 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 42 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 43 DownloadId download_id, | 43 DownloadId download_id, |
| 44 const DownloadPersistentStoreInfo& info, | 44 const FilePath& path, |
| 45 const GURL& url, |
| 46 const GURL& referrer_url, |
| 47 const base::Time& start_time, |
| 48 const base::Time& end_time, |
| 49 int64 received_bytes, |
| 50 int64 total_bytes, |
| 51 DownloadItem::DownloadState state, |
| 52 bool opened, |
| 45 const net::BoundNetLog& bound_net_log); | 53 const net::BoundNetLog& bound_net_log); |
| 46 | 54 |
| 47 // Constructing for a regular download. | 55 // Constructing for a regular download. |
| 48 // |bound_net_log| is constructed externally for our use. | 56 // |bound_net_log| is constructed externally for our use. |
| 49 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 57 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 50 const DownloadCreateInfo& info, | 58 const DownloadCreateInfo& info, |
| 51 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 59 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 52 const net::BoundNetLog& bound_net_log); | 60 const net::BoundNetLog& bound_net_log); |
| 53 | 61 |
| 54 // Constructing for the "Save Page As..." feature: | 62 // Constructing for the "Save Page As..." feature: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 virtual void UpdateObservers() OVERRIDE; | 76 virtual void UpdateObservers() OVERRIDE; |
| 69 virtual void DangerousDownloadValidated() OVERRIDE; | 77 virtual void DangerousDownloadValidated() OVERRIDE; |
| 70 virtual void TogglePause() OVERRIDE; | 78 virtual void TogglePause() OVERRIDE; |
| 71 virtual void Cancel(bool user_cancel) OVERRIDE; | 79 virtual void Cancel(bool user_cancel) OVERRIDE; |
| 72 virtual void Delete(DeleteReason reason) OVERRIDE; | 80 virtual void Delete(DeleteReason reason) OVERRIDE; |
| 73 virtual void Remove() OVERRIDE; | 81 virtual void Remove() OVERRIDE; |
| 74 virtual void OpenDownload() OVERRIDE; | 82 virtual void OpenDownload() OVERRIDE; |
| 75 virtual void ShowDownloadInShell() OVERRIDE; | 83 virtual void ShowDownloadInShell() OVERRIDE; |
| 76 virtual int32 GetId() const OVERRIDE; | 84 virtual int32 GetId() const OVERRIDE; |
| 77 virtual DownloadId GetGlobalId() const OVERRIDE; | 85 virtual DownloadId GetGlobalId() const OVERRIDE; |
| 78 virtual int64 GetDbHandle() const OVERRIDE; | |
| 79 virtual DownloadState GetState() const OVERRIDE; | 86 virtual DownloadState GetState() const OVERRIDE; |
| 80 virtual DownloadInterruptReason GetLastReason() const OVERRIDE; | 87 virtual DownloadInterruptReason GetLastReason() const OVERRIDE; |
| 81 virtual bool IsPaused() const OVERRIDE; | 88 virtual bool IsPaused() const OVERRIDE; |
| 82 virtual bool IsTemporary() const OVERRIDE; | 89 virtual bool IsTemporary() const OVERRIDE; |
| 83 virtual bool IsPersisted() const OVERRIDE; | |
| 84 virtual bool IsPartialDownload() const OVERRIDE; | 90 virtual bool IsPartialDownload() const OVERRIDE; |
| 85 virtual bool IsInProgress() const OVERRIDE; | 91 virtual bool IsInProgress() const OVERRIDE; |
| 86 virtual bool IsCancelled() const OVERRIDE; | 92 virtual bool IsCancelled() const OVERRIDE; |
| 87 virtual bool IsInterrupted() const OVERRIDE; | 93 virtual bool IsInterrupted() const OVERRIDE; |
| 88 virtual bool IsComplete() const OVERRIDE; | 94 virtual bool IsComplete() const OVERRIDE; |
| 89 virtual const GURL& GetURL() const OVERRIDE; | 95 virtual const GURL& GetURL() const OVERRIDE; |
| 90 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; | 96 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; |
| 91 virtual const GURL& GetOriginalUrl() const OVERRIDE; | 97 virtual const GURL& GetOriginalUrl() const OVERRIDE; |
| 92 virtual const GURL& GetReferrerUrl() const OVERRIDE; | 98 virtual const GURL& GetReferrerUrl() const OVERRIDE; |
| 93 virtual std::string GetSuggestedFilename() const OVERRIDE; | 99 virtual std::string GetSuggestedFilename() const OVERRIDE; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 119 virtual int64 GetTotalBytes() const OVERRIDE; | 125 virtual int64 GetTotalBytes() const OVERRIDE; |
| 120 virtual int64 GetReceivedBytes() const OVERRIDE; | 126 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 121 virtual base::Time GetStartTime() const OVERRIDE; | 127 virtual base::Time GetStartTime() const OVERRIDE; |
| 122 virtual base::Time GetEndTime() const OVERRIDE; | 128 virtual base::Time GetEndTime() const OVERRIDE; |
| 123 virtual bool CanShowInFolder() OVERRIDE; | 129 virtual bool CanShowInFolder() OVERRIDE; |
| 124 virtual bool CanOpenDownload() OVERRIDE; | 130 virtual bool CanOpenDownload() OVERRIDE; |
| 125 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 131 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 126 virtual bool GetOpenWhenComplete() const OVERRIDE; | 132 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 127 virtual bool GetAutoOpened() OVERRIDE; | 133 virtual bool GetAutoOpened() OVERRIDE; |
| 128 virtual bool GetOpened() const OVERRIDE; | 134 virtual bool GetOpened() const OVERRIDE; |
| 129 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; | |
| 130 virtual BrowserContext* GetBrowserContext() const OVERRIDE; | 135 virtual BrowserContext* GetBrowserContext() const OVERRIDE; |
| 131 virtual WebContents* GetWebContents() const OVERRIDE; | 136 virtual WebContents* GetWebContents() const OVERRIDE; |
| 132 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; | 137 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; |
| 133 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; | 138 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; |
| 134 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 139 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 135 virtual void SetIsTemporary(bool temporary) OVERRIDE; | 140 virtual void SetIsTemporary(bool temporary) OVERRIDE; |
| 136 virtual void SetOpened(bool opened) OVERRIDE; | 141 virtual void SetOpened(bool opened) OVERRIDE; |
| 137 virtual void SetDisplayName(const FilePath& name) OVERRIDE; | 142 virtual void SetDisplayName(const FilePath& name) OVERRIDE; |
| 138 virtual std::string DebugString(bool verbose) const OVERRIDE; | 143 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 139 virtual void MockDownloadOpenForTesting() OVERRIDE; | 144 virtual void MockDownloadOpenForTesting() OVERRIDE; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 virtual void UpdateProgress(int64 bytes_so_far, | 190 virtual void UpdateProgress(int64 bytes_so_far, |
| 186 int64 bytes_per_sec, | 191 int64 bytes_per_sec, |
| 187 const std::string& hash_state); | 192 const std::string& hash_state); |
| 188 | 193 |
| 189 virtual void OnAllDataSaved(const std::string& final_hash); | 194 virtual void OnAllDataSaved(const std::string& final_hash); |
| 190 | 195 |
| 191 // Called by SavePackage to display progress when the DownloadItem | 196 // Called by SavePackage to display progress when the DownloadItem |
| 192 // should be considered complete. | 197 // should be considered complete. |
| 193 virtual void MarkAsComplete(); | 198 virtual void MarkAsComplete(); |
| 194 | 199 |
| 195 // Interactions with persistence system -------------------------------------- | |
| 196 | |
| 197 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. | |
| 198 virtual void SetIsPersisted(); | |
| 199 virtual void SetDbHandle(int64 handle); | |
| 200 | |
| 201 private: | 200 private: |
| 202 // Fine grained states of a download. | 201 // Fine grained states of a download. |
| 203 enum DownloadInternalState { | 202 enum DownloadInternalState { |
| 204 // Unless otherwise specified, state transitions are linear forward | 203 // Unless otherwise specified, state transitions are linear forward |
| 205 // in this list. | 204 // in this list. |
| 206 | 205 |
| 207 // Includes both before and after file name determination. | 206 // Includes both before and after file name determination. |
| 208 // TODO(rdsmith): Put in state variable for file name determination. | 207 // TODO(rdsmith): Put in state variable for file name determination. |
| 209 IN_PROGRESS_INTERNAL, | 208 IN_PROGRESS_INTERNAL, |
| 210 | 209 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 419 |
| 421 // The views of this item in the download shelf and download contents. | 420 // The views of this item in the download shelf and download contents. |
| 422 ObserverList<Observer> observers_; | 421 ObserverList<Observer> observers_; |
| 423 | 422 |
| 424 // Time the download was started. | 423 // Time the download was started. |
| 425 base::Time start_time_; | 424 base::Time start_time_; |
| 426 | 425 |
| 427 // Time the download completed. | 426 // Time the download completed. |
| 428 base::Time end_time_; | 427 base::Time end_time_; |
| 429 | 428 |
| 430 // Our persistent store handle. | |
| 431 int64 db_handle_; | |
| 432 | |
| 433 // Our delegate. | 429 // Our delegate. |
| 434 DownloadItemImplDelegate* delegate_; | 430 DownloadItemImplDelegate* delegate_; |
| 435 | 431 |
| 436 // 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. |
| 437 bool is_paused_; | 433 bool is_paused_; |
| 438 | 434 |
| 439 // A flag for indicating if the download should be opened at completion. | 435 // A flag for indicating if the download should be opened at completion. |
| 440 bool open_when_complete_; | 436 bool open_when_complete_; |
| 441 | 437 |
| 442 // A flag for indicating if the downloaded file is externally removed. | 438 // A flag for indicating if the downloaded file is externally removed. |
| 443 bool file_externally_removed_; | 439 bool file_externally_removed_; |
| 444 | 440 |
| 445 // Indicates if the download is considered potentially safe or dangerous | 441 // Indicates if the download is considered potentially safe or dangerous |
| 446 // (executable files are typically considered dangerous). | 442 // (executable files are typically considered dangerous). |
| 447 SafetyState safety_state_; | 443 SafetyState safety_state_; |
| 448 | 444 |
| 449 // True if the download was auto-opened. We set this rather than using | 445 // True if the download was auto-opened. We set this rather than using |
| 450 // an observer as it's frequently possible for the download to be auto opened | 446 // an observer as it's frequently possible for the download to be auto opened |
| 451 // before the observer is added. | 447 // before the observer is added. |
| 452 bool auto_opened_; | 448 bool auto_opened_; |
| 453 | 449 |
| 454 bool is_persisted_; | |
| 455 | |
| 456 // True if the item was downloaded temporarily. | 450 // True if the item was downloaded temporarily. |
| 457 bool is_temporary_; | 451 bool is_temporary_; |
| 458 | 452 |
| 459 // True if we've saved all the data for the download. | 453 // True if we've saved all the data for the download. |
| 460 bool all_data_saved_; | 454 bool all_data_saved_; |
| 461 | 455 |
| 462 // Did the user open the item either directly or indirectly (such as by | 456 // Did the user open the item either directly or indirectly (such as by |
| 463 // setting always open files of this type)? The shelf also sets this field | 457 // setting always open files of this type)? The shelf also sets this field |
| 464 // when the user closes the shelf before the item has been opened but should | 458 // when the user closes the shelf before the item has been opened but should |
| 465 // be treated as though the user opened it. | 459 // be treated as though the user opened it. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 481 const net::BoundNetLog bound_net_log_; | 475 const net::BoundNetLog bound_net_log_; |
| 482 | 476 |
| 483 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 477 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 484 | 478 |
| 485 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 479 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 486 }; | 480 }; |
| 487 | 481 |
| 488 } // namespace content | 482 } // namespace content |
| 489 | 483 |
| 490 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 484 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |