| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "content/browser/download/download_item.h" | 17 #include "content/browser/download/download_item.h" |
| 18 #include "content/browser/download/download_id.h" | 18 #include "content/browser/download/download_id.h" |
| 19 #include "content/browser/download/download_request_handle.h" | 19 #include "content/browser/download/download_request_handle.h" |
| 20 #include "content/browser/download/download_state_info.h" | 20 #include "content/browser/download/download_state_info.h" |
| 21 #include "content/browser/download/interrupt_reasons.h" | 21 #include "content/browser/download/interrupt_reasons.h" |
| 22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 | 25 |
| 26 class DownloadFileManager; | 26 class DownloadFileManager; |
| 27 class DownloadId; |
| 28 class DownloadManager; |
| 27 class TabContents; | 29 class TabContents; |
| 28 | 30 |
| 29 struct DownloadCreateInfo; | 31 struct DownloadCreateInfo; |
| 30 struct DownloadPersistentStoreInfo; | 32 struct DownloadPersistentStoreInfo; |
| 31 | 33 |
| 32 namespace content { | |
| 33 class BrowserContext; | |
| 34 } | |
| 35 | |
| 36 // See download_item.h for usage. | 34 // See download_item.h for usage. |
| 37 class CONTENT_EXPORT DownloadItemImpl : public DownloadItem { | 35 class CONTENT_EXPORT DownloadItemImpl : public DownloadItem { |
| 38 public: | 36 public: |
| 39 // Delegate is defined in DownloadItemImpl (rather than DownloadItem) | |
| 40 // as it's relevant to the class implementation (class methods need to | |
| 41 // call into it) and doesn't have anything to do with its interface. | |
| 42 // Despite this, the delegate methods take DownloadItems as arguments | |
| 43 // (rather than DownloadItemImpls) so that classes that inherit from it | |
| 44 // can be used with DownloadItem mocks rather than being tied to | |
| 45 // DownloadItemImpls. | |
| 46 class Delegate { | |
| 47 public: | |
| 48 Delegate(); | |
| 49 virtual ~Delegate(); | |
| 50 | |
| 51 // Used for catching use-after-free errors. | |
| 52 void Attach(); | |
| 53 void Detach(); | |
| 54 | |
| 55 // Tests if a file type should be opened automatically. | |
| 56 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) = 0; | |
| 57 | |
| 58 // Allows the delegate to override the opening of a download. If it returns | |
| 59 // true then it's reponsible for opening the item. | |
| 60 virtual bool ShouldOpenDownload(DownloadItem* download) = 0; | |
| 61 | |
| 62 // Checks whether a downloaded file still exists and updates the | |
| 63 // file's state if the file is already removed. | |
| 64 // The check may or may not result in a later asynchronous call | |
| 65 // to OnDownloadedFileRemoved(). | |
| 66 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0; | |
| 67 | |
| 68 // If all pre-requisites have been met, complete download processing. | |
| 69 // TODO(rdsmith): Move into DownloadItem. | |
| 70 virtual void MaybeCompleteDownload(DownloadItem* download) = 0; | |
| 71 | |
| 72 // For contextual issues like language and prefs. | |
| 73 virtual content::BrowserContext* BrowserContext() const = 0; | |
| 74 | |
| 75 // Handle any delegate portions of a state change operation on the | |
| 76 // DownloadItem. | |
| 77 virtual void DownloadCancelled(DownloadItem* download) = 0; | |
| 78 virtual void DownloadCompleted(DownloadItem* download) = 0; | |
| 79 virtual void DownloadOpened(DownloadItem* download) = 0; | |
| 80 virtual void DownloadRemoved(DownloadItem* download) = 0; | |
| 81 | |
| 82 // Assert consistent state for delgate object at various transitions. | |
| 83 virtual void AssertStateConsistent(DownloadItem* download) const = 0; | |
| 84 | |
| 85 private: | |
| 86 // For "Outlives attached DownloadItemImpl" invariant assertion. | |
| 87 int count_; | |
| 88 }; | |
| 89 | |
| 90 // Note that it is the responsibility of the caller to ensure that a | |
| 91 // DownloadItemImpl::Delegate passed to a DownloadItemImpl constructor | |
| 92 // outlives the DownloadItemImpl. | |
| 93 | |
| 94 // Constructing from persistent store: | 37 // Constructing from persistent store: |
| 95 DownloadItemImpl(Delegate* delegate, | 38 DownloadItemImpl(DownloadManager* download_manager, |
| 96 DownloadId download_id, | |
| 97 const DownloadPersistentStoreInfo& info); | 39 const DownloadPersistentStoreInfo& info); |
| 98 | 40 |
| 99 // Constructing for a regular download. | 41 // Constructing for a regular download. |
| 100 // Takes ownership of the object pointed to by |request_handle|. | 42 // Takes ownership of the object pointed to by |request_handle|. |
| 101 DownloadItemImpl(Delegate* delegate, | 43 DownloadItemImpl(DownloadManager* download_manager, |
| 102 const DownloadCreateInfo& info, | 44 const DownloadCreateInfo& info, |
| 103 DownloadRequestHandleInterface* request_handle, | 45 DownloadRequestHandleInterface* request_handle, |
| 104 bool is_otr); | 46 bool is_otr); |
| 105 | 47 |
| 106 // Constructing for the "Save Page As..." feature: | 48 // Constructing for the "Save Page As..." feature: |
| 107 DownloadItemImpl(Delegate* delegate, | 49 DownloadItemImpl(DownloadManager* download_manager, |
| 108 const FilePath& path, | 50 const FilePath& path, |
| 109 const GURL& url, | 51 const GURL& url, |
| 110 bool is_otr, | 52 bool is_otr, |
| 111 DownloadId download_id); | 53 DownloadId download_id); |
| 112 | 54 |
| 113 virtual ~DownloadItemImpl(); | 55 virtual ~DownloadItemImpl(); |
| 114 | 56 |
| 115 // Overridden from DownloadItem. | 57 // Overridden from DownloadItem. |
| 116 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 58 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 117 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 59 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 118 virtual void UpdateObservers() OVERRIDE; | 60 virtual void UpdateObservers() OVERRIDE; |
| 119 virtual bool CanShowInFolder() OVERRIDE; | 61 virtual bool CanShowInFolder() OVERRIDE; |
| 120 virtual bool CanOpenDownload() OVERRIDE; | 62 virtual bool CanOpenDownload() OVERRIDE; |
| 121 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 63 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
| 122 virtual void OpenDownload() OVERRIDE; | 64 virtual void OpenDownload() OVERRIDE; |
| 123 virtual void ShowDownloadInShell() OVERRIDE; | 65 virtual void ShowDownloadInShell() OVERRIDE; |
| 124 virtual void DangerousDownloadValidated() OVERRIDE; | 66 virtual void DangerousDownloadValidated() OVERRIDE; |
| 125 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; | 67 virtual void UpdateProgress(int64 bytes_so_far, int64 bytes_per_sec) OVERRIDE; |
| 126 virtual void Cancel(bool user_cancel) OVERRIDE; | 68 virtual void Cancel(bool user_cancel) OVERRIDE; |
| 127 virtual void MarkAsComplete() OVERRIDE; | 69 virtual void MarkAsComplete() OVERRIDE; |
| 128 virtual void DelayedDownloadOpened() OVERRIDE; | 70 virtual void DelayedDownloadOpened() OVERRIDE; |
| 129 virtual void OnAllDataSaved( | 71 virtual void OnAllDataSaved( |
| 130 int64 size, const std::string& final_hash) OVERRIDE; | 72 int64 size, const std::string& final_hash) OVERRIDE; |
| 131 virtual void OnDownloadedFileRemoved() OVERRIDE; | 73 virtual void OnDownloadedFileRemoved() OVERRIDE; |
| 132 virtual void MaybeCompleteDownload() OVERRIDE; | |
| 133 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; | 74 virtual void Interrupted(int64 size, InterruptReason reason) OVERRIDE; |
| 134 virtual void Delete(DeleteReason reason) OVERRIDE; | 75 virtual void Delete(DeleteReason reason) OVERRIDE; |
| 135 virtual void Remove() OVERRIDE; | 76 virtual void Remove() OVERRIDE; |
| 136 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; | 77 virtual bool TimeRemaining(base::TimeDelta* remaining) const OVERRIDE; |
| 137 virtual int64 CurrentSpeed() const OVERRIDE; | 78 virtual int64 CurrentSpeed() const OVERRIDE; |
| 138 virtual int PercentComplete() const OVERRIDE; | 79 virtual int PercentComplete() const OVERRIDE; |
| 139 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; | 80 virtual void OnPathDetermined(const FilePath& path) OVERRIDE; |
| 140 virtual bool AllDataSaved() const OVERRIDE; | 81 virtual bool AllDataSaved() const OVERRIDE; |
| 141 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; | 82 virtual void SetFileCheckResults(const DownloadStateInfo& state) OVERRIDE; |
| 142 virtual void Rename(const FilePath& full_path) OVERRIDE; | 83 virtual void Rename(const FilePath& full_path) OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 164 virtual int64 GetTotalBytes() const OVERRIDE; | 105 virtual int64 GetTotalBytes() const OVERRIDE; |
| 165 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 106 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
| 166 virtual const std::string& GetHash() const OVERRIDE; | 107 virtual const std::string& GetHash() const OVERRIDE; |
| 167 virtual int64 GetReceivedBytes() const OVERRIDE; | 108 virtual int64 GetReceivedBytes() const OVERRIDE; |
| 168 virtual int32 GetId() const OVERRIDE; | 109 virtual int32 GetId() const OVERRIDE; |
| 169 virtual DownloadId GetGlobalId() const OVERRIDE; | 110 virtual DownloadId GetGlobalId() const OVERRIDE; |
| 170 virtual base::Time GetStartTime() const OVERRIDE; | 111 virtual base::Time GetStartTime() const OVERRIDE; |
| 171 virtual base::Time GetEndTime() const OVERRIDE; | 112 virtual base::Time GetEndTime() const OVERRIDE; |
| 172 virtual void SetDbHandle(int64 handle) OVERRIDE; | 113 virtual void SetDbHandle(int64 handle) OVERRIDE; |
| 173 virtual int64 GetDbHandle() const OVERRIDE; | 114 virtual int64 GetDbHandle() const OVERRIDE; |
| 115 virtual DownloadManager* GetDownloadManager() OVERRIDE; |
| 174 virtual bool IsPaused() const OVERRIDE; | 116 virtual bool IsPaused() const OVERRIDE; |
| 175 virtual bool GetOpenWhenComplete() const OVERRIDE; | 117 virtual bool GetOpenWhenComplete() const OVERRIDE; |
| 176 virtual void SetOpenWhenComplete(bool open) OVERRIDE; | 118 virtual void SetOpenWhenComplete(bool open) OVERRIDE; |
| 177 virtual bool GetFileExternallyRemoved() const OVERRIDE; | 119 virtual bool GetFileExternallyRemoved() const OVERRIDE; |
| 178 virtual SafetyState GetSafetyState() const OVERRIDE; | 120 virtual SafetyState GetSafetyState() const OVERRIDE; |
| 179 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; | 121 virtual DownloadStateInfo::DangerType GetDangerType() const OVERRIDE; |
| 180 virtual bool IsDangerous() const OVERRIDE; | 122 virtual bool IsDangerous() const OVERRIDE; |
| 181 virtual void MarkFileDangerous() OVERRIDE; | 123 virtual void MarkFileDangerous() OVERRIDE; |
| 182 virtual void MarkUrlDangerous() OVERRIDE; | 124 virtual void MarkUrlDangerous() OVERRIDE; |
| 183 virtual void MarkContentDangerous() OVERRIDE; | 125 virtual void MarkContentDangerous() OVERRIDE; |
| 184 virtual bool GetAutoOpened() OVERRIDE; | 126 virtual bool GetAutoOpened() OVERRIDE; |
| 185 virtual const FilePath& GetTargetName() const OVERRIDE; | 127 virtual const FilePath& GetTargetName() const OVERRIDE; |
| 186 virtual bool PromptUserForSaveLocation() const OVERRIDE; | 128 virtual bool PromptUserForSaveLocation() const OVERRIDE; |
| 187 virtual bool IsOtr() const OVERRIDE; | 129 virtual bool IsOtr() const OVERRIDE; |
| 188 virtual const FilePath& GetSuggestedPath() const OVERRIDE; | 130 virtual const FilePath& GetSuggestedPath() const OVERRIDE; |
| 189 virtual bool IsTemporary() const OVERRIDE; | 131 virtual bool IsTemporary() const OVERRIDE; |
| 190 virtual void SetOpened(bool opened) OVERRIDE; | 132 virtual void SetOpened(bool opened) OVERRIDE; |
| 191 virtual bool GetOpened() const OVERRIDE; | 133 virtual bool GetOpened() const OVERRIDE; |
| 192 virtual InterruptReason GetLastReason() const OVERRIDE; | 134 virtual InterruptReason GetLastReason() const OVERRIDE; |
| 193 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; | 135 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const OVERRIDE; |
| 194 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; | 136 virtual DownloadStateInfo GetStateInfo() const OVERRIDE; |
| 195 virtual content::BrowserContext* BrowserContext() const OVERRIDE; | |
| 196 virtual TabContents* GetTabContents() const OVERRIDE; | 137 virtual TabContents* GetTabContents() const OVERRIDE; |
| 197 virtual FilePath GetTargetFilePath() const OVERRIDE; | 138 virtual FilePath GetTargetFilePath() const OVERRIDE; |
| 198 virtual FilePath GetFileNameToReportUser() const OVERRIDE; | 139 virtual FilePath GetFileNameToReportUser() const OVERRIDE; |
| 199 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; | 140 virtual FilePath GetUserVerifiedFilePath() const OVERRIDE; |
| 200 virtual bool NeedsRename() const OVERRIDE; | 141 virtual bool NeedsRename() const OVERRIDE; |
| 201 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; | 142 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; |
| 202 virtual std::string DebugString(bool verbose) const OVERRIDE; | 143 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 203 virtual void MockDownloadOpenForTesting() OVERRIDE; | 144 virtual void MockDownloadOpenForTesting() OVERRIDE; |
| 204 | 145 |
| 205 private: | 146 private: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 238 |
| 298 // Time the download was started | 239 // Time the download was started |
| 299 base::Time start_time_; | 240 base::Time start_time_; |
| 300 | 241 |
| 301 // Time the download completed | 242 // Time the download completed |
| 302 base::Time end_time_; | 243 base::Time end_time_; |
| 303 | 244 |
| 304 // Our persistent store handle | 245 // Our persistent store handle |
| 305 int64 db_handle_; | 246 int64 db_handle_; |
| 306 | 247 |
| 307 // Our delegate. | 248 // Our owning object |
| 308 Delegate* delegate_; | 249 DownloadManager* download_manager_; |
| 309 | 250 |
| 310 // In progress downloads may be paused by the user, we note it here | 251 // In progress downloads may be paused by the user, we note it here |
| 311 bool is_paused_; | 252 bool is_paused_; |
| 312 | 253 |
| 313 // A flag for indicating if the download should be opened at completion. | 254 // A flag for indicating if the download should be opened at completion. |
| 314 bool open_when_complete_; | 255 bool open_when_complete_; |
| 315 | 256 |
| 316 // A flag for indicating if the downloaded file is externally removed. | 257 // A flag for indicating if the downloaded file is externally removed. |
| 317 bool file_externally_removed_; | 258 bool file_externally_removed_; |
| 318 | 259 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 344 // only. | 285 // only. |
| 345 bool open_enabled_; | 286 bool open_enabled_; |
| 346 | 287 |
| 347 // Did the delegate delay calling Complete on this download? | 288 // Did the delegate delay calling Complete on this download? |
| 348 bool delegate_delayed_complete_; | 289 bool delegate_delayed_complete_; |
| 349 | 290 |
| 350 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 291 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 351 }; | 292 }; |
| 352 | 293 |
| 353 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 294 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |