| 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 // 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_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| 18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| 19 #pragma once | 19 #pragma once |
| 20 | 20 |
| 21 #include <string> | 21 #include <string> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
| 25 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/observer_list.h" | 26 #include "base/observer_list.h" |
| 26 #include "base/time.h" | 27 #include "base/time.h" |
| 27 #include "base/timer.h" | 28 #include "base/timer.h" |
| 28 #include "content/browser/download/download_request_handle.h" | 29 #include "content/browser/download/download_request_handle.h" |
| 29 #include "content/browser/download/download_state_info.h" | 30 #include "content/browser/download/download_state_info.h" |
| 30 #include "content/browser/download/interrupt_reasons.h" | 31 #include "content/browser/download/interrupt_reasons.h" |
| 31 #include "content/common/content_export.h" | 32 #include "content/common/content_export.h" |
| 32 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
| 33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 34 | 35 |
| 35 class DownloadFileManager; | 36 class DownloadFileManager; |
| 36 class DownloadId; | 37 class DownloadId; |
| 37 class DownloadManager; | 38 class DownloadManager; |
| 39 class TabContents; |
| 40 |
| 38 struct DownloadCreateInfo; | 41 struct DownloadCreateInfo; |
| 39 struct DownloadPersistentStoreInfo; | 42 struct DownloadPersistentStoreInfo; |
| 40 | 43 |
| 41 // One DownloadItem per download. This is the model class that stores all the | 44 // One DownloadItem per download. This is the model class that stores all the |
| 42 // state for a download. Multiple views, such as a tab's download shelf and the | 45 // state for a download. Multiple views, such as a tab's download shelf and the |
| 43 // Destination tab's download view, may refer to a given DownloadItem. | 46 // Destination tab's download view, may refer to a given DownloadItem. |
| 44 // | 47 // |
| 45 // This is intended to be used only on the UI thread. | 48 // This is intended to be used only on the UI thread. |
| 46 class CONTENT_EXPORT DownloadItem { | 49 class CONTENT_EXPORT DownloadItem { |
| 47 public: | 50 public: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 virtual void OnDownloadOpened(DownloadItem* download) = 0; | 112 virtual void OnDownloadOpened(DownloadItem* download) = 0; |
| 110 | 113 |
| 111 protected: | 114 protected: |
| 112 virtual ~Observer() {} | 115 virtual ~Observer() {} |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 // Constructing from persistent store: | 118 // Constructing from persistent store: |
| 116 DownloadItem(DownloadManager* download_manager, | 119 DownloadItem(DownloadManager* download_manager, |
| 117 const DownloadPersistentStoreInfo& info); | 120 const DownloadPersistentStoreInfo& info); |
| 118 | 121 |
| 119 // Constructing for a regular download: | 122 // Constructing for a regular download. |
| 123 // Takes ownership of the object pointed to by |request_handle|. |
| 120 DownloadItem(DownloadManager* download_manager, | 124 DownloadItem(DownloadManager* download_manager, |
| 121 const DownloadCreateInfo& info, | 125 const DownloadCreateInfo& info, |
| 122 const DownloadRequestHandle& request_handle, | 126 DownloadRequestHandleInterface* request_handle, |
| 123 bool is_otr); | 127 bool is_otr); |
| 124 | 128 |
| 125 // Constructing for the "Save Page As..." feature: | 129 // Constructing for the "Save Page As..." feature: |
| 126 DownloadItem(DownloadManager* download_manager, | 130 DownloadItem(DownloadManager* download_manager, |
| 127 const FilePath& path, | 131 const FilePath& path, |
| 128 const GURL& url, | 132 const GURL& url, |
| 129 bool is_otr, | 133 bool is_otr, |
| 130 DownloadId download_id); | 134 DownloadId download_id); |
| 131 | 135 |
| 132 virtual ~DownloadItem(); | 136 virtual ~DownloadItem(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool is_otr() const { return is_otr_; } | 307 bool is_otr() const { return is_otr_; } |
| 304 const FilePath& suggested_path() const { return state_info_.suggested_path; } | 308 const FilePath& suggested_path() const { return state_info_.suggested_path; } |
| 305 bool is_temporary() const { return is_temporary_; } | 309 bool is_temporary() const { return is_temporary_; } |
| 306 void set_opened(bool opened) { opened_ = opened; } | 310 void set_opened(bool opened) { opened_ = opened; } |
| 307 bool opened() const { return opened_; } | 311 bool opened() const { return opened_; } |
| 308 | 312 |
| 309 InterruptReason last_reason() const { return last_reason_; } | 313 InterruptReason last_reason() const { return last_reason_; } |
| 310 | 314 |
| 311 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; | 315 DownloadPersistentStoreInfo GetPersistentStoreInfo() const; |
| 312 DownloadStateInfo state_info() const { return state_info_; } | 316 DownloadStateInfo state_info() const { return state_info_; } |
| 313 const DownloadRequestHandle& request_handle() const { | 317 |
| 314 return request_handle_; | 318 TabContents* GetTabContents() const; |
| 315 } | |
| 316 | 319 |
| 317 // Returns the final target file path for the download. | 320 // Returns the final target file path for the download. |
| 318 FilePath GetTargetFilePath() const; | 321 FilePath GetTargetFilePath() const; |
| 319 | 322 |
| 320 // Returns the file-name that should be reported to the user, which is | 323 // Returns the file-name that should be reported to the user, which is |
| 321 // target_name possibly with the uniquifier number. | 324 // target_name possibly with the uniquifier number. |
| 322 FilePath GetFileNameToReportUser() const; | 325 FilePath GetFileNameToReportUser() const; |
| 323 | 326 |
| 324 // Returns the user-verified target file path for the download. | 327 // Returns the user-verified target file path for the download. |
| 325 // This returns the same path as GetTargetFilePath() for safe downloads | 328 // This returns the same path as GetTargetFilePath() for safe downloads |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // Helper function to recompute |state_info_.target_name| when | 372 // Helper function to recompute |state_info_.target_name| when |
| 370 // it may have changed. (If it's non-null it should be left alone, | 373 // it may have changed. (If it's non-null it should be left alone, |
| 371 // otherwise updated from |full_path_|.) | 374 // otherwise updated from |full_path_|.) |
| 372 void UpdateTarget(); | 375 void UpdateTarget(); |
| 373 | 376 |
| 374 // State information used by the download manager. | 377 // State information used by the download manager. |
| 375 DownloadStateInfo state_info_; | 378 DownloadStateInfo state_info_; |
| 376 | 379 |
| 377 // The handle to the request information. Used for operations outside the | 380 // The handle to the request information. Used for operations outside the |
| 378 // download system. | 381 // download system. |
| 379 DownloadRequestHandle request_handle_; | 382 scoped_ptr<DownloadRequestHandleInterface> request_handle_; |
| 380 | 383 |
| 381 // Download ID assigned by DownloadResourceHandler. | 384 // Download ID assigned by DownloadResourceHandler. |
| 382 int32 download_id_; | 385 int32 download_id_; |
| 383 | 386 |
| 384 // Full path to the downloaded or downloading file. | 387 // Full path to the downloaded or downloading file. |
| 385 FilePath full_path_; | 388 FilePath full_path_; |
| 386 | 389 |
| 387 // A number that should be appended to the path to make it unique, or 0 if the | 390 // A number that should be appended to the path to make it unique, or 0 if the |
| 388 // path should be used as is. | 391 // path should be used as is. |
| 389 int path_uniquifier_; | 392 int path_uniquifier_; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // only. | 487 // only. |
| 485 bool open_enabled_; | 488 bool open_enabled_; |
| 486 | 489 |
| 487 // Did the delegate delay calling Complete on this download? | 490 // Did the delegate delay calling Complete on this download? |
| 488 bool delegate_delayed_complete_; | 491 bool delegate_delayed_complete_; |
| 489 | 492 |
| 490 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 493 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 491 }; | 494 }; |
| 492 | 495 |
| 493 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 496 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |