| 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 OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; | 137 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) OVERRIDE; |
| 133 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 138 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 134 virtual void SetIsTemporary(bool temporary) OVERRIDE; | 139 virtual void SetIsTemporary(bool temporary) OVERRIDE; |
| 135 virtual void SetOpened(bool opened) OVERRIDE; | 140 virtual void SetOpened(bool opened) OVERRIDE; |
| 136 virtual void SetDisplayName(const FilePath& name) OVERRIDE; | 141 virtual void SetDisplayName(const FilePath& name) OVERRIDE; |
| 137 virtual std::string DebugString(bool verbose) const OVERRIDE; | 142 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 138 virtual void MockDownloadOpenForTesting() OVERRIDE; | 143 virtual void MockDownloadOpenForTesting() OVERRIDE; |
| 139 | 144 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 virtual void UpdateProgress(int64 bytes_so_far, | 186 virtual void UpdateProgress(int64 bytes_so_far, |
| 182 int64 bytes_per_sec, | 187 int64 bytes_per_sec, |
| 183 const std::string& hash_state); | 188 const std::string& hash_state); |
| 184 | 189 |
| 185 virtual void OnAllDataSaved(const std::string& final_hash); | 190 virtual void OnAllDataSaved(const std::string& final_hash); |
| 186 | 191 |
| 187 // Called by SavePackage to display progress when the DownloadItem | 192 // Called by SavePackage to display progress when the DownloadItem |
| 188 // should be considered complete. | 193 // should be considered complete. |
| 189 virtual void MarkAsComplete(); | 194 virtual void MarkAsComplete(); |
| 190 | 195 |
| 191 // Interactions with persistence system -------------------------------------- | |
| 192 | |
| 193 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. | |
| 194 virtual void SetIsPersisted(); | |
| 195 virtual void SetDbHandle(int64 handle); | |
| 196 | |
| 197 private: | 196 private: |
| 198 // Fine grained states of a download. | 197 // Fine grained states of a download. |
| 199 enum DownloadInternalState { | 198 enum DownloadInternalState { |
| 200 // Unless otherwise specified, state transitions are linear forward | 199 // Unless otherwise specified, state transitions are linear forward |
| 201 // in this list. | 200 // in this list. |
| 202 | 201 |
| 203 // Includes both before and after file name determination. | 202 // Includes both before and after file name determination. |
| 204 // TODO(rdsmith): Put in state variable for file name determination. | 203 // TODO(rdsmith): Put in state variable for file name determination. |
| 205 IN_PROGRESS_INTERNAL, | 204 IN_PROGRESS_INTERNAL, |
| 206 | 205 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 412 |
| 414 // The views of this item in the download shelf and download contents. | 413 // The views of this item in the download shelf and download contents. |
| 415 ObserverList<Observer> observers_; | 414 ObserverList<Observer> observers_; |
| 416 | 415 |
| 417 // Time the download was started. | 416 // Time the download was started. |
| 418 base::Time start_time_; | 417 base::Time start_time_; |
| 419 | 418 |
| 420 // Time the download completed. | 419 // Time the download completed. |
| 421 base::Time end_time_; | 420 base::Time end_time_; |
| 422 | 421 |
| 423 // Our persistent store handle. | |
| 424 int64 db_handle_; | |
| 425 | |
| 426 // Our delegate. | 422 // Our delegate. |
| 427 DownloadItemImplDelegate* delegate_; | 423 DownloadItemImplDelegate* delegate_; |
| 428 | 424 |
| 429 // In progress downloads may be paused by the user, we note it here. | 425 // In progress downloads may be paused by the user, we note it here. |
| 430 bool is_paused_; | 426 bool is_paused_; |
| 431 | 427 |
| 432 // A flag for indicating if the download should be opened at completion. | 428 // A flag for indicating if the download should be opened at completion. |
| 433 bool open_when_complete_; | 429 bool open_when_complete_; |
| 434 | 430 |
| 435 // A flag for indicating if the downloaded file is externally removed. | 431 // A flag for indicating if the downloaded file is externally removed. |
| 436 bool file_externally_removed_; | 432 bool file_externally_removed_; |
| 437 | 433 |
| 438 // Indicates if the download is considered potentially safe or dangerous | 434 // Indicates if the download is considered potentially safe or dangerous |
| 439 // (executable files are typically considered dangerous). | 435 // (executable files are typically considered dangerous). |
| 440 SafetyState safety_state_; | 436 SafetyState safety_state_; |
| 441 | 437 |
| 442 // True if the download was auto-opened. We set this rather than using | 438 // True if the download was auto-opened. We set this rather than using |
| 443 // an observer as it's frequently possible for the download to be auto opened | 439 // an observer as it's frequently possible for the download to be auto opened |
| 444 // before the observer is added. | 440 // before the observer is added. |
| 445 bool auto_opened_; | 441 bool auto_opened_; |
| 446 | 442 |
| 447 bool is_persisted_; | |
| 448 | |
| 449 // True if the item was downloaded temporarily. | 443 // True if the item was downloaded temporarily. |
| 450 bool is_temporary_; | 444 bool is_temporary_; |
| 451 | 445 |
| 452 // True if we've saved all the data for the download. | 446 // True if we've saved all the data for the download. |
| 453 bool all_data_saved_; | 447 bool all_data_saved_; |
| 454 | 448 |
| 455 // Did the user open the item either directly or indirectly (such as by | 449 // Did the user open the item either directly or indirectly (such as by |
| 456 // setting always open files of this type)? The shelf also sets this field | 450 // setting always open files of this type)? The shelf also sets this field |
| 457 // when the user closes the shelf before the item has been opened but should | 451 // when the user closes the shelf before the item has been opened but should |
| 458 // be treated as though the user opened it. | 452 // be treated as though the user opened it. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 474 const net::BoundNetLog bound_net_log_; | 468 const net::BoundNetLog bound_net_log_; |
| 475 | 469 |
| 476 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 470 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 477 | 471 |
| 478 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 472 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 479 }; | 473 }; |
| 480 | 474 |
| 481 } // namespace content | 475 } // namespace content |
| 482 | 476 |
| 483 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 477 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |