| 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 #include <iostream> |
| 22 | 23 |
| 23 #include "base/basictypes.h" | 24 #include "base/basictypes.h" |
| 24 #include "base/file_path.h" | 25 #include "base/file_path.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/common/notification_observer.h" | 31 #include "content/common/notification_observer.h" |
| 31 #include "content/common/notification_registrar.h" | 32 #include "content/common/notification_registrar.h" |
| 32 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
| 33 | 34 |
| 34 class CrxInstaller; | 35 class CrxInstaller; |
| 35 class DownloadFileManager; | 36 class DownloadFileManager; |
| 37 class DownloadId; |
| 36 class DownloadManager; | 38 class DownloadManager; |
| 37 struct DownloadCreateInfo; | 39 struct DownloadCreateInfo; |
| 38 struct DownloadPersistentStoreInfo; | 40 struct DownloadPersistentStoreInfo; |
| 39 | 41 |
| 40 // One DownloadItem per download. This is the model class that stores all the | 42 // One DownloadItem per download. This is the model class that stores all the |
| 41 // state for a download. Multiple views, such as a tab's download shelf and the | 43 // state for a download. Multiple views, such as a tab's download shelf and the |
| 42 // Destination tab's download view, may refer to a given DownloadItem. | 44 // Destination tab's download view, may refer to a given DownloadItem. |
| 43 // | 45 // |
| 44 // This is intended to be used only on the UI thread. | 46 // This is intended to be used only on the UI thread. |
| 45 class DownloadItem : public NotificationObserver { | 47 class DownloadItem : public NotificationObserver { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Constructing for a regular download: | 120 // Constructing for a regular download: |
| 119 DownloadItem(DownloadManager* download_manager, | 121 DownloadItem(DownloadManager* download_manager, |
| 120 const DownloadCreateInfo& info, | 122 const DownloadCreateInfo& info, |
| 121 bool is_otr); | 123 bool is_otr); |
| 122 | 124 |
| 123 // Constructing for the "Save Page As..." feature: | 125 // Constructing for the "Save Page As..." feature: |
| 124 DownloadItem(DownloadManager* download_manager, | 126 DownloadItem(DownloadManager* download_manager, |
| 125 const FilePath& path, | 127 const FilePath& path, |
| 126 const GURL& url, | 128 const GURL& url, |
| 127 bool is_otr, | 129 bool is_otr, |
| 128 int download_id); | 130 DownloadId download_id); |
| 129 | 131 |
| 130 virtual ~DownloadItem(); | 132 virtual ~DownloadItem(); |
| 131 | 133 |
| 132 void AddObserver(Observer* observer); | 134 void AddObserver(Observer* observer); |
| 133 void RemoveObserver(Observer* observer); | 135 void RemoveObserver(Observer* observer); |
| 134 | 136 |
| 135 // Notifies our observers periodically. | 137 // Notifies our observers periodically. |
| 136 void UpdateObservers(); | 138 void UpdateObservers(); |
| 137 | 139 |
| 138 // NotificationObserver implementation. | 140 // NotificationObserver implementation. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 std::string content_disposition() const { return content_disposition_; } | 272 std::string content_disposition() const { return content_disposition_; } |
| 271 std::string mime_type() const { return mime_type_; } | 273 std::string mime_type() const { return mime_type_; } |
| 272 std::string original_mime_type() const { return original_mime_type_; } | 274 std::string original_mime_type() const { return original_mime_type_; } |
| 273 std::string referrer_charset() const { return referrer_charset_; } | 275 std::string referrer_charset() const { return referrer_charset_; } |
| 274 int64 total_bytes() const { return total_bytes_; } | 276 int64 total_bytes() const { return total_bytes_; } |
| 275 void set_total_bytes(int64 total_bytes) { | 277 void set_total_bytes(int64 total_bytes) { |
| 276 total_bytes_ = total_bytes; | 278 total_bytes_ = total_bytes; |
| 277 } | 279 } |
| 278 int64 received_bytes() const { return received_bytes_; } | 280 int64 received_bytes() const { return received_bytes_; } |
| 279 int32 id() const { return download_id_; } | 281 int32 id() const { return download_id_; } |
| 282 DownloadId global_id() const; |
| 280 base::Time start_time() const { return start_time_; } | 283 base::Time start_time() const { return start_time_; } |
| 281 void set_db_handle(int64 handle) { db_handle_ = handle; } | 284 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 282 int64 db_handle() const { return db_handle_; } | 285 int64 db_handle() const { return db_handle_; } |
| 283 DownloadManager* download_manager() { return download_manager_; } | 286 DownloadManager* download_manager() { return download_manager_; } |
| 284 bool is_paused() const { return is_paused_; } | 287 bool is_paused() const { return is_paused_; } |
| 285 bool open_when_complete() const { return open_when_complete_; } | 288 bool open_when_complete() const { return open_when_complete_; } |
| 286 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 289 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 287 bool file_externally_removed() const { return file_externally_removed_; } | 290 bool file_externally_removed() const { return file_externally_removed_; } |
| 288 SafetyState safety_state() const { return safety_state_; } | 291 SafetyState safety_state() const { return safety_state_; } |
| 289 // Why |safety_state_| is not SAFE. | 292 // Why |safety_state_| is not SAFE. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // only. | 488 // only. |
| 486 bool open_enabled_; | 489 bool open_enabled_; |
| 487 | 490 |
| 488 // DownloadItem observes CRX installs it initiates. | 491 // DownloadItem observes CRX installs it initiates. |
| 489 NotificationRegistrar registrar_; | 492 NotificationRegistrar registrar_; |
| 490 | 493 |
| 491 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 494 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 492 }; | 495 }; |
| 493 | 496 |
| 494 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 497 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |