| 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 // Each download is represented by a DownloadItem, and all DownloadItems | 5 // Each download is represented by a DownloadItem, and all DownloadItems |
| 6 // are owned by the DownloadManager which maintains a global list of all | 6 // are owned by the DownloadManager which maintains a global list of all |
| 7 // downloads. DownloadItems are created when a user initiates a download, | 7 // downloads. DownloadItems are created when a user initiates a download, |
| 8 // and exist for the duration of the browser life time. | 8 // and exist for the duration of the browser life time. |
| 9 // | 9 // |
| 10 // Download observers: | 10 // Download observers: |
| 11 // DownloadItem::Observer: | 11 // DownloadItem::Observer: |
| 12 // - allows observers to receive notifications about one download from start | 12 // - allows observers to receive notifications about one download from start |
| 13 // to completion | 13 // to completion |
| 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to | 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to |
| 15 // receive state updates. | 15 // receive state updates. |
| 16 | 16 |
| 17 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 17 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
| 18 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 18 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
| 19 | 19 |
| 20 #include <map> | 20 #include <map> |
| 21 #include <string> | 21 #include <string> |
| 22 #include <vector> | 22 #include <vector> |
| 23 | 23 |
| 24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
| 25 #include "base/string16.h" | 25 #include "base/string16.h" |
| 26 #include "base/supports_user_data.h" | 26 #include "base/supports_user_data.h" |
| 27 #include "content/public/browser/download_danger_type.h" | 27 #include "content/public/browser/download_danger_type.h" |
| 28 #include "content/public/browser/download_interrupt_reasons.h" | 28 #include "content/public/browser/download_interrupt_reasons.h" |
| 29 #include "content/public/common/page_transition_types.h" | 29 #include "content/public/common/page_transition_types.h" |
| 30 #include "net/base/net_log.h" |
| 30 | 31 |
| 31 class FilePath; | 32 class FilePath; |
| 32 class GURL; | 33 class GURL; |
| 33 | 34 |
| 34 namespace base { | 35 namespace base { |
| 35 class Time; | 36 class Time; |
| 36 class TimeDelta; | 37 class TimeDelta; |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace content { | 40 namespace content { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 public: | 96 public: |
| 96 virtual void OnDownloadUpdated(DownloadItem* download) {} | 97 virtual void OnDownloadUpdated(DownloadItem* download) {} |
| 97 virtual void OnDownloadOpened(DownloadItem* download) {} | 98 virtual void OnDownloadOpened(DownloadItem* download) {} |
| 98 virtual void OnDownloadRemoved(DownloadItem* download) {} | 99 virtual void OnDownloadRemoved(DownloadItem* download) {} |
| 99 | 100 |
| 100 // Called when the download is being destroyed. This happens after | 101 // Called when the download is being destroyed. This happens after |
| 101 // every OnDownloadRemoved() as well as when the DownloadManager is going | 102 // every OnDownloadRemoved() as well as when the DownloadManager is going |
| 102 // down. | 103 // down. |
| 103 virtual void OnDownloadDestroyed(DownloadItem* download) {} | 104 virtual void OnDownloadDestroyed(DownloadItem* download) {} |
| 104 | 105 |
| 106 // Support for download interruptions. |
| 107 virtual void OnDownloadInterrupted(DownloadItem* download) {} |
| 108 virtual void OnDownloadResumed(DownloadItem* download) {} |
| 109 |
| 105 protected: | 110 protected: |
| 106 virtual ~Observer() {} | 111 virtual ~Observer() {} |
| 107 }; | 112 }; |
| 108 | 113 |
| 109 virtual ~DownloadItem() {} | 114 virtual ~DownloadItem() {} |
| 110 | 115 |
| 111 // Observation --------------------------------------------------------------- | 116 // Observation --------------------------------------------------------------- |
| 112 | 117 |
| 113 virtual void AddObserver(DownloadItem::Observer* observer) = 0; | 118 virtual void AddObserver(DownloadItem::Observer* observer) = 0; |
| 114 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; | 119 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // State accessors ----------------------------------------------------------- | 155 // State accessors ----------------------------------------------------------- |
| 151 | 156 |
| 152 virtual int32 GetId() const = 0; | 157 virtual int32 GetId() const = 0; |
| 153 virtual DownloadId GetGlobalId() const = 0; | 158 virtual DownloadId GetGlobalId() const = 0; |
| 154 virtual DownloadState GetState() const = 0; | 159 virtual DownloadState GetState() const = 0; |
| 155 | 160 |
| 156 // Only valid if |GetState() == DownloadItem::INTERRUPTED|. | 161 // Only valid if |GetState() == DownloadItem::INTERRUPTED|. |
| 157 virtual DownloadInterruptReason GetLastReason() const = 0; | 162 virtual DownloadInterruptReason GetLastReason() const = 0; |
| 158 | 163 |
| 159 virtual bool IsPaused() const = 0; | 164 virtual bool IsPaused() const = 0; |
| 165 virtual bool CanResumeInterrupted() const = 0; |
| 160 virtual bool IsTemporary() const = 0; | 166 virtual bool IsTemporary() const = 0; |
| 161 | 167 |
| 162 // Convenience routines for accessing GetState() results conceptually ----- | 168 // Convenience routines for accessing GetState() results conceptually ----- |
| 163 | 169 |
| 164 // Returns true if the download needs more data. | 170 // Returns true if the download needs more data. |
| 165 virtual bool IsPartialDownload() const = 0; | 171 virtual bool IsPartialDownload() const = 0; |
| 166 | 172 |
| 167 // Returns true if the download is still receiving data. | 173 // Returns true if the download is still receiving data. |
| 168 virtual bool IsInProgress() const = 0; | 174 virtual bool IsInProgress() const = 0; |
| 169 | 175 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 virtual base::Time GetEndTime() const = 0; | 276 virtual base::Time GetEndTime() const = 0; |
| 271 | 277 |
| 272 // Open/Show State accessors ---------------------------------------------- | 278 // Open/Show State accessors ---------------------------------------------- |
| 273 | 279 |
| 274 // Returns true if it is OK to open a folder which this file is inside. | 280 // Returns true if it is OK to open a folder which this file is inside. |
| 275 virtual bool CanShowInFolder() = 0; | 281 virtual bool CanShowInFolder() = 0; |
| 276 | 282 |
| 277 // Returns true if it is OK to open the download. | 283 // Returns true if it is OK to open the download. |
| 278 virtual bool CanOpenDownload() = 0; | 284 virtual bool CanOpenDownload() = 0; |
| 279 | 285 |
| 286 // Returns true if the download is paused or interrupted, and can be resumed. |
| 287 virtual bool CanResumeDownload() const = 0; |
| 288 |
| 280 // Tests if a file type should be opened automatically. | 289 // Tests if a file type should be opened automatically. |
| 281 virtual bool ShouldOpenFileBasedOnExtension() = 0; | 290 virtual bool ShouldOpenFileBasedOnExtension() = 0; |
| 282 | 291 |
| 283 // Returns true if the download will be auto-opened when complete. | 292 // Returns true if the download will be auto-opened when complete. |
| 284 virtual bool GetOpenWhenComplete() const = 0; | 293 virtual bool GetOpenWhenComplete() const = 0; |
| 285 | 294 |
| 286 // Returns true if the download has been auto-opened by the system. | 295 // Returns true if the download has been auto-opened by the system. |
| 287 virtual bool GetAutoOpened() = 0; | 296 virtual bool GetAutoOpened() = 0; |
| 288 | 297 |
| 289 // Returns true if the download has been opened. | 298 // Returns true if the download has been opened. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 312 | 321 |
| 313 // Mark the download as having been opened (without actually opening it). | 322 // Mark the download as having been opened (without actually opening it). |
| 314 virtual void SetOpened(bool opened) = 0; | 323 virtual void SetOpened(bool opened) = 0; |
| 315 | 324 |
| 316 // Set a display name for the download that will be independent of the target | 325 // Set a display name for the download that will be independent of the target |
| 317 // filename. If |name| is not empty, then GetFileNameToReportUser() will | 326 // filename. If |name| is not empty, then GetFileNameToReportUser() will |
| 318 // return |name|. Has no effect on the final target filename. | 327 // return |name|. Has no effect on the final target filename. |
| 319 virtual void SetDisplayName(const FilePath& name) = 0; | 328 virtual void SetDisplayName(const FilePath& name) = 0; |
| 320 | 329 |
| 321 // Debug/testing ------------------------------------------------------------- | 330 // Debug/testing ------------------------------------------------------------- |
| 331 // Gets the BoundNetLog associated with this download. |
| 332 virtual const net::BoundNetLog& GetBoundNetLog() const = 0; |
| 333 |
| 322 virtual std::string DebugString(bool verbose) const = 0; | 334 virtual std::string DebugString(bool verbose) const = 0; |
| 323 virtual void MockDownloadOpenForTesting() = 0; | 335 virtual void MockDownloadOpenForTesting() = 0; |
| 324 }; | 336 }; |
| 325 | 337 |
| 326 } // namespace content | 338 } // namespace content |
| 327 | 339 |
| 328 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 340 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
| OLD | NEW |