Componentize ShortcutsBackend
[chromium-blink-merge.git] / chrome / browser / download / download_target_determiner_delegate.h
blobf2aeec6f03625bf71cb9a3a1461f2bd68d700f88
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.
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_
8 #include "base/callback_forward.h"
10 #include "chrome/browser/download/download_path_reservation_tracker.h"
11 #include "content/public/browser/download_danger_type.h"
13 class ExtensionDownloadsEventRouter;
15 namespace base {
16 class FilePath;
19 namespace content {
20 class DownloadItem;
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;
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;
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;
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;
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;
65 // Callback to be invoked after GetFileMimeType() completes. The parameter
66 // should be the MIME type of the requested file. If no MIME type can be
67 // determined, it should be set to the empty string.
68 typedef base::Callback<void(const std::string&)> GetFileMimeTypeCallback;
70 // Notifies extensions of the impending filename determination. |virtual_path|
71 // is the current suggested virtual path. The |callback| should be invoked to
72 // indicate whether any extensions wish to override the path.
73 virtual void NotifyExtensions(content::DownloadItem* download,
74 const base::FilePath& virtual_path,
75 const NotifyExtensionsCallback& callback) = 0;
77 // Reserve |virtual_path|. This is expected to check the following:
78 // - Whether |virtual_path| can be written to by the user. If not, the
79 // |virtual_path| can be changed to writeable path if necessary.
80 // - If |conflict_action| is UNIQUIFY then |virtual_path| should be
81 // modified so that the new path is writeable and unique. If
82 // |conflict_action| is PROMPT, then in the event of a conflict,
83 // |callback| should be invoked with |success| set to |false| in
84 // order to force a prompt. |virtual_path| may or may not be
85 // modified in the latter case.
86 // - If |create_directory| is true, then the parent directory of
87 // |virtual_path| should be created if it doesn't exist.
89 // |callback| should be invoked on completion with the results.
90 virtual void ReserveVirtualPath(
91 content::DownloadItem* download,
92 const base::FilePath& virtual_path,
93 bool create_directory,
94 DownloadPathReservationTracker::FilenameConflictAction conflict_action,
95 const ReservedPathCallback& callback) = 0;
97 // Display a prompt to the user requesting that a download target be chosen.
98 // Should invoke |callback| upon completion.
99 virtual void PromptUserForDownloadPath(
100 content::DownloadItem* download,
101 const base::FilePath& virtual_path,
102 const FileSelectedCallback& callback) = 0;
104 // If |virtual_path| is not a local path, should return a possibly temporary
105 // local path to use for storing the downloaded file. If |virtual_path| is
106 // already local, then it should return the same path. |callback| should be
107 // invoked to return the path.
108 virtual void DetermineLocalPath(content::DownloadItem* download,
109 const base::FilePath& virtual_path,
110 const LocalPathCallback& callback) = 0;
112 // Check whether the download URL is malicious and invoke |callback| with a
113 // suggested danger type for the download.
114 virtual void CheckDownloadUrl(content::DownloadItem* download,
115 const base::FilePath& virtual_path,
116 const CheckDownloadUrlCallback& callback) = 0;
118 // Get the MIME type for the given file.
119 virtual void GetFileMimeType(const base::FilePath& path,
120 const GetFileMimeTypeCallback& callback) = 0;
121 protected:
122 virtual ~DownloadTargetDeterminerDelegate();
125 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_