Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/extensions/api/file_system/file_entry_picker.cc

Issue 2967223002: Move fileSystem API FilePicker class to own file (Closed)
Patch Set: no comment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "chrome/browser/extensions/api/file_system/file_entry_picker.h"
6
7 #include <memory>
8
9 #include "base/files/file_path.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/platform_util.h"
13 #include "chrome/browser/ui/chrome_select_file_policy.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/shell_dialogs/selected_file_info.h"
17
18 namespace extensions {
19
20 FileEntryPicker::FileEntryPicker(
21 content::WebContents* web_contents,
22 const base::FilePath& suggested_name,
23 const ui::SelectFileDialog::FileTypeInfo& file_type_info,
24 ui::SelectFileDialog::Type picker_type,
25 FilesSelectedCallback&& files_selected_callback,
26 base::OnceClosure&& file_selection_canceled_callback)
27 : files_selected_callback_(std::move(files_selected_callback)),
28 file_selection_canceled_callback_(
29 std::move(file_selection_canceled_callback)) {
30 gfx::NativeWindow owning_window =
31 web_contents ? platform_util::GetTopLevel(web_contents->GetNativeView())
32 : nullptr;
33 select_file_dialog_ = ui::SelectFileDialog::Create(
34 this, base::MakeUnique<ChromeSelectFilePolicy>(web_contents).release());
35 select_file_dialog_->SelectFile(
36 picker_type, base::string16(), suggested_name, &file_type_info, 0,
37 base::FilePath::StringType(), owning_window, nullptr);
38 }
39
40 FileEntryPicker::~FileEntryPicker() {}
41
42 void FileEntryPicker::FileSelected(const base::FilePath& path,
43 int index,
44 void* params) {
45 std::vector<base::FilePath> paths;
46 paths.push_back(path);
47 MultiFilesSelected(paths, params);
Devlin 2017/07/05 19:08:04 nit: MultiFilesSelected(std::vector<base::FilePath
michaelpg 2017/07/05 19:52:53 Done w/ aggregate initialization, as per style gui
48 }
49
50 void FileEntryPicker::FileSelectedWithExtraInfo(
51 const ui::SelectedFileInfo& file,
52 int index,
53 void* params) {
54 // Normally, file.local_path is used because it is a native path to the
55 // local read-only cached file in the case of remote file system like
56 // Chrome OS's Google Drive integration. Here, however, |file.file_path| is
57 // necessary because we need to create a FileEntry denoting the remote file,
58 // not its cache. On other platforms than Chrome OS, they are the same.
59 //
60 // TODO(kinaba): remove this, once after the file picker implements proper
61 // switch of the path treatment depending on the |allowed_paths|.
62 FileSelected(file.file_path, index, params);
63 }
64
65 void FileEntryPicker::MultiFilesSelected(
66 const std::vector<base::FilePath>& files,
67 void* params) {
68 std::move(files_selected_callback_).Run(files);
69 delete this;
70 }
71
72 void FileEntryPicker::MultiFilesSelectedWithExtraInfo(
73 const std::vector<ui::SelectedFileInfo>& files,
74 void* params) {
75 std::vector<base::FilePath> paths;
76 for (std::vector<ui::SelectedFileInfo>::const_iterator it = files.begin();
77 it != files.end(); ++it) {
78 paths.push_back(it->file_path);
79 }
80 MultiFilesSelected(paths, params);
81 }
82
83 void FileEntryPicker::FileSelectionCanceled(void* params) {
84 std::move(file_selection_canceled_callback_).Run();
85 delete this;
86 }
87
88 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698