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: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 enum TargetDisposition { | 75 enum TargetDisposition { |
76 TARGET_DISPOSITION_OVERWRITE, // Overwrite if the target already exists. | 76 TARGET_DISPOSITION_OVERWRITE, // Overwrite if the target already exists. |
77 TARGET_DISPOSITION_PROMPT // Prompt the user for the actual | 77 TARGET_DISPOSITION_PROMPT // Prompt the user for the actual |
78 // target. Implies | 78 // target. Implies |
79 // TARGET_DISPOSITION_OVERWRITE. | 79 // TARGET_DISPOSITION_OVERWRITE. |
80 }; | 80 }; |
81 | 81 |
82 // Callback used with AcquireFileAndDeleteDownload(). | 82 // Callback used with AcquireFileAndDeleteDownload(). |
83 typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback; | 83 typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback; |
84 | 84 |
85 // Used to represent an invalid download ID. | |
85 static const uint32_t kInvalidId; | 86 static const uint32_t kInvalidId; |
86 | 87 |
87 // Interface that observers of a particular download must implement in order | 88 // Interface that observers of a particular download must implement in order |
88 // to receive updates to the download's status. | 89 // to receive updates to the download's status. |
89 class CONTENT_EXPORT Observer { | 90 class CONTENT_EXPORT Observer { |
90 public: | 91 public: |
91 virtual void OnDownloadUpdated(DownloadItem* download) {} | 92 virtual void OnDownloadUpdated(DownloadItem* download) {} |
92 virtual void OnDownloadOpened(DownloadItem* download) {} | 93 virtual void OnDownloadOpened(DownloadItem* download) {} |
93 virtual void OnDownloadRemoved(DownloadItem* download) {} | 94 virtual void OnDownloadRemoved(DownloadItem* download) {} |
94 | 95 |
(...skipping 24 matching lines...) Expand all Loading... | |
119 // path to the downloaded file. The caller is responsible for cleanup. | 120 // path to the downloaded file. The caller is responsible for cleanup. |
120 // Note: It is important for |callback| to be valid since the downloaded file | 121 // Note: It is important for |callback| to be valid since the downloaded file |
121 // will not be cleaned up if the callback fails. | 122 // will not be cleaned up if the callback fails. |
122 virtual void StealDangerousDownload(const AcquireFileCallback& callback) = 0; | 123 virtual void StealDangerousDownload(const AcquireFileCallback& callback) = 0; |
123 | 124 |
124 // Pause a download. Will have no effect if the download is already | 125 // Pause a download. Will have no effect if the download is already |
125 // paused. | 126 // paused. |
126 virtual void Pause() = 0; | 127 virtual void Pause() = 0; |
127 | 128 |
128 // Resume a download that has been paused or interrupted. Will have no effect | 129 // Resume a download that has been paused or interrupted. Will have no effect |
129 // if the download is neither. | 130 // if the download is neither. Only does something if CanResume() returns |
131 // true. | |
130 virtual void Resume() = 0; | 132 virtual void Resume() = 0; |
131 | 133 |
132 // Cancel the download operation. We need to distinguish between cancels at | 134 // Cancel the download operation. |
133 // exit (DownloadManager destructor) from user interface initiated cancels | 135 // |
134 // because at exit, the history system may not exist, and any updates to it | 136 // Set |user_cancel| to true if the cancellation was triggered by an explicit |
135 // require AddRef'ing the DownloadManager in the destructor which results in | 137 // user action. Non-user-initiated cancels typically happen when the browser |
136 // a DCHECK failure. Set |user_cancel| to false when canceling from at | 138 // is being closed with in-progress downloads. |
137 // exit to prevent this crash. This may result in a difference between the | |
138 // downloaded file's size on disk, and what the history system's last record | |
139 // of it is. At worst, we'll end up re-downloading a small portion of the file | |
140 // when resuming a download (assuming the server supports byte ranges). | |
141 virtual void Cancel(bool user_cancel) = 0; | 139 virtual void Cancel(bool user_cancel) = 0; |
142 | 140 |
143 // Removes the download from the views and history. If the download was | 141 // Removes the download from the views and history. If the download was |
144 // in-progress or interrupted, then the intermediate file will also be | 142 // in-progress or interrupted, then the intermediate file will also be |
145 // deleted. | 143 // deleted. |
146 virtual void Remove() = 0; | 144 virtual void Remove() = 0; |
147 | 145 |
148 // Open the file associated with this download. If the download is | 146 // Open the file associated with this download. If the download is |
149 // still in progress, marks the download to be opened when it is complete. | 147 // still in progress, marks the download to be opened when it is complete. |
150 virtual void OpenDownload() = 0; | 148 virtual void OpenDownload() = 0; |
151 | 149 |
152 // Show the download via the OS shell. | 150 // Show the download via the OS shell. |
153 virtual void ShowDownloadInShell() = 0; | 151 virtual void ShowDownloadInShell() = 0; |
154 | 152 |
155 // State accessors ----------------------------------------------------------- | 153 // State accessors ----------------------------------------------------------- |
156 | 154 |
157 // Retrieve the ID for this download. The ID is provided by the owner of the | 155 // Retrieve the ID for this download. The ID is provided by the owner of the |
158 // DownloadItem and is expected to uniquely identify the download within the | 156 // DownloadItem and is expected to uniquely identify the download within the |
159 // context of its container during the lifetime of the download. | 157 // context of its container during the lifetime of the download. A valid |
158 // download will never return |kInvalidId|. | |
160 virtual uint32_t GetId() const = 0; | 159 virtual uint32_t GetId() const = 0; |
161 | 160 |
162 // Retrieve the GUID for this download. The returned string is never empty and | 161 // Retrieve the GUID for this download. The returned string is never empty and |
163 // will satisfy base::IsValidGUID(), in addition to uniquely identifying the | 162 // will satisfy base::IsValidGUID(), and uniquely identifies the download |
clamy
2016/10/04 14:21:30
nit: remove comma?
asanka
2016/10/04 14:44:55
Done
| |
164 // download during its lifetime regardless of its container. | 163 // during its lifetime. |
165 virtual const std::string& GetGuid() const = 0; | 164 virtual const std::string& GetGuid() const = 0; |
166 | 165 |
167 // Get the current state of the download. See DownloadState for descriptions | 166 // Get the current state of the download. See DownloadState for descriptions |
168 // of each download state. | 167 // of each download state. |
169 virtual DownloadState GetState() const = 0; | 168 virtual DownloadState GetState() const = 0; |
170 | 169 |
171 // Returns the most recent interrupt reason for this download. Returns | 170 // Returns the most recent interrupt reason for this download. Returns |
172 // DOWNLOAD_INTERRUPT_REASON_NONE if there is no previous interrupt reason. | 171 // |DOWNLOAD_INTERRUPT_REASON_NONE| if there is no previous interrupt reason. |
173 // Cancelled downloads return DOWNLOAD_INTERRUPT_REASON_USER_CANCELLED. If | 172 // Interrupted downloads and resumed downloads return the last known interrupt |
174 // the download was resumed, then the return value is the interrupt reason | 173 // reason. |
175 // prior to resumption. | |
176 virtual DownloadInterruptReason GetLastReason() const = 0; | 174 virtual DownloadInterruptReason GetLastReason() const = 0; |
177 | 175 |
176 // The download is currently paused. Calling Resume() will transition out of | |
177 // this paused state. | |
178 virtual bool IsPaused() const = 0; | 178 virtual bool IsPaused() const = 0; |
179 | |
180 // DEPRECATED. True if this is a temporary download and should not be | |
181 // persisted. | |
179 virtual bool IsTemporary() const = 0; | 182 virtual bool IsTemporary() const = 0; |
180 | 183 |
181 // Returns true if the download can be resumed. A download can be resumed if | 184 // Returns true if the download can be resumed. A download can be resumed if |
182 // an in-progress download was paused or if an interrupted download requires | 185 // an in-progress download was paused or if an interrupted download requires |
183 // user-interaction to resume. | 186 // user-interaction to resume. |
184 virtual bool CanResume() const = 0; | 187 virtual bool CanResume() const = 0; |
185 | 188 |
186 // Returns true if the download is in a terminal state. This includes | 189 // Returns true if the download is in a terminal state. This includes |
187 // completed downloads, cancelled downloads, and interrupted downloads that | 190 // completed downloads, cancelled downloads, and interrupted downloads that |
188 // can't be resumed. | 191 // can't be resumed. |
189 virtual bool IsDone() const = 0; | 192 virtual bool IsDone() const = 0; |
190 | 193 |
191 // Origin State accessors ------------------------------------------------- | 194 // Origin State accessors ------------------------------------------------- |
192 | 195 |
196 // Final URL. The primary resource being downloaded is from this URL. This is | |
197 // the tail of GetUrlChain(). May return an empty GURL if there is no valid | |
198 // download URL. | |
193 virtual const GURL& GetURL() const = 0; | 199 virtual const GURL& GetURL() const = 0; |
200 | |
201 // The complete URL chain including redirects. URL at index i redirected to | |
202 // URL at index i+1. | |
194 virtual const std::vector<GURL>& GetUrlChain() const = 0; | 203 virtual const std::vector<GURL>& GetUrlChain() const = 0; |
204 | |
205 // The URL that the download request originally attempted to fetch. This may | |
206 // defer from GetURL() if there were redirects. The return value from this | |
clamy
2016/10/04 14:21:29
nit: s/defer/differ
asanka
2016/10/04 14:44:55
Done
| |
207 // accessor is the same as the head of GetUrlChain(). | |
195 virtual const GURL& GetOriginalUrl() const = 0; | 208 virtual const GURL& GetOriginalUrl() const = 0; |
209 | |
210 // URL of document that is considered the referrer for the original URL. | |
196 virtual const GURL& GetReferrerUrl() const = 0; | 211 virtual const GURL& GetReferrerUrl() const = 0; |
212 | |
213 // Site instance URL. Used to locate the correct storage partition during | |
214 // subsequent browser sessions. | |
clamy
2016/10/04 14:21:30
nit: mention that it may be different from the cur
asanka
2016/10/04 14:44:55
Done
| |
197 virtual const GURL& GetSiteUrl() const = 0; | 215 virtual const GURL& GetSiteUrl() const = 0; |
216 | |
217 // URL of the top level frame at the time the download was initiated. | |
198 virtual const GURL& GetTabUrl() const = 0; | 218 virtual const GURL& GetTabUrl() const = 0; |
219 | |
220 // Referrer URL for top level frame. | |
199 virtual const GURL& GetTabReferrerUrl() const = 0; | 221 virtual const GURL& GetTabReferrerUrl() const = 0; |
222 | |
223 // For downloads initiated via <a download>, this is the suggested download | |
224 // filename from the download attribute. | |
200 virtual std::string GetSuggestedFilename() const = 0; | 225 virtual std::string GetSuggestedFilename() const = 0; |
226 | |
227 // Content-Disposition header value from HTTP response. | |
201 virtual std::string GetContentDisposition() const = 0; | 228 virtual std::string GetContentDisposition() const = 0; |
229 | |
230 // Effective MIME type of downloaded content. | |
202 virtual std::string GetMimeType() const = 0; | 231 virtual std::string GetMimeType() const = 0; |
232 | |
233 // Content-Type header value from HTTP response. May be different from | |
234 // GetMimeType() if a different effective MIME type was chosen after MIME | |
235 // sniffing. | |
203 virtual std::string GetOriginalMimeType() const = 0; | 236 virtual std::string GetOriginalMimeType() const = 0; |
237 | |
238 // Remote address of server serving download contents. | |
204 virtual std::string GetRemoteAddress() const = 0; | 239 virtual std::string GetRemoteAddress() const = 0; |
240 | |
241 // Whether the download request was initiated in response to a user gesture. | |
205 virtual bool HasUserGesture() const = 0; | 242 virtual bool HasUserGesture() const = 0; |
243 | |
244 // The page transition type associated with the download request. | |
206 virtual ui::PageTransition GetTransitionType() const = 0; | 245 virtual ui::PageTransition GetTransitionType() const = 0; |
246 | |
247 // Last-Modified header value. | |
207 virtual const std::string& GetLastModifiedTime() const = 0; | 248 virtual const std::string& GetLastModifiedTime() const = 0; |
249 | |
250 // ETag header value. | |
208 virtual const std::string& GetETag() const = 0; | 251 virtual const std::string& GetETag() const = 0; |
252 | |
253 // Whether this download is a SavePackage download. | |
209 virtual bool IsSavePackageDownload() const = 0; | 254 virtual bool IsSavePackageDownload() const = 0; |
210 | 255 |
211 // Destination State accessors -------------------------------------------- | 256 // Destination State accessors -------------------------------------------- |
212 | 257 |
213 // Full path to the downloaded or downloading file. This is the path to the | 258 // Full path to the downloaded or downloading file. This is the path to the |
214 // physical file, if one exists. It should be considered a hint; changes to | 259 // physical file, if one exists. It should be considered a hint; changes to |
215 // this value and renames of the file on disk are not atomic with each other. | 260 // this value and renames of the file on disk are not atomic with each other. |
216 // May be empty if the in-progress path hasn't been determined yet or if the | 261 // May be empty if the in-progress path hasn't been determined yet or if the |
217 // download was interrupted. | 262 // download was interrupted. |
218 // | 263 // |
(...skipping 12 matching lines...) Expand all Loading... | |
231 | 276 |
232 // If the download forced a path rather than requesting name determination, | 277 // If the download forced a path rather than requesting name determination, |
233 // return the path requested. | 278 // return the path requested. |
234 virtual const base::FilePath& GetForcedFilePath() const = 0; | 279 virtual const base::FilePath& GetForcedFilePath() const = 0; |
235 | 280 |
236 // Returns the file-name that should be reported to the user. If a display | 281 // Returns the file-name that should be reported to the user. If a display |
237 // name has been explicitly set using SetDisplayName(), this function returns | 282 // name has been explicitly set using SetDisplayName(), this function returns |
238 // that display name. Otherwise returns the final target filename. | 283 // that display name. Otherwise returns the final target filename. |
239 virtual base::FilePath GetFileNameToReportUser() const = 0; | 284 virtual base::FilePath GetFileNameToReportUser() const = 0; |
240 | 285 |
286 // See TargetDisposition. | |
241 virtual TargetDisposition GetTargetDisposition() const = 0; | 287 virtual TargetDisposition GetTargetDisposition() const = 0; |
242 | 288 |
243 // Final hash of completely downloaded file, or partial hash of an interrupted | 289 // Final hash of completely downloaded file, or partial hash of an interrupted |
244 // download; only valid if GetState() == COMPLETED or INTERRUPTED. If | 290 // download; only valid if GetState() == COMPLETED or INTERRUPTED. If |
245 // non-empty the returned string contains a raw SHA-256 hash (i.e. not hex | 291 // non-empty the returned string contains a raw SHA-256 hash (i.e. not hex |
246 // encoded). | 292 // encoded). |
247 virtual const std::string& GetHash() const = 0; | 293 virtual const std::string& GetHash() const = 0; |
248 | 294 |
249 // True if the file associated with the download has been removed by | 295 // True if the file associated with the download has been removed by |
250 // external action. | 296 // external action. |
(...skipping 23 matching lines...) Expand all Loading... | |
274 | 320 |
275 // Simple calculation of the amount of time remaining to completion. Fills | 321 // Simple calculation of the amount of time remaining to completion. Fills |
276 // |*remaining| with the amount of time remaining if successful. Fails and | 322 // |*remaining| with the amount of time remaining if successful. Fails and |
277 // returns false if we do not have the number of bytes or the speed so can | 323 // returns false if we do not have the number of bytes or the speed so can |
278 // not estimate. | 324 // not estimate. |
279 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0; | 325 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0; |
280 | 326 |
281 // Simple speed estimate in bytes/s | 327 // Simple speed estimate in bytes/s |
282 virtual int64_t CurrentSpeed() const = 0; | 328 virtual int64_t CurrentSpeed() const = 0; |
283 | 329 |
284 // Rough percent complete, -1 means we don't know (== we didn't receive a | 330 // Rough percent complete. Returns -1 if progress is unknown. 100 if the |
285 // total size). | 331 // download is already complete. |
286 virtual int PercentComplete() const = 0; | 332 virtual int PercentComplete() const = 0; |
287 | 333 |
288 // Returns true if this download has saved all of its data. | 334 // Returns true if this download has saved all of its data. A download may |
335 // have saved all its data but still waiting for some other process to | |
clamy
2016/10/04 14:21:30
nit: s/still waiting/still be waiting
asanka
2016/10/04 14:44:55
Done
| |
336 // complete before the download is considered complete. E.g. A dangerous | |
337 // download needs to be accepted by the user before the file is renamed to its | |
338 // final name. | |
289 virtual bool AllDataSaved() const = 0; | 339 virtual bool AllDataSaved() const = 0; |
290 | 340 |
341 // Total number of expected bytes. Returns -1 if the total size is unknown. | |
291 virtual int64_t GetTotalBytes() const = 0; | 342 virtual int64_t GetTotalBytes() const = 0; |
343 | |
344 // Total number of bytes that have been received and written to the download | |
345 // file. | |
292 virtual int64_t GetReceivedBytes() const = 0; | 346 virtual int64_t GetReceivedBytes() const = 0; |
347 | |
348 // Time the download was first started. This timestamp is always valid and | |
349 // doesn't change. | |
293 virtual base::Time GetStartTime() const = 0; | 350 virtual base::Time GetStartTime() const = 0; |
351 | |
352 // Time the download was marked as complete. Returns base::Time() if the | |
353 // download hasn't reached a completion state yet. | |
294 virtual base::Time GetEndTime() const = 0; | 354 virtual base::Time GetEndTime() const = 0; |
295 | 355 |
296 // Open/Show State accessors ---------------------------------------------- | 356 // Open/Show State accessors ---------------------------------------------- |
297 | 357 |
298 // Returns true if it is OK to open a folder which this file is inside. | 358 // Returns true if it is OK to open a folder which this file is inside. |
299 virtual bool CanShowInFolder() = 0; | 359 virtual bool CanShowInFolder() = 0; |
300 | 360 |
301 // Returns true if it is OK to open the download. | 361 // Returns true if it is OK to open the download. |
302 virtual bool CanOpenDownload() = 0; | 362 virtual bool CanOpenDownload() = 0; |
303 | 363 |
304 // Tests if a file type should be opened automatically. | 364 // Tests if a file type should be opened automatically. |
305 virtual bool ShouldOpenFileBasedOnExtension() = 0; | 365 virtual bool ShouldOpenFileBasedOnExtension() = 0; |
306 | 366 |
307 // Returns true if the download will be auto-opened when complete. | 367 // Returns true if the download will be auto-opened when complete. |
308 virtual bool GetOpenWhenComplete() const = 0; | 368 virtual bool GetOpenWhenComplete() const = 0; |
309 | 369 |
310 // Returns true if the download has been auto-opened by the system. | 370 // Returns true if the download has been auto-opened by the system. |
311 virtual bool GetAutoOpened() = 0; | 371 virtual bool GetAutoOpened() = 0; |
312 | 372 |
313 // Returns true if the download has been opened. | 373 // Returns true if the download has been opened. |
314 virtual bool GetOpened() const = 0; | 374 virtual bool GetOpened() const = 0; |
315 | 375 |
316 // Misc State accessors --------------------------------------------------- | 376 // Misc State accessors --------------------------------------------------- |
317 | 377 |
378 // BrowserContext that indirectly owns this download. Always valid. | |
318 virtual BrowserContext* GetBrowserContext() const = 0; | 379 virtual BrowserContext* GetBrowserContext() const = 0; |
380 | |
381 // WebContents associated with the download. Returns nullptr if the | |
382 // WebContents is unknown or if the download was not performed on behalf of a | |
383 // renderer. | |
319 virtual WebContents* GetWebContents() const = 0; | 384 virtual WebContents* GetWebContents() const = 0; |
320 | 385 |
321 // External state transitions/setters ---------------------------------------- | 386 // External state transitions/setters ---------------------------------------- |
387 | |
322 // TODO(rdsmith): These should all be removed; the download item should | 388 // TODO(rdsmith): These should all be removed; the download item should |
323 // control its own state transitions. | 389 // control its own state transitions. |
324 | 390 |
325 // Called if a check of the download contents was performed and the results of | 391 // Called if a check of the download contents was performed and the results of |
326 // the test are available. This should only be called after AllDataSaved() is | 392 // the test are available. This should only be called after AllDataSaved() is |
327 // true. | 393 // true. |
328 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) = 0; | 394 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) = 0; |
329 | 395 |
330 // Mark the download to be auto-opened when completed. | 396 // Mark the download to be auto-opened when completed. |
331 virtual void SetOpenWhenComplete(bool open) = 0; | 397 virtual void SetOpenWhenComplete(bool open) = 0; |
332 | 398 |
333 // Mark the download as having been opened (without actually opening it). | 399 // Mark the download as having been opened (without actually opening it). |
334 virtual void SetOpened(bool opened) = 0; | 400 virtual void SetOpened(bool opened) = 0; |
335 | 401 |
336 // Set a display name for the download that will be independent of the target | 402 // Set a display name for the download that will be independent of the target |
337 // filename. If |name| is not empty, then GetFileNameToReportUser() will | 403 // filename. If |name| is not empty, then GetFileNameToReportUser() will |
338 // return |name|. Has no effect on the final target filename. | 404 // return |name|. Has no effect on the final target filename. |
339 virtual void SetDisplayName(const base::FilePath& name) = 0; | 405 virtual void SetDisplayName(const base::FilePath& name) = 0; |
340 | 406 |
341 // Debug/testing ------------------------------------------------------------- | 407 // Debug/testing ------------------------------------------------------------- |
342 virtual std::string DebugString(bool verbose) const = 0; | 408 virtual std::string DebugString(bool verbose) const = 0; |
343 }; | 409 }; |
344 | 410 |
345 } // namespace content | 411 } // namespace content |
346 | 412 |
347 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 413 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
OLD | NEW |