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.
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_
8 #include "base/callback.h"
9 #include "ui/shell_dialogs/select_file_dialog.h"
17 class DownloadManager
;
21 // Handles showing a dialog to the user to ask for the filename for a download.
22 class DownloadFilePicker
: public ui::SelectFileDialog::Listener
{
24 // Callback used to pass the user selection back to the owner of this
26 // |virtual_path|: The path chosen by the user. If the user cancels the file
27 // selection, then this parameter will be the empty path. On Chrome OS,
28 // this path may contain virtual mount points if the user chose a virtual
29 // path (e.g. Google Drive).
30 typedef base::Callback
<void(const base::FilePath
& virtual_path
)>
33 // Display a file picker dialog for |item|. The |suggested_path| will be used
34 // as the initial path displayed to the user. |callback| will always be
35 // invoked even if |item| is destroyed prior to the file picker completing.
36 static void ShowFilePicker(content::DownloadItem
* item
,
37 const base::FilePath
& suggested_path
,
38 const FileSelectedCallback
& callback
);
41 DownloadFilePicker(content::DownloadItem
* item
,
42 const base::FilePath
& suggested_path
,
43 const FileSelectedCallback
& callback
);
44 virtual ~DownloadFilePicker();
46 // Runs |file_selected_callback_| with |virtual_path| and then deletes this
48 void OnFileSelected(const base::FilePath
& virtual_path
);
50 // SelectFileDialog::Listener implementation.
51 virtual void FileSelected(const base::FilePath
& path
,
53 void* params
) OVERRIDE
;
54 virtual void FileSelectionCanceled(void* params
) OVERRIDE
;
56 // Initially suggested path.
57 base::FilePath suggested_path_
;
59 // Callback invoked when a file selection is complete.
60 FileSelectedCallback file_selected_callback_
;
62 // For managing select file dialogs.
63 scoped_refptr
<ui::SelectFileDialog
> select_file_dialog_
;
65 // True if UMA regarding on the result of the file selection should be
67 bool should_record_file_picker_result_
;
69 DISALLOW_COPY_AND_ASSIGN(DownloadFilePicker
);
72 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_