| 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 18 matching lines...) Expand all Loading... |
| 29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { | 29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { |
| 30 public: | 30 public: |
| 31 // Note that it is the responsibility of the caller to ensure that a | 31 // Note that it is the responsibility of the caller to ensure that a |
| 32 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor | 32 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor |
| 33 // outlives the DownloadItemImpl. | 33 // outlives the DownloadItemImpl. |
| 34 | 34 |
| 35 // Constructing from persistent store: | 35 // Constructing from persistent store: |
| 36 // |bound_net_log| is constructed externally for our use. | 36 // |bound_net_log| is constructed externally for our use. |
| 37 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 37 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 38 content::DownloadId download_id, | 38 content::DownloadId download_id, |
| 39 const content::DownloadPersistentStoreInfo& info, | 39 const FilePath& path, |
| 40 const GURL& url, |
| 41 const GURL& referrer_url, |
| 42 const base::Time& start_time, |
| 43 const base::Time& end_time, |
| 44 int64 received_bytes, |
| 45 int64 total_bytes, |
| 46 DownloadItem::DownloadState state, |
| 47 bool opened, |
| 40 const net::BoundNetLog& bound_net_log); | 48 const net::BoundNetLog& bound_net_log); |
| 41 | 49 |
| 42 // Constructing for a regular download. | 50 // Constructing for a regular download. |
| 43 // |bound_net_log| is constructed externally for our use. | 51 // |bound_net_log| is constructed externally for our use. |
| 44 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 52 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 45 const DownloadCreateInfo& info, | 53 const DownloadCreateInfo& info, |
| 46 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 54 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 47 const net::BoundNetLog& bound_net_log); | 55 const net::BoundNetLog& bound_net_log); |
| 48 | 56 |
| 49 // Constructing for the "Save Page As..." feature: | 57 // Constructing for the "Save Page As..." feature: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 virtual void UpdateObservers() OVERRIDE; | 71 virtual void UpdateObservers() OVERRIDE; |
| 64 virtual void DangerousDownloadValidated() OVERRIDE; | 72 virtual void DangerousDownloadValidated() OVERRIDE; |
| 65 virtual void TogglePause() OVERRIDE; | 73 virtual void TogglePause() OVERRIDE; |
| 66 virtual void Cancel(bool user_cancel) OVERRIDE; | 74 virtual void Cancel(bool user_cancel) OVERRIDE; |
| 67 virtual void Delete(DeleteReason reason) OVERRIDE; | 75 virtual void Delete(DeleteReason reason) OVERRIDE; |
| 68 virtual void Remove() OVERRIDE; | 76 virtual void Remove() OVERRIDE; |
| 69 virtual void OpenDownload() OVERRIDE; | 77 virtual void OpenDownload() OVERRIDE; |
| 70 virtual void ShowDownloadInShell() OVERRIDE; | 78 virtual void ShowDownloadInShell() OVERRIDE; |
| 71 virtual int32 GetId() const OVERRIDE; | 79 virtual int32 GetId() const OVERRIDE; |
| 72 virtual content::DownloadId GetGlobalId() const OVERRIDE; | 80 virtual content::DownloadId GetGlobalId() const OVERRIDE; |
| 73 virtual int64 GetDbHandle() const OVERRIDE; | |
| 74 virtual DownloadState GetState() const OVERRIDE; | 81 virtual DownloadState GetState() const OVERRIDE; |
| 75 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; | 82 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; |
| 76 virtual bool IsPaused() const OVERRIDE; | 83 virtual bool IsPaused() const OVERRIDE; |
| 77 virtual bool IsTemporary() const OVERRIDE; | 84 virtual bool IsTemporary() const OVERRIDE; |
| 78 virtual bool IsPersisted() const OVERRIDE; | |
| 79 virtual bool IsPartialDownload() const OVERRIDE; | 85 virtual bool IsPartialDownload() const OVERRIDE; |
| 80 virtual bool IsInProgress() const OVERRIDE; | 86 virtual bool IsInProgress() const OVERRIDE; |
| 81 virtual bool IsCancelled() const OVERRIDE; | 87 virtual bool IsCancelled() const OVERRIDE; |
| 82 virtual bool IsInterrupted() const OVERRIDE; | 88 virtual bool IsInterrupted() const OVERRIDE; |
| 83 virtual bool IsComplete() const OVERRIDE; | 89 virtual bool IsComplete() const OVERRIDE; |
| 84 virtual const GURL& GetURL() const OVERRIDE; | 90 virtual const GURL& GetURL() const OVERRIDE; |
| 85 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; | 91 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; |
| 86 virtual const GURL& GetOriginalUrl() const OVERRIDE; | 92 virtual const GURL& GetOriginalUrl() const OVERRIDE; |
| 87 virtual const GURL& GetReferrerUrl() const OVERRIDE; | 93 virtual const GURL& GetReferrerUrl() const OVERRIDE; |
| 88 virtual std::string GetSuggestedFilename() const OVERRIDE; | 94 virtual std::string GetSuggestedFilename() const OVERRIDE; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 114 virtual int64 GetTotalBytes() const OVERRIDE; | 120 virtual int64 GetTotalBytes() const OVERRIDE; |
| 115 virtual int64 GetReceivedBytes() const OVERRIDE; | 121 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 116 virtual base::Time GetStartTime() const OVERRIDE; | 122 virtual base::Time GetStartTime() const OVERRIDE; |
| 117 virtual base::Time GetEndTime() const OVERRIDE; | 123 virtual base::Time GetEndTime() const OVERRIDE; |
| 118 virtual bool CanShowInFolder() OVERRIDE; | 124 virtual bool CanShowInFolder() OVERRIDE; |
| 119 virtual bool CanOpenDownload() OVERRIDE; | 125 virtual bool CanOpenDownload() OVERRIDE; |
| 120 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 126 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 121 virtual bool GetOpenWhenComplete() const OVERRIDE; | 127 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 122 virtual bool GetAutoOpened() OVERRIDE; | 128 virtual bool GetAutoOpened() OVERRIDE; |
| 123 virtual bool GetOpened() const OVERRIDE; | 129 virtual bool GetOpened() const OVERRIDE; |
| 124 virtual content::DownloadPersistentStoreInfo | |
| 125 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; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 virtual void UpdateProgress(int64 bytes_so_far, | 197 virtual void UpdateProgress(int64 bytes_so_far, |
| 194 int64 bytes_per_sec, | 198 int64 bytes_per_sec, |
| 195 const std::string& hash_state); | 199 const std::string& hash_state); |
| 196 | 200 |
| 197 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); | 201 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); |
| 198 | 202 |
| 199 // Called by SavePackage to display progress when the DownloadItem | 203 // Called by SavePackage to display progress when the DownloadItem |
| 200 // should be considered complete. | 204 // should be considered complete. |
| 201 virtual void MarkAsComplete(); | 205 virtual void MarkAsComplete(); |
| 202 | 206 |
| 203 // Interactions with persistence system -------------------------------------- | |
| 204 | |
| 205 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. | |
| 206 virtual void SetIsPersisted(); | |
| 207 virtual void SetDbHandle(int64 handle); | |
| 208 | |
| 209 private: | 207 private: |
| 210 // Normal progression of a download ------------------------------------------ | 208 // Normal progression of a download ------------------------------------------ |
| 211 | 209 |
| 212 // These are listed in approximately chronological order. There are also | 210 // These are listed in approximately chronological order. There are also |
| 213 // public methods involved in normal download progression; see | 211 // public methods involved in normal download progression; see |
| 214 // the implementation ordering in download_item_impl.cc. | 212 // the implementation ordering in download_item_impl.cc. |
| 215 | 213 |
| 216 // Construction common to all constructors. |active| should be true for new | 214 // Construction common to all constructors. |active| should be true for new |
| 217 // downloads and false for downloads from the history. | 215 // downloads and false for downloads from the history. |
| 218 // |download_type| indicates to the net log system what kind of download | 216 // |download_type| indicates to the net log system what kind of download |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 358 |
| 361 // The views of this item in the download shelf and download contents. | 359 // The views of this item in the download shelf and download contents. |
| 362 ObserverList<Observer> observers_; | 360 ObserverList<Observer> observers_; |
| 363 | 361 |
| 364 // Time the download was started. | 362 // Time the download was started. |
| 365 base::Time start_time_; | 363 base::Time start_time_; |
| 366 | 364 |
| 367 // Time the download completed. | 365 // Time the download completed. |
| 368 base::Time end_time_; | 366 base::Time end_time_; |
| 369 | 367 |
| 370 // Our persistent store handle. | |
| 371 int64 db_handle_; | |
| 372 | |
| 373 // Our delegate. | 368 // Our delegate. |
| 374 DownloadItemImplDelegate* delegate_; | 369 DownloadItemImplDelegate* delegate_; |
| 375 | 370 |
| 376 // In progress downloads may be paused by the user, we note it here. | 371 // In progress downloads may be paused by the user, we note it here. |
| 377 bool is_paused_; | 372 bool is_paused_; |
| 378 | 373 |
| 379 // A flag for indicating if the download should be opened at completion. | 374 // A flag for indicating if the download should be opened at completion. |
| 380 bool open_when_complete_; | 375 bool open_when_complete_; |
| 381 | 376 |
| 382 // A flag for indicating if the downloaded file is externally removed. | 377 // A flag for indicating if the downloaded file is externally removed. |
| 383 bool file_externally_removed_; | 378 bool file_externally_removed_; |
| 384 | 379 |
| 385 // Indicates if the download is considered potentially safe or dangerous | 380 // Indicates if the download is considered potentially safe or dangerous |
| 386 // (executable files are typically considered dangerous). | 381 // (executable files are typically considered dangerous). |
| 387 SafetyState safety_state_; | 382 SafetyState safety_state_; |
| 388 | 383 |
| 389 // True if the download was auto-opened. We set this rather than using | 384 // True if the download was auto-opened. We set this rather than using |
| 390 // an observer as it's frequently possible for the download to be auto opened | 385 // an observer as it's frequently possible for the download to be auto opened |
| 391 // before the observer is added. | 386 // before the observer is added. |
| 392 bool auto_opened_; | 387 bool auto_opened_; |
| 393 | 388 |
| 394 bool is_persisted_; | |
| 395 | |
| 396 // True if the item was downloaded temporarily. | 389 // True if the item was downloaded temporarily. |
| 397 bool is_temporary_; | 390 bool is_temporary_; |
| 398 | 391 |
| 399 // True if we've saved all the data for the download. | 392 // True if we've saved all the data for the download. |
| 400 bool all_data_saved_; | 393 bool all_data_saved_; |
| 401 | 394 |
| 402 // Did the user open the item either directly or indirectly (such as by | 395 // Did the user open the item either directly or indirectly (such as by |
| 403 // setting always open files of this type)? The shelf also sets this field | 396 // setting always open files of this type)? The shelf also sets this field |
| 404 // when the user closes the shelf before the item has been opened but should | 397 // when the user closes the shelf before the item has been opened but should |
| 405 // be treated as though the user opened it. | 398 // be treated as though the user opened it. |
| 406 bool opened_; | 399 bool opened_; |
| 407 | 400 |
| 408 // Do we actually open downloads when requested? For testing purposes only. | 401 // Do we actually open downloads when requested? For testing purposes only. |
| 409 bool open_enabled_; | 402 bool open_enabled_; |
| 410 | 403 |
| 411 // Did the delegate delay calling Complete on this download? | 404 // Did the delegate delay calling Complete on this download? |
| 412 bool delegate_delayed_complete_; | 405 bool delegate_delayed_complete_; |
| 413 | 406 |
| 414 // Net log to use for this download. | 407 // Net log to use for this download. |
| 415 const net::BoundNetLog bound_net_log_; | 408 const net::BoundNetLog bound_net_log_; |
| 416 | 409 |
| 417 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 410 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 418 | 411 |
| 419 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 412 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 420 }; | 413 }; |
| 421 | 414 |
| 422 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 415 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |