OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
9 | 11 #include "chrome/browser/download/download_confirmation_reason.h" |
| 12 #include "chrome/browser/download/download_confirmation_result.h" |
10 #include "chrome/browser/download/download_path_reservation_tracker.h" | 13 #include "chrome/browser/download/download_path_reservation_tracker.h" |
11 #include "content/public/browser/download_danger_type.h" | 14 #include "content/public/browser/download_danger_type.h" |
12 | 15 |
13 namespace base { | 16 namespace base { |
14 class FilePath; | 17 class FilePath; |
15 } | 18 } |
16 | 19 |
17 namespace content { | 20 namespace content { |
18 class DownloadItem; | 21 class DownloadItem; |
19 } | 22 } |
20 | 23 |
21 // Delegate for DownloadTargetDeterminer. The delegate isn't owned by | 24 // Delegate for DownloadTargetDeterminer. The delegate isn't owned by |
22 // DownloadTargetDeterminer and is expected to outlive it. | 25 // DownloadTargetDeterminer and is expected to outlive it. |
23 class DownloadTargetDeterminerDelegate { | 26 class DownloadTargetDeterminerDelegate { |
24 public: | 27 public: |
25 // Callback to be invoked after NotifyExtensions() completes. The | 28 // Callback to be invoked after NotifyExtensions() completes. The |
26 // |new_virtual_path| should be set to a new path if an extension wishes to | 29 // |new_virtual_path| should be set to a new path if an extension wishes to |
27 // override the download path. |conflict_action| should be set to the action | 30 // override the download path. |conflict_action| should be set to the action |
28 // to take if a file exists at |new_virtual_path|. If |new_virtual_path| is | 31 // to take if a file exists at |new_virtual_path|. If |new_virtual_path| is |
29 // empty, then the download target will be unchanged and |conflict_action| is | 32 // empty, then the download target will be unchanged and |conflict_action| is |
30 // ignored. | 33 // ignored. |
31 typedef base::Callback<void( | 34 typedef base::Callback<void( |
32 const base::FilePath& new_virtual_path, | 35 const base::FilePath& new_virtual_path, |
33 DownloadPathReservationTracker::FilenameConflictAction conflict_action)> | 36 DownloadPathReservationTracker::FilenameConflictAction conflict_action)> |
34 NotifyExtensionsCallback; | 37 NotifyExtensionsCallback; |
35 | 38 |
36 // Callback to be invoked when ReserveVirtualPath() completes. If the path | 39 // Callback to be invoked when ReserveVirtualPath() completes. |
37 // reservation is successful, then |successful| should be true and | 40 using ReservedPathCallback = |
38 // |reserved_path| should contain the reserved path. Otherwise, |successful| | 41 DownloadPathReservationTracker::ReservedPathCallback; |
39 // should be false. In the failure case, |reserved_path| is ignored. | |
40 typedef base::Callback<void(const base::FilePath& reserved_path, | |
41 bool successful)> ReservedPathCallback; | |
42 | 42 |
43 // Callback to be invoked when PromptUserForDownloadPath() completes. | 43 // Callback to be invoked when RequestConfirmation() completes. |
44 // |virtual_path|: The path chosen by the user. If the user cancels the file | 44 // |virtual_path|: The path chosen by the user. If the user cancels the file |
45 // selection, then this parameter will be the empty path. On Chrome OS, | 45 // selection, then this parameter will be the empty path. On Chrome OS, |
46 // this path may contain virtual mount points if the user chose a virtual | 46 // this path may contain virtual mount points if the user chose a virtual |
47 // path (e.g. Google Drive). | 47 // path (e.g. Google Drive). |
48 typedef base::Callback<void(const base::FilePath& virtual_path)> | 48 typedef base::Callback<void(DownloadConfirmationResult, |
49 FileSelectedCallback; | 49 const base::FilePath& virtual_path)> |
| 50 ConfirmationCallback; |
50 | 51 |
51 // Callback to be invoked when DetermineLocalPath() completes. The argument | 52 // Callback to be invoked when DetermineLocalPath() completes. The argument |
52 // should be the determined local path. It should be non-empty on success. If | 53 // should be the determined local path. It should be non-empty on success. If |
53 // |virtual_path| is already a local path, then |virtual_path| should be | 54 // |virtual_path| is already a local path, then |virtual_path| should be |
54 // returned as-is. | 55 // returned as-is. |
55 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; | 56 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; |
56 | 57 |
57 // Callback to be invoked after CheckDownloadUrl() completes. The parameter to | 58 // Callback to be invoked after CheckDownloadUrl() completes. The parameter to |
58 // the callback should indicate the danger type of the download based on the | 59 // the callback should indicate the danger type of the download based on the |
59 // results of the URL check. | 60 // results of the URL check. |
(...skipping 27 matching lines...) Expand all Loading... |
87 // |callback| should be invoked on completion with the results. | 88 // |callback| should be invoked on completion with the results. |
88 virtual void ReserveVirtualPath( | 89 virtual void ReserveVirtualPath( |
89 content::DownloadItem* download, | 90 content::DownloadItem* download, |
90 const base::FilePath& virtual_path, | 91 const base::FilePath& virtual_path, |
91 bool create_directory, | 92 bool create_directory, |
92 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 93 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
93 const ReservedPathCallback& callback) = 0; | 94 const ReservedPathCallback& callback) = 0; |
94 | 95 |
95 // Display a prompt to the user requesting that a download target be chosen. | 96 // Display a prompt to the user requesting that a download target be chosen. |
96 // Should invoke |callback| upon completion. | 97 // Should invoke |callback| upon completion. |
97 virtual void PromptUserForDownloadPath( | 98 virtual void RequestConfirmation(content::DownloadItem* download, |
98 content::DownloadItem* download, | 99 const base::FilePath& virtual_path, |
99 const base::FilePath& virtual_path, | 100 DownloadConfirmationReason reason, |
100 const FileSelectedCallback& callback) = 0; | 101 const ConfirmationCallback& callback) = 0; |
101 | 102 |
102 // If |virtual_path| is not a local path, should return a possibly temporary | 103 // If |virtual_path| is not a local path, should return a possibly temporary |
103 // local path to use for storing the downloaded file. If |virtual_path| is | 104 // local path to use for storing the downloaded file. If |virtual_path| is |
104 // already local, then it should return the same path. |callback| should be | 105 // already local, then it should return the same path. |callback| should be |
105 // invoked to return the path. | 106 // invoked to return the path. |
106 virtual void DetermineLocalPath(content::DownloadItem* download, | 107 virtual void DetermineLocalPath(content::DownloadItem* download, |
107 const base::FilePath& virtual_path, | 108 const base::FilePath& virtual_path, |
108 const LocalPathCallback& callback) = 0; | 109 const LocalPathCallback& callback) = 0; |
109 | 110 |
110 // Check whether the download URL is malicious and invoke |callback| with a | 111 // Check whether the download URL is malicious and invoke |callback| with a |
111 // suggested danger type for the download. | 112 // suggested danger type for the download. |
112 virtual void CheckDownloadUrl(content::DownloadItem* download, | 113 virtual void CheckDownloadUrl(content::DownloadItem* download, |
113 const base::FilePath& virtual_path, | 114 const base::FilePath& virtual_path, |
114 const CheckDownloadUrlCallback& callback) = 0; | 115 const CheckDownloadUrlCallback& callback) = 0; |
115 | 116 |
116 // Get the MIME type for the given file. | 117 // Get the MIME type for the given file. |
117 virtual void GetFileMimeType(const base::FilePath& path, | 118 virtual void GetFileMimeType(const base::FilePath& path, |
118 const GetFileMimeTypeCallback& callback) = 0; | 119 const GetFileMimeTypeCallback& callback) = 0; |
| 120 |
119 protected: | 121 protected: |
120 virtual ~DownloadTargetDeterminerDelegate(); | 122 virtual ~DownloadTargetDeterminerDelegate(); |
121 }; | 123 }; |
122 | 124 |
123 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | 125 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ |
OLD | NEW |