Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | |
| 7 | |
| 8 #include "base/callback_forward.h" | |
| 9 | |
| 10 #include "chrome/browser/download/download_path_reservation_tracker.h" | |
| 11 #include "content/public/browser/download_danger_type.h" | |
| 12 | |
| 13 class ExtensionDownloadsEventRouter; | |
| 14 | |
| 15 namespace base { | |
| 16 class FilePath; | |
| 17 } | |
| 18 | |
| 19 namespace content { | |
| 20 class DownloadItem; | |
| 21 } | |
| 22 | |
| 23 // Delegate for DownloadTargetDeterminer. The delegate isn't owned by | |
| 24 // DownloadTargetDeterminer and is expected to outlive it. | |
| 25 class DownloadTargetDeterminerDelegate { | |
| 26 public: | |
| 27 // Callback to be invoked after NotifyExtensions() completes. The | |
| 28 // |new_virtual_path| should be set to a new path if an extension wishes to | |
| 29 // override the download path. |conflict_action| should be set to the action | |
| 30 // to take if a file exists at |new_virtual_path|. If |new_virtual_path| is | |
| 31 // empty, then the download target will be unchanged and |conflict_action| is | |
| 32 // ignored. | |
| 33 typedef base::Callback<void( | |
| 34 const base::FilePath& new_virtual_path, | |
| 35 DownloadPathReservationTracker::FilenameConflictAction conflict_action)> | |
| 36 NotifyExtensionsCallback; | |
| 37 | |
| 38 // Callback to be invoked when ReserveVirtualPath() completes. If the path | |
| 39 // reservation is successful, then |successful| should be true and | |
| 40 // |reserved_path| should contain the reserved path. Otherwise, |successful| | |
| 41 // should be false. In the failure case, |reserved_path| is ignored. | |
| 42 typedef base::Callback<void(const base::FilePath& reserved_path, | |
| 43 bool successful)> ReservedPathCallback; | |
| 44 | |
| 45 // Callback to be invoked when PromptUserForDownloadPath() completes. | |
| 46 // |virtual_path|: The path chosen by the user. If the user cancels the file | |
| 47 // selection, then this parameter will be the empty path. On Chrome OS, | |
| 48 // this path may contain virtual mount points if the user chose a virtual | |
| 49 // path (e.g. Google Drive). | |
| 50 typedef base::Callback<void(const base::FilePath& virtual_path)> | |
| 51 FileSelectedCallback; | |
| 52 | |
| 53 // Callback to be invoked when DetermineLocalPath() completes. The argument | |
| 54 // should be the determined local path. It should be non-empty on success. If | |
| 55 // |virtual_path| is already a local path, then |virtual_path| should be | |
| 56 // returned as-is. | |
| 57 typedef base::Callback<void(const base::FilePath&)> LocalPathCallback; | |
| 58 | |
| 59 // Callback to be invoked after CheckDownloadUrl() completes. The parameter to | |
| 60 // the callback should indicate the danger type of the download based on the | |
| 61 // results of the URL check. | |
| 62 typedef base::Callback<void(content::DownloadDangerType danger_type)> | |
| 63 CheckDownloadUrlCallback; | |
| 64 | |
| 65 // Notifies extensions of the impending filename determination. |virtual_path| | |
| 66 // is the current suggested virtual path. The |callback| should be invoked to | |
| 67 // indicate whether any extensions wish to override the path. | |
| 68 virtual void NotifyExtensions(content::DownloadItem* download, | |
| 69 const base::FilePath& virtual_path, | |
| 70 const NotifyExtensionsCallback& callback) = 0; | |
| 71 | |
| 72 // Reserve |virtual_path|. This is expected to check the following: | |
| 73 // - Whether |virtual_path| can be written to by the user. If not, the | |
| 74 // |virtual_path| can be changed to writeable path if necessary. | |
| 75 // - If |should_uniquify_path| is true, then |virtual_path| should be modified | |
|
benjhayden
2013/04/25 17:16:04
s/should_uniquify_path/conflict_action/g
asanka
2013/04/25 19:08:26
Thanks. Fixed locally and will show up in the next
| |
| 76 // so that the new path is writeable and unique. | |
| 77 // | |
| 78 // |callback| should be invoked on completion with the results. | |
| 79 virtual void ReserveVirtualPath( | |
| 80 content::DownloadItem* download, | |
| 81 const base::FilePath& virtual_path, | |
| 82 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | |
| 83 const ReservedPathCallback& callback) = 0; | |
| 84 | |
| 85 // Display a prompt to the user requesting that a download target be chosen. | |
| 86 // Should invoke |callback| upon completion. | |
| 87 virtual void PromptUserForDownloadPath( | |
| 88 content::DownloadItem* download, | |
| 89 const base::FilePath& virtual_path, | |
| 90 const FileSelectedCallback& callback) = 0; | |
| 91 | |
| 92 // If |virtual_path| is not a local path, should return a possibly temporary | |
| 93 // local path to use for storing the downloaded file. If |virtual_path| is | |
| 94 // already local, then it should return the same path. |callback| should be | |
| 95 // invoked to return the path. | |
| 96 virtual void DetermineLocalPath(content::DownloadItem* download, | |
| 97 const base::FilePath& virtual_path, | |
| 98 const LocalPathCallback& callback) = 0; | |
| 99 | |
| 100 // Check whether the download URL is malicious and invoke |callback| with a | |
| 101 // suggested danger type for the download. | |
| 102 virtual void CheckDownloadUrl(content::DownloadItem* download, | |
| 103 const base::FilePath& virtual_path, | |
| 104 const CheckDownloadUrlCallback& callback) = 0; | |
| 105 | |
| 106 protected: | |
| 107 virtual ~DownloadTargetDeterminerDelegate(); | |
| 108 }; | |
| 109 | |
| 110 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_ | |
| OLD | NEW |