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