| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // to use to store the download until OnDownloadCompleting() is called. | 68 // to use to store the download until OnDownloadCompleting() is called. |
| 69 virtual void OnDownloadTargetDetermined( | 69 virtual void OnDownloadTargetDetermined( |
| 70 const FilePath& target_path, | 70 const FilePath& target_path, |
| 71 TargetDisposition disposition, | 71 TargetDisposition disposition, |
| 72 content::DownloadDangerType danger_type, | 72 content::DownloadDangerType danger_type, |
| 73 const FilePath& intermediate_path); | 73 const FilePath& intermediate_path); |
| 74 | 74 |
| 75 // Indicate that an error has occurred on the download. | 75 // Indicate that an error has occurred on the download. |
| 76 virtual void Interrupt(content::DownloadInterruptReason reason); | 76 virtual void Interrupt(content::DownloadInterruptReason reason); |
| 77 | 77 |
| 78 // Mark the item as having been persisted. | |
| 79 virtual void SetIsPersisted(); | |
| 80 | |
| 81 // Set the item's DB handle. | |
| 82 virtual void SetDbHandle(int64 handle); | |
| 83 | |
| 84 // Cancels the off-thread aspects of the download. | 78 // Cancels the off-thread aspects of the download. |
| 85 // TODO(rdsmith): This should be private and only called from | 79 // TODO(rdsmith): This should be private and only called from |
| 86 // DownloadItem::Cancel/Interrupt; it isn't now because we can't | 80 // DownloadItem::Cancel/Interrupt; it isn't now because we can't |
| 87 // call those functions from | 81 // call those functions from |
| 88 // DownloadManager::FileSelectionCancelled() without doing some | 82 // DownloadManager::FileSelectionCancelled() without doing some |
| 89 // rewrites of the DownloadManager queues. | 83 // rewrites of the DownloadManager queues. |
| 90 virtual void OffThreadCancel(); | 84 virtual void OffThreadCancel(); |
| 91 | 85 |
| 92 // Called when the downloaded file is removed. | 86 // Called when the downloaded file is removed. |
| 93 virtual void OnDownloadedFileRemoved(); | 87 virtual void OnDownloadedFileRemoved(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 108 // Called by SavePackage to display progress when the DownloadItem | 102 // Called by SavePackage to display progress when the DownloadItem |
| 109 // should be considered complete. | 103 // should be considered complete. |
| 110 virtual void MarkAsComplete(); | 104 virtual void MarkAsComplete(); |
| 111 | 105 |
| 112 // Called when all data has been saved. Only has display effects. | 106 // Called when all data has been saved. Only has display effects. |
| 113 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); | 107 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); |
| 114 | 108 |
| 115 // Called by SavePackage to set the total number of bytes on the item. | 109 // Called by SavePackage to set the total number of bytes on the item. |
| 116 virtual void SetTotalBytes(int64 total_bytes); | 110 virtual void SetTotalBytes(int64 total_bytes); |
| 117 | 111 |
| 112 // Notify observers that this item is being removed by the user. |
| 113 virtual void NotifyRemoved(); |
| 114 |
| 118 // Overridden from DownloadItem. | 115 // Overridden from DownloadItem. |
| 119 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 116 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 120 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 117 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 121 virtual void UpdateObservers() OVERRIDE; | 118 virtual void UpdateObservers() OVERRIDE; |
| 122 virtual bool CanShowInFolder() OVERRIDE; | 119 virtual bool CanShowInFolder() OVERRIDE; |
| 123 virtual bool CanOpenDownload() OVERRIDE; | 120 virtual bool CanOpenDownload() OVERRIDE; |
| 124 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 121 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 125 virtual void OpenDownload() OVERRIDE; | 122 virtual void OpenDownload() OVERRIDE; |
| 126 virtual void ShowDownloadInShell() OVERRIDE; | 123 virtual void ShowDownloadInShell() OVERRIDE; |
| 127 virtual void DangerousDownloadValidated() OVERRIDE; | 124 virtual void DangerousDownloadValidated() OVERRIDE; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 157 virtual std::string GetReferrerCharset() const OVERRIDE; | 154 virtual std::string GetReferrerCharset() const OVERRIDE; |
| 158 virtual std::string GetRemoteAddress() const OVERRIDE; | 155 virtual std::string GetRemoteAddress() const OVERRIDE; |
| 159 virtual int64 GetTotalBytes() const OVERRIDE; | 156 virtual int64 GetTotalBytes() const OVERRIDE; |
| 160 virtual const std::string& GetHash() const OVERRIDE; | 157 virtual const std::string& GetHash() const OVERRIDE; |
| 161 virtual int64 GetReceivedBytes() const OVERRIDE; | 158 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 162 virtual const std::string& GetHashState() const OVERRIDE; | 159 virtual const std::string& GetHashState() const OVERRIDE; |
| 163 virtual int32 GetId() const OVERRIDE; | 160 virtual int32 GetId() const OVERRIDE; |
| 164 virtual content::DownloadId GetGlobalId() const OVERRIDE; | 161 virtual content::DownloadId GetGlobalId() const OVERRIDE; |
| 165 virtual base::Time GetStartTime() const OVERRIDE; | 162 virtual base::Time GetStartTime() const OVERRIDE; |
| 166 virtual base::Time GetEndTime() const OVERRIDE; | 163 virtual base::Time GetEndTime() const OVERRIDE; |
| 167 virtual bool IsPersisted() const OVERRIDE; | |
| 168 virtual int64 GetDbHandle() const OVERRIDE; | |
| 169 virtual bool IsPaused() const OVERRIDE; | 164 virtual bool IsPaused() const OVERRIDE; |
| 170 virtual bool GetOpenWhenComplete() const OVERRIDE; | 165 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 171 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 166 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 172 virtual bool GetFileExternallyRemoved() const OVERRIDE; | 167 virtual bool GetFileExternallyRemoved() const OVERRIDE; |
| 173 virtual SafetyState GetSafetyState() const OVERRIDE; | 168 virtual SafetyState GetSafetyState() const OVERRIDE; |
| 174 virtual content::DownloadDangerType GetDangerType() const OVERRIDE; | 169 virtual content::DownloadDangerType GetDangerType() const OVERRIDE; |
| 175 virtual bool IsDangerous() const OVERRIDE; | 170 virtual bool IsDangerous() const OVERRIDE; |
| 176 virtual bool GetAutoOpened() OVERRIDE; | 171 virtual bool GetAutoOpened() OVERRIDE; |
| 177 virtual FilePath GetTargetName() const OVERRIDE; | 172 virtual FilePath GetTargetName() const OVERRIDE; |
| 178 virtual const FilePath& GetForcedFilePath() const OVERRIDE; | 173 virtual const FilePath& GetForcedFilePath() const OVERRIDE; |
| 179 virtual bool HasUserGesture() const OVERRIDE; | 174 virtual bool HasUserGesture() const OVERRIDE; |
| 180 virtual content::PageTransition GetTransitionType() const OVERRIDE; | 175 virtual content::PageTransition GetTransitionType() const OVERRIDE; |
| 181 virtual bool IsOtr() const OVERRIDE; | 176 virtual bool IsOtr() const OVERRIDE; |
| 182 virtual bool IsTemporary() const OVERRIDE; | 177 virtual bool IsTemporary() const OVERRIDE; |
| 183 virtual void SetIsTemporary(bool temporary) OVERRIDE; | 178 virtual void SetIsTemporary(bool temporary) OVERRIDE; |
| 184 virtual void SetOpened(bool opened) OVERRIDE; | 179 virtual void SetOpened(bool opened) OVERRIDE; |
| 185 virtual bool GetOpened() const OVERRIDE; | 180 virtual bool GetOpened() const OVERRIDE; |
| 186 virtual const std::string& GetLastModifiedTime() const OVERRIDE; | 181 virtual const std::string& GetLastModifiedTime() const OVERRIDE; |
| 187 virtual const std::string& GetETag() const OVERRIDE; | 182 virtual const std::string& GetETag() const OVERRIDE; |
| 188 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; | 183 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; |
| 189 virtual content::DownloadPersistentStoreInfo | |
| 190 GetPersistentStoreInfo() const OVERRIDE; | |
| 191 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; | 184 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; |
| 192 virtual content::WebContents* GetWebContents() const OVERRIDE; | 185 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 193 virtual FilePath GetFileNameToReportUser() const OVERRIDE; | 186 virtual FilePath GetFileNameToReportUser() const OVERRIDE; |
| 194 virtual void SetDisplayName(const FilePath& name) OVERRIDE; | 187 virtual void SetDisplayName(const FilePath& name) OVERRIDE; |
| 195 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; | 188 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; |
| 196 virtual std::string DebugString(bool verbose) const OVERRIDE; | 189 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 197 virtual void MockDownloadOpenForTesting() OVERRIDE; | 190 virtual void MockDownloadOpenForTesting() OVERRIDE; |
| 198 virtual ExternalData* GetExternalData(const void* key) OVERRIDE; | |
| 199 virtual const ExternalData* GetExternalData(const void* key) const OVERRIDE; | |
| 200 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE; | |
| 201 | 191 |
| 202 private: | 192 private: |
| 203 // Construction common to all constructors. |active| should be true for new | 193 // Construction common to all constructors. |active| should be true for new |
| 204 // downloads and false for downloads from the history. | 194 // downloads and false for downloads from the history. |
| 205 // |download_type| indicates to the net log system what kind of download | 195 // |download_type| indicates to the net log system what kind of download |
| 206 // this is. | 196 // this is. |
| 207 void Init(bool active, download_net_logs::DownloadType download_type); | 197 void Init(bool active, download_net_logs::DownloadType download_type); |
| 208 | 198 |
| 209 // Returns true if the download still needs to be renamed to | 199 // Returns true if the download still needs to be renamed to |
| 210 // GetTargetFilePath(). | 200 // GetTargetFilePath(). |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 340 |
| 351 // The views of this item in the download shelf and download contents. | 341 // The views of this item in the download shelf and download contents. |
| 352 ObserverList<Observer> observers_; | 342 ObserverList<Observer> observers_; |
| 353 | 343 |
| 354 // Time the download was started. | 344 // Time the download was started. |
| 355 base::Time start_time_; | 345 base::Time start_time_; |
| 356 | 346 |
| 357 // Time the download completed. | 347 // Time the download completed. |
| 358 base::Time end_time_; | 348 base::Time end_time_; |
| 359 | 349 |
| 360 // Our persistent store handle. | |
| 361 int64 db_handle_; | |
| 362 | |
| 363 // Our delegate. | 350 // Our delegate. |
| 364 DownloadItemImplDelegate* delegate_; | 351 DownloadItemImplDelegate* delegate_; |
| 365 | 352 |
| 366 // In progress downloads may be paused by the user, we note it here. | 353 // In progress downloads may be paused by the user, we note it here. |
| 367 bool is_paused_; | 354 bool is_paused_; |
| 368 | 355 |
| 369 // A flag for indicating if the download should be opened at completion. | 356 // A flag for indicating if the download should be opened at completion. |
| 370 bool open_when_complete_; | 357 bool open_when_complete_; |
| 371 | 358 |
| 372 // A flag for indicating if the downloaded file is externally removed. | 359 // A flag for indicating if the downloaded file is externally removed. |
| 373 bool file_externally_removed_; | 360 bool file_externally_removed_; |
| 374 | 361 |
| 375 // Indicates if the download is considered potentially safe or dangerous | 362 // Indicates if the download is considered potentially safe or dangerous |
| 376 // (executable files are typically considered dangerous). | 363 // (executable files are typically considered dangerous). |
| 377 SafetyState safety_state_; | 364 SafetyState safety_state_; |
| 378 | 365 |
| 379 // True if the download was auto-opened. We set this rather than using | 366 // True if the download was auto-opened. We set this rather than using |
| 380 // an observer as it's frequently possible for the download to be auto opened | 367 // an observer as it's frequently possible for the download to be auto opened |
| 381 // before the observer is added. | 368 // before the observer is added. |
| 382 bool auto_opened_; | 369 bool auto_opened_; |
| 383 | 370 |
| 384 bool is_persisted_; | |
| 385 | |
| 386 // True if the download was initiated in an incognito window. | 371 // True if the download was initiated in an incognito window. |
| 387 bool is_otr_; | 372 bool is_otr_; |
| 388 | 373 |
| 389 // True if the item was downloaded temporarily. | 374 // True if the item was downloaded temporarily. |
| 390 bool is_temporary_; | 375 bool is_temporary_; |
| 391 | 376 |
| 392 // True if we've saved all the data for the download. | 377 // True if we've saved all the data for the download. |
| 393 bool all_data_saved_; | 378 bool all_data_saved_; |
| 394 | 379 |
| 395 // Did the user open the item either directly or indirectly (such as by | 380 // Did the user open the item either directly or indirectly (such as by |
| 396 // setting always open files of this type)? The shelf also sets this field | 381 // setting always open files of this type)? The shelf also sets this field |
| 397 // when the user closes the shelf before the item has been opened but should | 382 // when the user closes the shelf before the item has been opened but should |
| 398 // be treated as though the user opened it. | 383 // be treated as though the user opened it. |
| 399 bool opened_; | 384 bool opened_; |
| 400 | 385 |
| 401 // Do we actually open downloads when requested? For testing purposes only. | 386 // Do we actually open downloads when requested? For testing purposes only. |
| 402 bool open_enabled_; | 387 bool open_enabled_; |
| 403 | 388 |
| 404 // Did the delegate delay calling Complete on this download? | 389 // Did the delegate delay calling Complete on this download? |
| 405 bool delegate_delayed_complete_; | 390 bool delegate_delayed_complete_; |
| 406 | 391 |
| 407 // External Data storage. All objects in the store | |
| 408 // are owned by the DownloadItemImpl. | |
| 409 std::map<const void*, ExternalData*> external_data_map_; | |
| 410 | |
| 411 // Net log to use for this download. | 392 // Net log to use for this download. |
| 412 const net::BoundNetLog bound_net_log_; | 393 const net::BoundNetLog bound_net_log_; |
| 413 | 394 |
| 414 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 395 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 415 | 396 |
| 416 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 397 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 417 }; | 398 }; |
| 418 | 399 |
| 419 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 400 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |