| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_FILE_PICKER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 8 #include "base/callback.h" |
| 9 #include "ui/shell_dialogs/select_file_dialog.h" | 9 #include "ui/shell_dialogs/select_file_dialog.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class FilePath; | 12 class FilePath; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class DownloadItem; | 16 class DownloadItem; |
| 17 class DownloadManager; | 17 class DownloadManager; |
| 18 class WebContents; | 18 class WebContents; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Handles showing a dialog to the user to ask for the filename for a download. | 21 // Handles showing a dialog to the user to ask for the filename for a download. |
| 22 class DownloadFilePicker : public ui::SelectFileDialog::Listener { | 22 class DownloadFilePicker : public ui::SelectFileDialog::Listener { |
| 23 public: | 23 public: |
| 24 DownloadFilePicker(); | 24 // Callback used to pass the user selection back to the owner of this |
| 25 // object. |
| 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)> |
| 31 FileSelectedCallback; |
| 32 |
| 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); |
| 39 |
| 40 private: |
| 41 DownloadFilePicker(content::DownloadItem* item, |
| 42 const base::FilePath& suggested_path, |
| 43 const FileSelectedCallback& callback); |
| 25 virtual ~DownloadFilePicker(); | 44 virtual ~DownloadFilePicker(); |
| 26 | 45 |
| 27 void Init(content::DownloadManager* download_manager, | 46 // Runs |file_selected_callback_| with |virtual_path| and then deletes this |
| 28 content::DownloadItem* item, | 47 // object. |
| 29 const base::FilePath& suggested_path, | 48 void OnFileSelected(const base::FilePath& virtual_path); |
| 30 const ChromeDownloadManagerDelegate::FileSelectedCallback& | |
| 31 callback); | |
| 32 | 49 |
| 33 protected: | |
| 34 // On ChromeOS |suggested_path| might be a temporary local filename. This | |
| 35 // method should be overridden to set the correct suggested path to prompt the | |
| 36 // user. | |
| 37 virtual void InitSuggestedPath(content::DownloadItem* item, | |
| 38 const base::FilePath& suggested_path); | |
| 39 | |
| 40 void set_suggested_path(const base::FilePath& suggested_path) { | |
| 41 suggested_path_ = suggested_path; | |
| 42 } | |
| 43 | |
| 44 // Runs |file_selected_callback_| with |path| and then deletes this object. | |
| 45 void OnFileSelected(const base::FilePath& path); | |
| 46 | |
| 47 void RecordFileSelected(const base::FilePath& path); | |
| 48 | |
| 49 scoped_refptr<content::DownloadManager> download_manager_; | |
| 50 int32 download_id_; | |
| 51 | |
| 52 private: | |
| 53 // SelectFileDialog::Listener implementation. | 50 // SelectFileDialog::Listener implementation. |
| 54 virtual void FileSelected(const base::FilePath& path, | 51 virtual void FileSelected(const base::FilePath& path, |
| 55 int index, | 52 int index, |
| 56 void* params) OVERRIDE; | 53 void* params) OVERRIDE; |
| 57 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 54 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
| 58 | 55 |
| 56 // Initially suggested path. |
| 59 base::FilePath suggested_path_; | 57 base::FilePath suggested_path_; |
| 60 | 58 |
| 61 ChromeDownloadManagerDelegate::FileSelectedCallback file_selected_callback_; | 59 // Callback invoked when a file selection is complete. |
| 60 FileSelectedCallback file_selected_callback_; |
| 62 | 61 |
| 63 // For managing select file dialogs. | 62 // For managing select file dialogs. |
| 64 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 63 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
| 65 | 64 |
| 65 // True if UMA regarding on the result of the file selection should be |
| 66 // recorded. |
| 67 bool should_record_file_picker_result_; |
| 68 |
| 66 DISALLOW_COPY_AND_ASSIGN(DownloadFilePicker); | 69 DISALLOW_COPY_AND_ASSIGN(DownloadFilePicker); |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ | 72 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_PICKER_H_ |
| OLD | NEW |