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 #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 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "content/browser/download/download_net_log_parameters.h" | 19 #include "content/browser/download/download_net_log_parameters.h" |
18 #include "content/browser/download/download_request_handle.h" | 20 #include "content/browser/download/download_request_handle.h" |
19 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
20 #include "content/public/browser/download_destination_observer.h" | 22 #include "content/public/browser/download_destination_observer.h" |
21 #include "content/public/browser/download_interrupt_reasons.h" | 23 #include "content/public/browser/download_interrupt_reasons.h" |
22 #include "content/public/browser/download_item.h" | 24 #include "content/public/browser/download_item.h" |
(...skipping 20 matching lines...) Expand all Loading... |
43 // The maximum number of attempts we will make to resume automatically. | 45 // The maximum number of attempts we will make to resume automatically. |
44 static const int kMaxAutoResumeAttempts; | 46 static const int kMaxAutoResumeAttempts; |
45 | 47 |
46 // Note that it is the responsibility of the caller to ensure that a | 48 // Note that it is the responsibility of the caller to ensure that a |
47 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor | 49 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor |
48 // outlives the DownloadItemImpl. | 50 // outlives the DownloadItemImpl. |
49 | 51 |
50 // Constructing from persistent store: | 52 // Constructing from persistent store: |
51 // |bound_net_log| is constructed externally for our use. | 53 // |bound_net_log| is constructed externally for our use. |
52 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 54 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
53 uint32 id, | 55 uint32_t id, |
54 const base::FilePath& current_path, | 56 const base::FilePath& current_path, |
55 const base::FilePath& target_path, | 57 const base::FilePath& target_path, |
56 const std::vector<GURL>& url_chain, | 58 const std::vector<GURL>& url_chain, |
57 const GURL& referrer_url, | 59 const GURL& referrer_url, |
58 const std::string& mime_type, | 60 const std::string& mime_type, |
59 const std::string& original_mime_type, | 61 const std::string& original_mime_type, |
60 const base::Time& start_time, | 62 const base::Time& start_time, |
61 const base::Time& end_time, | 63 const base::Time& end_time, |
62 const std::string& etag, | 64 const std::string& etag, |
63 const std::string& last_modified, | 65 const std::string& last_modified, |
64 int64 received_bytes, | 66 int64_t received_bytes, |
65 int64 total_bytes, | 67 int64_t total_bytes, |
66 DownloadItem::DownloadState state, | 68 DownloadItem::DownloadState state, |
67 DownloadDangerType danger_type, | 69 DownloadDangerType danger_type, |
68 DownloadInterruptReason interrupt_reason, | 70 DownloadInterruptReason interrupt_reason, |
69 bool opened, | 71 bool opened, |
70 const net::BoundNetLog& bound_net_log); | 72 const net::BoundNetLog& bound_net_log); |
71 | 73 |
72 // Constructing for a regular download. | 74 // Constructing for a regular download. |
73 // |bound_net_log| is constructed externally for our use. | 75 // |bound_net_log| is constructed externally for our use. |
74 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 76 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
75 uint32 id, | 77 uint32_t id, |
76 const DownloadCreateInfo& info, | 78 const DownloadCreateInfo& info, |
77 const net::BoundNetLog& bound_net_log); | 79 const net::BoundNetLog& bound_net_log); |
78 | 80 |
79 // Constructing for the "Save Page As..." feature: | 81 // Constructing for the "Save Page As..." feature: |
80 // |bound_net_log| is constructed externally for our use. | 82 // |bound_net_log| is constructed externally for our use. |
81 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 83 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
82 uint32 id, | 84 uint32_t id, |
83 const base::FilePath& path, | 85 const base::FilePath& path, |
84 const GURL& url, | 86 const GURL& url, |
85 const std::string& mime_type, | 87 const std::string& mime_type, |
86 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 88 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
87 const net::BoundNetLog& bound_net_log); | 89 const net::BoundNetLog& bound_net_log); |
88 | 90 |
89 ~DownloadItemImpl() override; | 91 ~DownloadItemImpl() override; |
90 | 92 |
91 // DownloadItem | 93 // DownloadItem |
92 void AddObserver(DownloadItem::Observer* observer) override; | 94 void AddObserver(DownloadItem::Observer* observer) override; |
93 void RemoveObserver(DownloadItem::Observer* observer) override; | 95 void RemoveObserver(DownloadItem::Observer* observer) override; |
94 void UpdateObservers() override; | 96 void UpdateObservers() override; |
95 void ValidateDangerousDownload() override; | 97 void ValidateDangerousDownload() override; |
96 void StealDangerousDownload(const AcquireFileCallback& callback) override; | 98 void StealDangerousDownload(const AcquireFileCallback& callback) override; |
97 void Pause() override; | 99 void Pause() override; |
98 void Resume() override; | 100 void Resume() override; |
99 void Cancel(bool user_cancel) override; | 101 void Cancel(bool user_cancel) override; |
100 void Remove() override; | 102 void Remove() override; |
101 void OpenDownload() override; | 103 void OpenDownload() override; |
102 void ShowDownloadInShell() override; | 104 void ShowDownloadInShell() override; |
103 uint32 GetId() const override; | 105 uint32_t GetId() const override; |
104 DownloadState GetState() const override; | 106 DownloadState GetState() const override; |
105 DownloadInterruptReason GetLastReason() const override; | 107 DownloadInterruptReason GetLastReason() const override; |
106 bool IsPaused() const override; | 108 bool IsPaused() const override; |
107 bool IsTemporary() const override; | 109 bool IsTemporary() const override; |
108 bool CanResume() const override; | 110 bool CanResume() const override; |
109 bool IsDone() const override; | 111 bool IsDone() const override; |
110 const GURL& GetURL() const override; | 112 const GURL& GetURL() const override; |
111 const std::vector<GURL>& GetUrlChain() const override; | 113 const std::vector<GURL>& GetUrlChain() const override; |
112 const GURL& GetOriginalUrl() const override; | 114 const GURL& GetOriginalUrl() const override; |
113 const GURL& GetReferrerUrl() const override; | 115 const GURL& GetReferrerUrl() const override; |
(...skipping 14 matching lines...) Expand all Loading... |
128 const base::FilePath& GetForcedFilePath() const override; | 130 const base::FilePath& GetForcedFilePath() const override; |
129 base::FilePath GetFileNameToReportUser() const override; | 131 base::FilePath GetFileNameToReportUser() const override; |
130 TargetDisposition GetTargetDisposition() const override; | 132 TargetDisposition GetTargetDisposition() const override; |
131 const std::string& GetHash() const override; | 133 const std::string& GetHash() const override; |
132 const std::string& GetHashState() const override; | 134 const std::string& GetHashState() const override; |
133 bool GetFileExternallyRemoved() const override; | 135 bool GetFileExternallyRemoved() const override; |
134 void DeleteFile(const base::Callback<void(bool)>& callback) override; | 136 void DeleteFile(const base::Callback<void(bool)>& callback) override; |
135 bool IsDangerous() const override; | 137 bool IsDangerous() const override; |
136 DownloadDangerType GetDangerType() const override; | 138 DownloadDangerType GetDangerType() const override; |
137 bool TimeRemaining(base::TimeDelta* remaining) const override; | 139 bool TimeRemaining(base::TimeDelta* remaining) const override; |
138 int64 CurrentSpeed() const override; | 140 int64_t CurrentSpeed() const override; |
139 int PercentComplete() const override; | 141 int PercentComplete() const override; |
140 bool AllDataSaved() const override; | 142 bool AllDataSaved() const override; |
141 int64 GetTotalBytes() const override; | 143 int64_t GetTotalBytes() const override; |
142 int64 GetReceivedBytes() const override; | 144 int64_t GetReceivedBytes() const override; |
143 base::Time GetStartTime() const override; | 145 base::Time GetStartTime() const override; |
144 base::Time GetEndTime() const override; | 146 base::Time GetEndTime() const override; |
145 bool CanShowInFolder() override; | 147 bool CanShowInFolder() override; |
146 bool CanOpenDownload() override; | 148 bool CanOpenDownload() override; |
147 bool ShouldOpenFileBasedOnExtension() override; | 149 bool ShouldOpenFileBasedOnExtension() override; |
148 bool GetOpenWhenComplete() const override; | 150 bool GetOpenWhenComplete() const override; |
149 bool GetAutoOpened() override; | 151 bool GetAutoOpened() override; |
150 bool GetOpened() const override; | 152 bool GetOpened() const override; |
151 BrowserContext* GetBrowserContext() const override; | 153 BrowserContext* GetBrowserContext() const override; |
152 WebContents* GetWebContents() const override; | 154 WebContents* GetWebContents() const override; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // for use by download destinations. | 194 // for use by download destinations. |
193 virtual base::WeakPtr<DownloadDestinationObserver> | 195 virtual base::WeakPtr<DownloadDestinationObserver> |
194 DestinationObserverAsWeakPtr(); | 196 DestinationObserverAsWeakPtr(); |
195 | 197 |
196 // Get the download's BoundNetLog. | 198 // Get the download's BoundNetLog. |
197 virtual const net::BoundNetLog& GetBoundNetLog() const; | 199 virtual const net::BoundNetLog& GetBoundNetLog() const; |
198 | 200 |
199 // DownloadItemImpl routines only needed by SavePackage ---------------------- | 201 // DownloadItemImpl routines only needed by SavePackage ---------------------- |
200 | 202 |
201 // Called by SavePackage to set the total number of bytes on the item. | 203 // Called by SavePackage to set the total number of bytes on the item. |
202 virtual void SetTotalBytes(int64 total_bytes); | 204 virtual void SetTotalBytes(int64_t total_bytes); |
203 | 205 |
204 virtual void OnAllDataSaved(const std::string& final_hash); | 206 virtual void OnAllDataSaved(const std::string& final_hash); |
205 | 207 |
206 // Called by SavePackage to display progress when the DownloadItem | 208 // Called by SavePackage to display progress when the DownloadItem |
207 // should be considered complete. | 209 // should be considered complete. |
208 virtual void MarkAsComplete(); | 210 virtual void MarkAsComplete(); |
209 | 211 |
210 // DownloadDestinationObserver | 212 // DownloadDestinationObserver |
211 void DestinationUpdate(int64 bytes_so_far, | 213 void DestinationUpdate(int64_t bytes_so_far, |
212 int64 bytes_per_sec, | 214 int64_t bytes_per_sec, |
213 const std::string& hash_state) override; | 215 const std::string& hash_state) override; |
214 void DestinationError(DownloadInterruptReason reason) override; | 216 void DestinationError(DownloadInterruptReason reason) override; |
215 void DestinationCompleted(const std::string& final_hash) override; | 217 void DestinationCompleted(const std::string& final_hash) override; |
216 | 218 |
217 private: | 219 private: |
218 // Fine grained states of a download. Note that active downloads are created | 220 // Fine grained states of a download. Note that active downloads are created |
219 // in IN_PROGRESS_INTERNAL state. However, downloads creates via history can | 221 // in IN_PROGRESS_INTERNAL state. However, downloads creates via history can |
220 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and | 222 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and |
221 // INTERRUPTED_INTERNAL. | 223 // INTERRUPTED_INTERNAL. |
222 | 224 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 static const char* DebugResumeModeString(ResumeMode mode); | 388 static const char* DebugResumeModeString(ResumeMode mode); |
387 | 389 |
388 // Will be false for save package downloads retrieved from the history. | 390 // Will be false for save package downloads retrieved from the history. |
389 // TODO(rdsmith): Replace with a generalized enum for "download source". | 391 // TODO(rdsmith): Replace with a generalized enum for "download source". |
390 const bool is_save_package_download_; | 392 const bool is_save_package_download_; |
391 | 393 |
392 // The handle to the request information. Used for operations outside the | 394 // The handle to the request information. Used for operations outside the |
393 // download system. | 395 // download system. |
394 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | 396 scoped_ptr<DownloadRequestHandleInterface> request_handle_; |
395 | 397 |
396 uint32 download_id_; | 398 uint32_t download_id_; |
397 | 399 |
398 // Display name for the download. If this is empty, then the display name is | 400 // Display name for the download. If this is empty, then the display name is |
399 // considered to be |target_path_.BaseName()|. | 401 // considered to be |target_path_.BaseName()|. |
400 base::FilePath display_name_; | 402 base::FilePath display_name_; |
401 | 403 |
402 // Full path to the downloaded or downloading file. This is the path to the | 404 // Full path to the downloaded or downloading file. This is the path to the |
403 // physical file, if one exists. The final target path is specified by | 405 // physical file, if one exists. The final target path is specified by |
404 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't | 406 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't |
405 // been determined. | 407 // been determined. |
406 base::FilePath current_path_; | 408 base::FilePath current_path_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // The value of the content type header sent with the downloaded item. It | 452 // The value of the content type header sent with the downloaded item. It |
451 // may be different from |mime_type_|, which may be set based on heuristics | 453 // may be different from |mime_type_|, which may be set based on heuristics |
452 // which may look at the file extension and first few bytes of the file. | 454 // which may look at the file extension and first few bytes of the file. |
453 std::string original_mime_type_; | 455 std::string original_mime_type_; |
454 | 456 |
455 // The remote IP address where the download was fetched from. Copied from | 457 // The remote IP address where the download was fetched from. Copied from |
456 // DownloadCreateInfo::remote_address. | 458 // DownloadCreateInfo::remote_address. |
457 std::string remote_address_; | 459 std::string remote_address_; |
458 | 460 |
459 // Total bytes expected. | 461 // Total bytes expected. |
460 int64 total_bytes_; | 462 int64_t total_bytes_; |
461 | 463 |
462 // Current received bytes. | 464 // Current received bytes. |
463 int64 received_bytes_; | 465 int64_t received_bytes_; |
464 | 466 |
465 // Current speed. Calculated by the DownloadFile. | 467 // Current speed. Calculated by the DownloadFile. |
466 int64 bytes_per_sec_; | 468 int64_t bytes_per_sec_; |
467 | 469 |
468 // Sha256 hash of the content. This might be empty either because | 470 // Sha256 hash of the content. This might be empty either because |
469 // the download isn't done yet or because the hash isn't needed | 471 // the download isn't done yet or because the hash isn't needed |
470 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). | 472 // (ChromeDownloadManagerDelegate::GenerateFileHash() returned false). |
471 std::string hash_; | 473 std::string hash_; |
472 | 474 |
473 // A blob containing the state of the hash algorithm. Only valid while the | 475 // A blob containing the state of the hash algorithm. Only valid while the |
474 // download is in progress. | 476 // download is in progress. |
475 std::string hash_state_; | 477 std::string hash_state_; |
476 | 478 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 const net::BoundNetLog bound_net_log_; | 553 const net::BoundNetLog bound_net_log_; |
552 | 554 |
553 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 555 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
554 | 556 |
555 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 557 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
556 }; | 558 }; |
557 | 559 |
558 } // namespace content | 560 } // namespace content |
559 | 561 |
560 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 562 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
OLD | NEW |