Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: content/public/browser/download_item.h

Issue 2388143002: [downloads] Document undocumented accessors in DownloadItem. (Closed)
Patch Set: Fix comma use, spelling, and other issues spotted by clamy@ Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 // differ from GetURL() if there were redirects. The return value from this
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. This may be different from all of
215 // GetOriginalUrl(), GetURL() and GetReferrerUrl().
197 virtual const GURL& GetSiteUrl() const = 0; 216 virtual const GURL& GetSiteUrl() const = 0;
217
218 // URL of the top level frame at the time the download was initiated.
198 virtual const GURL& GetTabUrl() const = 0; 219 virtual const GURL& GetTabUrl() const = 0;
220
221 // Referrer URL for top level frame.
199 virtual const GURL& GetTabReferrerUrl() const = 0; 222 virtual const GURL& GetTabReferrerUrl() const = 0;
223
224 // For downloads initiated via <a download>, this is the suggested download
225 // filename from the download attribute.
200 virtual std::string GetSuggestedFilename() const = 0; 226 virtual std::string GetSuggestedFilename() const = 0;
227
228 // Content-Disposition header value from HTTP response.
201 virtual std::string GetContentDisposition() const = 0; 229 virtual std::string GetContentDisposition() const = 0;
230
231 // Effective MIME type of downloaded content.
202 virtual std::string GetMimeType() const = 0; 232 virtual std::string GetMimeType() const = 0;
233
234 // Content-Type header value from HTTP response. May be different from
235 // GetMimeType() if a different effective MIME type was chosen after MIME
236 // sniffing.
203 virtual std::string GetOriginalMimeType() const = 0; 237 virtual std::string GetOriginalMimeType() const = 0;
238
239 // Remote address of server serving download contents.
204 virtual std::string GetRemoteAddress() const = 0; 240 virtual std::string GetRemoteAddress() const = 0;
241
242 // Whether the download request was initiated in response to a user gesture.
205 virtual bool HasUserGesture() const = 0; 243 virtual bool HasUserGesture() const = 0;
244
245 // The page transition type associated with the download request.
206 virtual ui::PageTransition GetTransitionType() const = 0; 246 virtual ui::PageTransition GetTransitionType() const = 0;
247
248 // Last-Modified header value.
207 virtual const std::string& GetLastModifiedTime() const = 0; 249 virtual const std::string& GetLastModifiedTime() const = 0;
250
251 // ETag header value.
208 virtual const std::string& GetETag() const = 0; 252 virtual const std::string& GetETag() const = 0;
253
254 // Whether this download is a SavePackage download.
209 virtual bool IsSavePackageDownload() const = 0; 255 virtual bool IsSavePackageDownload() const = 0;
210 256
211 // Destination State accessors -------------------------------------------- 257 // Destination State accessors --------------------------------------------
212 258
213 // Full path to the downloaded or downloading file. This is the path to the 259 // 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 260 // 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. 261 // 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 262 // May be empty if the in-progress path hasn't been determined yet or if the
217 // download was interrupted. 263 // download was interrupted.
218 // 264 //
(...skipping 12 matching lines...) Expand all
231 277
232 // If the download forced a path rather than requesting name determination, 278 // If the download forced a path rather than requesting name determination,
233 // return the path requested. 279 // return the path requested.
234 virtual const base::FilePath& GetForcedFilePath() const = 0; 280 virtual const base::FilePath& GetForcedFilePath() const = 0;
235 281
236 // Returns the file-name that should be reported to the user. If a display 282 // 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 283 // name has been explicitly set using SetDisplayName(), this function returns
238 // that display name. Otherwise returns the final target filename. 284 // that display name. Otherwise returns the final target filename.
239 virtual base::FilePath GetFileNameToReportUser() const = 0; 285 virtual base::FilePath GetFileNameToReportUser() const = 0;
240 286
287 // See TargetDisposition.
241 virtual TargetDisposition GetTargetDisposition() const = 0; 288 virtual TargetDisposition GetTargetDisposition() const = 0;
242 289
243 // Final hash of completely downloaded file, or partial hash of an interrupted 290 // Final hash of completely downloaded file, or partial hash of an interrupted
244 // download; only valid if GetState() == COMPLETED or INTERRUPTED. If 291 // 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 292 // non-empty the returned string contains a raw SHA-256 hash (i.e. not hex
246 // encoded). 293 // encoded).
247 virtual const std::string& GetHash() const = 0; 294 virtual const std::string& GetHash() const = 0;
248 295
249 // True if the file associated with the download has been removed by 296 // True if the file associated with the download has been removed by
250 // external action. 297 // external action.
(...skipping 23 matching lines...) Expand all
274 321
275 // Simple calculation of the amount of time remaining to completion. Fills 322 // Simple calculation of the amount of time remaining to completion. Fills
276 // |*remaining| with the amount of time remaining if successful. Fails and 323 // |*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 324 // returns false if we do not have the number of bytes or the speed so can
278 // not estimate. 325 // not estimate.
279 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0; 326 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0;
280 327
281 // Simple speed estimate in bytes/s 328 // Simple speed estimate in bytes/s
282 virtual int64_t CurrentSpeed() const = 0; 329 virtual int64_t CurrentSpeed() const = 0;
283 330
284 // Rough percent complete, -1 means we don't know (== we didn't receive a 331 // Rough percent complete. Returns -1 if progress is unknown. 100 if the
285 // total size). 332 // download is already complete.
286 virtual int PercentComplete() const = 0; 333 virtual int PercentComplete() const = 0;
287 334
288 // Returns true if this download has saved all of its data. 335 // Returns true if this download has saved all of its data. A download may
336 // have saved all its data but still be waiting for some other process to
337 // complete before the download is considered complete. E.g. A dangerous
338 // download needs to be accepted by the user before the file is renamed to its
339 // final name.
289 virtual bool AllDataSaved() const = 0; 340 virtual bool AllDataSaved() const = 0;
290 341
342 // Total number of expected bytes. Returns -1 if the total size is unknown.
291 virtual int64_t GetTotalBytes() const = 0; 343 virtual int64_t GetTotalBytes() const = 0;
344
345 // Total number of bytes that have been received and written to the download
346 // file.
292 virtual int64_t GetReceivedBytes() const = 0; 347 virtual int64_t GetReceivedBytes() const = 0;
348
349 // Time the download was first started. This timestamp is always valid and
350 // doesn't change.
293 virtual base::Time GetStartTime() const = 0; 351 virtual base::Time GetStartTime() const = 0;
352
353 // Time the download was marked as complete. Returns base::Time() if the
354 // download hasn't reached a completion state yet.
294 virtual base::Time GetEndTime() const = 0; 355 virtual base::Time GetEndTime() const = 0;
295 356
296 // Open/Show State accessors ---------------------------------------------- 357 // Open/Show State accessors ----------------------------------------------
297 358
298 // Returns true if it is OK to open a folder which this file is inside. 359 // Returns true if it is OK to open a folder which this file is inside.
299 virtual bool CanShowInFolder() = 0; 360 virtual bool CanShowInFolder() = 0;
300 361
301 // Returns true if it is OK to open the download. 362 // Returns true if it is OK to open the download.
302 virtual bool CanOpenDownload() = 0; 363 virtual bool CanOpenDownload() = 0;
303 364
304 // Tests if a file type should be opened automatically. 365 // Tests if a file type should be opened automatically.
305 virtual bool ShouldOpenFileBasedOnExtension() = 0; 366 virtual bool ShouldOpenFileBasedOnExtension() = 0;
306 367
307 // Returns true if the download will be auto-opened when complete. 368 // Returns true if the download will be auto-opened when complete.
308 virtual bool GetOpenWhenComplete() const = 0; 369 virtual bool GetOpenWhenComplete() const = 0;
309 370
310 // Returns true if the download has been auto-opened by the system. 371 // Returns true if the download has been auto-opened by the system.
311 virtual bool GetAutoOpened() = 0; 372 virtual bool GetAutoOpened() = 0;
312 373
313 // Returns true if the download has been opened. 374 // Returns true if the download has been opened.
314 virtual bool GetOpened() const = 0; 375 virtual bool GetOpened() const = 0;
315 376
316 // Misc State accessors --------------------------------------------------- 377 // Misc State accessors ---------------------------------------------------
317 378
379 // BrowserContext that indirectly owns this download. Always valid.
318 virtual BrowserContext* GetBrowserContext() const = 0; 380 virtual BrowserContext* GetBrowserContext() const = 0;
381
382 // WebContents associated with the download. Returns nullptr if the
383 // WebContents is unknown or if the download was not performed on behalf of a
384 // renderer.
319 virtual WebContents* GetWebContents() const = 0; 385 virtual WebContents* GetWebContents() const = 0;
320 386
321 // External state transitions/setters ---------------------------------------- 387 // External state transitions/setters ----------------------------------------
388
322 // TODO(rdsmith): These should all be removed; the download item should 389 // TODO(rdsmith): These should all be removed; the download item should
323 // control its own state transitions. 390 // control its own state transitions.
324 391
325 // Called if a check of the download contents was performed and the results of 392 // 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 393 // the test are available. This should only be called after AllDataSaved() is
327 // true. 394 // true.
328 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) = 0; 395 virtual void OnContentCheckCompleted(DownloadDangerType danger_type) = 0;
329 396
330 // Mark the download to be auto-opened when completed. 397 // Mark the download to be auto-opened when completed.
331 virtual void SetOpenWhenComplete(bool open) = 0; 398 virtual void SetOpenWhenComplete(bool open) = 0;
332 399
333 // Mark the download as having been opened (without actually opening it). 400 // Mark the download as having been opened (without actually opening it).
334 virtual void SetOpened(bool opened) = 0; 401 virtual void SetOpened(bool opened) = 0;
335 402
336 // Set a display name for the download that will be independent of the target 403 // Set a display name for the download that will be independent of the target
337 // filename. If |name| is not empty, then GetFileNameToReportUser() will 404 // filename. If |name| is not empty, then GetFileNameToReportUser() will
338 // return |name|. Has no effect on the final target filename. 405 // return |name|. Has no effect on the final target filename.
339 virtual void SetDisplayName(const base::FilePath& name) = 0; 406 virtual void SetDisplayName(const base::FilePath& name) = 0;
340 407
341 // Debug/testing ------------------------------------------------------------- 408 // Debug/testing -------------------------------------------------------------
342 virtual std::string DebugString(bool verbose) const = 0; 409 virtual std::string DebugString(bool verbose) const = 0;
343 }; 410 };
344 411
345 } // namespace content 412 } // namespace content
346 413
347 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ 414 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698