[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ | ||||
6 | #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ | ||||
7 | |||||
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 10 | #include "base/callback.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 13 | #include "content/common/content_export.h" |
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 14 | #include "content/public/browser/download_danger_type.h" |
15 | #include "content/public/browser/download_item.h" | ||||
[email protected] | 8d68a3e0 | 2013-01-12 15:57:10 | [diff] [blame] | 16 | #include "content/public/browser/download_url_parameters.h" |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 17 | |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 18 | namespace content { |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 19 | class DownloadItemImpl; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 20 | class BrowserContext; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 21 | |
22 | // Delegate for operations that a DownloadItemImpl can't do for itself. | ||||
23 | // The base implementation of this class does nothing (returning false | ||||
24 | // on predicates) so interfaces not of interest to a derived class may | ||||
25 | // be left unimplemented. | ||||
26 | class CONTENT_EXPORT DownloadItemImplDelegate { | ||||
27 | public: | ||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 28 | typedef base::Callback<void( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 29 | const base::FilePath&, // Target path |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 30 | DownloadItem::TargetDisposition, // overwrite/uniquify target |
31 | DownloadDangerType, | ||||
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 32 | const base::FilePath& // Intermediate file path |
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 33 | )> DownloadTargetCallback; |
34 | |||||
[email protected] | bde0e4f | 2012-11-08 22:49:59 | [diff] [blame] | 35 | // The boolean argument indicates whether or not the download was |
36 | // actually opened. | ||||
37 | typedef base::Callback<void(bool)> ShouldOpenDownloadCallback; | ||||
38 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 39 | DownloadItemImplDelegate(); |
40 | virtual ~DownloadItemImplDelegate(); | ||||
41 | |||||
42 | // Used for catching use-after-free errors. | ||||
43 | void Attach(); | ||||
44 | void Detach(); | ||||
45 | |||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 46 | // Request determination of the download target from the delegate. |
47 | virtual void DetermineDownloadTarget( | ||||
48 | DownloadItemImpl* download, const DownloadTargetCallback& callback); | ||||
49 | |||||
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 50 | // Allows the delegate to delay completion of the download. This function |
[email protected] | 9829962 | 2013-01-03 22:26:50 | [diff] [blame] | 51 | // will either return true (if the download may complete now) or will return |
52 | // false and call the provided callback at some future point. This function | ||||
53 | // may be called repeatedly. | ||||
54 | virtual bool ShouldCompleteDownload( | ||||
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 55 | DownloadItemImpl* download, |
56 | const base::Closure& complete_callback); | ||||
57 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 58 | // Allows the delegate to override the opening of a download. If it returns |
59 | // true then it's reponsible for opening the item. | ||||
[email protected] | bde0e4f | 2012-11-08 22:49:59 | [diff] [blame] | 60 | virtual bool ShouldOpenDownload( |
61 | DownloadItemImpl* download, const ShouldOpenDownloadCallback& callback); | ||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 62 | |
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 63 | // Tests if a file type should be opened automatically. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 64 | virtual bool ShouldOpenFileBasedOnExtension(const base::FilePath& path); |
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 65 | |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 66 | // Checks whether a downloaded file still exists and updates the |
67 | // file's state if the file is already removed. | ||||
68 | // The check may or may not result in a later asynchronous call | ||||
69 | // to OnDownloadedFileRemoved(). | ||||
70 | virtual void CheckForFileRemoval(DownloadItemImpl* download_item); | ||||
71 | |||||
asanka | 4350f6a | 2016-03-15 02:40:57 | [diff] [blame] | 72 | // Return a GUID string used for identifying the application to the system AV |
asanka | be2afd5 | 2016-10-05 14:29:04 | [diff] [blame] | 73 | // function for scanning downloaded files. If no GUID is provided or if the |
74 | // provided GUID is invalid, then the appropriate quarantining will be | ||||
75 | // performed manually without passing the download to the system AV function. | ||||
76 | // | ||||
77 | // This GUID is only used on Windows. | ||||
asanka | 4350f6a | 2016-03-15 02:40:57 | [diff] [blame] | 78 | virtual std::string GetApplicationClientIdForFileScanning() const; |
79 | |||||
[email protected] | 8d68a3e0 | 2013-01-12 15:57:10 | [diff] [blame] | 80 | // Called when an interrupted download is resumed. |
81 | virtual void ResumeInterruptedDownload( | ||||
dcheng | f6c4058 | 2016-04-09 00:05:13 | [diff] [blame] | 82 | std::unique_ptr<content::DownloadUrlParameters> params, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 83 | uint32_t id); |
[email protected] | 8d68a3e0 | 2013-01-12 15:57:10 | [diff] [blame] | 84 | |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 85 | // For contextual issues like language and prefs. |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 86 | virtual BrowserContext* GetBrowserContext() const; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 87 | |
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 88 | // Update the persistent store with our information. |
89 | virtual void UpdatePersistence(DownloadItemImpl* download); | ||||
90 | |||||
[email protected] | ffc0c2d | 2013-01-21 15:32:12 | [diff] [blame] | 91 | // Opens the file associated with this download. |
92 | virtual void OpenDownload(DownloadItemImpl* download); | ||||
93 | |||||
94 | // Shows the download via the OS shell. | ||||
95 | virtual void ShowDownloadInShell(DownloadItemImpl* download); | ||||
96 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 97 | // Handle any delegate portions of a state change operation on the |
98 | // DownloadItem. | ||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 99 | virtual void DownloadRemoved(DownloadItemImpl* download); |
[email protected] | 3d95e54 | 2012-11-20 00:52:08 | [diff] [blame] | 100 | |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 101 | // Assert consistent state for delgate object at various transitions. |
102 | virtual void AssertStateConsistent(DownloadItemImpl* download) const; | ||||
103 | |||||
104 | private: | ||||
105 | // For "Outlives attached DownloadItemImpl" invariant assertion. | ||||
106 | int count_; | ||||
107 | |||||
108 | DISALLOW_COPY_AND_ASSIGN(DownloadItemImplDelegate); | ||||
109 | }; | ||||
110 | |||||
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 111 | } // namespace content |
112 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 113 | #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ |