| 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 27 matching lines...) Expand all Loading... |
| 116 virtual int64 GetReceivedBytes() const OVERRIDE; | 122 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 117 virtual base::Time GetStartTime() const OVERRIDE; | 123 virtual base::Time GetStartTime() const OVERRIDE; |
| 118 virtual base::Time GetEndTime() const OVERRIDE; | 124 virtual base::Time GetEndTime() const OVERRIDE; |
| 119 virtual bool CanShowInFolder() OVERRIDE; | 125 virtual bool CanShowInFolder() OVERRIDE; |
| 120 virtual bool CanOpenDownload() OVERRIDE; | 126 virtual bool CanOpenDownload() OVERRIDE; |
| 121 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 127 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 122 virtual bool GetOpenWhenComplete() const OVERRIDE; | 128 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 123 virtual bool GetAutoOpened() OVERRIDE; | 129 virtual bool GetAutoOpened() OVERRIDE; |
| 124 virtual bool GetOpened() const OVERRIDE; | 130 virtual bool GetOpened() const OVERRIDE; |
| 125 virtual bool MatchesQuery(const string16& query) const OVERRIDE; | 131 virtual bool MatchesQuery(const string16& query) const OVERRIDE; |
| 126 virtual content::DownloadPersistentStoreInfo | |
| 127 GetPersistentStoreInfo() const OVERRIDE; | |
| 128 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; | 132 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; |
| 129 virtual content::WebContents* GetWebContents() const OVERRIDE; | 133 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 130 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; | 134 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; |
| 131 virtual void OnContentCheckCompleted( | 135 virtual void OnContentCheckCompleted( |
| 132 content::DownloadDangerType danger_type) OVERRIDE; | 136 content::DownloadDangerType danger_type) OVERRIDE; |
| 133 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 137 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 134 virtual void SetIsTemporary(bool temporary) OVERRIDE; | 138 virtual void SetIsTemporary(bool temporary) OVERRIDE; |
| 135 virtual void SetOpened(bool opened) OVERRIDE; | 139 virtual void SetOpened(bool opened) OVERRIDE; |
| 136 virtual void SetDisplayName(const FilePath& name) OVERRIDE; | 140 virtual void SetDisplayName(const FilePath& name) OVERRIDE; |
| 137 virtual std::string DebugString(bool verbose) const OVERRIDE; | 141 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 virtual void UpdateProgress(int64 bytes_so_far, | 199 virtual void UpdateProgress(int64 bytes_so_far, |
| 196 int64 bytes_per_sec, | 200 int64 bytes_per_sec, |
| 197 const std::string& hash_state); | 201 const std::string& hash_state); |
| 198 | 202 |
| 199 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); | 203 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); |
| 200 | 204 |
| 201 // Called by SavePackage to display progress when the DownloadItem | 205 // Called by SavePackage to display progress when the DownloadItem |
| 202 // should be considered complete. | 206 // should be considered complete. |
| 203 virtual void MarkAsComplete(); | 207 virtual void MarkAsComplete(); |
| 204 | 208 |
| 205 // Interactions with persistence system -------------------------------------- | |
| 206 | |
| 207 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. | |
| 208 virtual void SetIsPersisted(); | |
| 209 virtual void SetDbHandle(int64 handle); | |
| 210 | |
| 211 private: | 209 private: |
| 212 // Normal progression of a download ------------------------------------------ | 210 // Normal progression of a download ------------------------------------------ |
| 213 | 211 |
| 214 // These are listed in approximately chronological order. There are also | 212 // These are listed in approximately chronological order. There are also |
| 215 // public methods involved in normal download progression; see | 213 // public methods involved in normal download progression; see |
| 216 // the implementation ordering in download_item_impl.cc. | 214 // the implementation ordering in download_item_impl.cc. |
| 217 | 215 |
| 218 // Construction common to all constructors. |active| should be true for new | 216 // Construction common to all constructors. |active| should be true for new |
| 219 // downloads and false for downloads from the history. | 217 // downloads and false for downloads from the history. |
| 220 // |download_type| indicates to the net log system what kind of download | 218 // |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... |
| 362 | 360 |
| 363 // The views of this item in the download shelf and download contents. | 361 // The views of this item in the download shelf and download contents. |
| 364 ObserverList<Observer> observers_; | 362 ObserverList<Observer> observers_; |
| 365 | 363 |
| 366 // Time the download was started. | 364 // Time the download was started. |
| 367 base::Time start_time_; | 365 base::Time start_time_; |
| 368 | 366 |
| 369 // Time the download completed. | 367 // Time the download completed. |
| 370 base::Time end_time_; | 368 base::Time end_time_; |
| 371 | 369 |
| 372 // Our persistent store handle. | |
| 373 int64 db_handle_; | |
| 374 | |
| 375 // Our delegate. | 370 // Our delegate. |
| 376 DownloadItemImplDelegate* delegate_; | 371 DownloadItemImplDelegate* delegate_; |
| 377 | 372 |
| 378 // In progress downloads may be paused by the user, we note it here. | 373 // In progress downloads may be paused by the user, we note it here. |
| 379 bool is_paused_; | 374 bool is_paused_; |
| 380 | 375 |
| 381 // A flag for indicating if the download should be opened at completion. | 376 // A flag for indicating if the download should be opened at completion. |
| 382 bool open_when_complete_; | 377 bool open_when_complete_; |
| 383 | 378 |
| 384 // A flag for indicating if the downloaded file is externally removed. | 379 // A flag for indicating if the downloaded file is externally removed. |
| 385 bool file_externally_removed_; | 380 bool file_externally_removed_; |
| 386 | 381 |
| 387 // Indicates if the download is considered potentially safe or dangerous | 382 // Indicates if the download is considered potentially safe or dangerous |
| 388 // (executable files are typically considered dangerous). | 383 // (executable files are typically considered dangerous). |
| 389 SafetyState safety_state_; | 384 SafetyState safety_state_; |
| 390 | 385 |
| 391 // True if the download was auto-opened. We set this rather than using | 386 // True if the download was auto-opened. We set this rather than using |
| 392 // an observer as it's frequently possible for the download to be auto opened | 387 // an observer as it's frequently possible for the download to be auto opened |
| 393 // before the observer is added. | 388 // before the observer is added. |
| 394 bool auto_opened_; | 389 bool auto_opened_; |
| 395 | 390 |
| 396 bool is_persisted_; | |
| 397 | |
| 398 // True if the item was downloaded temporarily. | 391 // True if the item was downloaded temporarily. |
| 399 bool is_temporary_; | 392 bool is_temporary_; |
| 400 | 393 |
| 401 // True if we've saved all the data for the download. | 394 // True if we've saved all the data for the download. |
| 402 bool all_data_saved_; | 395 bool all_data_saved_; |
| 403 | 396 |
| 404 // Did the user open the item either directly or indirectly (such as by | 397 // Did the user open the item either directly or indirectly (such as by |
| 405 // setting always open files of this type)? The shelf also sets this field | 398 // setting always open files of this type)? The shelf also sets this field |
| 406 // when the user closes the shelf before the item has been opened but should | 399 // when the user closes the shelf before the item has been opened but should |
| 407 // be treated as though the user opened it. | 400 // be treated as though the user opened it. |
| 408 bool opened_; | 401 bool opened_; |
| 409 | 402 |
| 410 // Do we actually open downloads when requested? For testing purposes only. | 403 // Do we actually open downloads when requested? For testing purposes only. |
| 411 bool open_enabled_; | 404 bool open_enabled_; |
| 412 | 405 |
| 413 // Did the delegate delay calling Complete on this download? | 406 // Did the delegate delay calling Complete on this download? |
| 414 bool delegate_delayed_complete_; | 407 bool delegate_delayed_complete_; |
| 415 | 408 |
| 416 // Net log to use for this download. | 409 // Net log to use for this download. |
| 417 const net::BoundNetLog bound_net_log_; | 410 const net::BoundNetLog bound_net_log_; |
| 418 | 411 |
| 419 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 412 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 420 | 413 |
| 421 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 414 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 422 }; | 415 }; |
| 423 | 416 |
| 424 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 417 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |