Delete unused downloads page asset.
[chromium-blink-merge.git] / win8 / metro_driver / file_picker_ash.h
blob0862b69663589609313c03b1bc67cb33ee69c48d
1 // Copyright (c) 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 #ifndef CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_
5 #define CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_
7 #include <vector>
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/strings/string16.h"
14 class ChromeAppViewAsh;
15 struct MetroViewerHostMsg_SaveAsDialogParams;
17 namespace base {
18 class FilePath;
21 // Base class for the file pickers.
22 class FilePickerSessionBase {
23 public:
24 virtual ~FilePickerSessionBase();
26 // Runs the picker, returns true on success.
27 bool Run();
29 const base::string16& result() const { return result_; }
31 bool success() const { return success_; }
33 protected:
34 // Creates a file picker for open_file_name.
35 FilePickerSessionBase(ChromeAppViewAsh* app_view,
36 const base::string16& title,
37 const base::string16& filter,
38 const base::FilePath& default_path);
40 // Creates, configures and starts a file picker.
41 // If the HRESULT returned is a failure code the file picker has not started,
42 // so no callbacks should be expected.
43 virtual HRESULT StartFilePicker() = 0;
45 // True iff a file picker has successfully finished.
46 bool success_;
48 // The title of the file picker.
49 base::string16 title_;
51 // The file type filter.
52 base::string16 filter_;
54 // The starting directory/file name.
55 base::FilePath default_path_;
57 // Pointer to the ChromeAppViewAsh instance. We notify the ChromeAppViewAsh
58 // instance when the file open/save operations complete.
59 ChromeAppViewAsh* app_view_;
61 base::string16 result_;
63 private:
64 // Initiate a file picker, must be called on the main metro thread.
65 // Returns true on success.
66 bool DoFilePicker();
68 DISALLOW_COPY_AND_ASSIGN(FilePickerSessionBase);
71 // Provides functionality to display the open file/multiple open file pickers
72 // metro dialog.
73 class OpenFilePickerSession : public FilePickerSessionBase {
74 public:
75 OpenFilePickerSession(ChromeAppViewAsh* app_view,
76 const base::string16& title,
77 const base::string16& filter,
78 const base::FilePath& default_path,
79 bool allow_multi_select);
80 ~OpenFilePickerSession() override;
82 const std::vector<base::FilePath>& filenames() const {
83 return filenames_;
86 const bool allow_multi_select() const {
87 return allow_multi_select_;
90 private:
91 HRESULT StartFilePicker() override;
93 typedef winfoundtn::IAsyncOperation<winstorage::StorageFile*>
94 SingleFileAsyncOp;
95 typedef winfoundtn::Collections::IVectorView<
96 winstorage::StorageFile*> StorageFileVectorCollection;
97 typedef winfoundtn::IAsyncOperation<StorageFileVectorCollection*>
98 MultiFileAsyncOp;
100 // Called asynchronously when a single file picker is done.
101 HRESULT SinglePickerDone(SingleFileAsyncOp* async, AsyncStatus status);
103 // Called asynchronously when a multi file picker is done.
104 HRESULT MultiPickerDone(MultiFileAsyncOp* async, AsyncStatus status);
106 // Composes a multi-file result string suitable for returning to a
107 // from a storage file collection.
108 static HRESULT ComposeMultiFileResult(StorageFileVectorCollection* files,
109 base::string16* result);
111 // True if the multi file picker is to be displayed.
112 bool allow_multi_select_;
113 // If multi select is true then this member contains the list of filenames
114 // to be returned back.
115 std::vector<base::FilePath> filenames_;
117 DISALLOW_COPY_AND_ASSIGN(OpenFilePickerSession);
120 // Provides functionality to display the save file picker.
121 class SaveFilePickerSession : public FilePickerSessionBase {
122 public:
123 SaveFilePickerSession(ChromeAppViewAsh* app_view,
124 const MetroViewerHostMsg_SaveAsDialogParams& params);
126 int filter_index() const;
128 private:
129 HRESULT StartFilePicker() override;
131 typedef winfoundtn::IAsyncOperation<winstorage::StorageFile*> SaveFileAsyncOp;
133 // Called asynchronously when the save file picker is done.
134 HRESULT FilePickerDone(SaveFileAsyncOp* async, AsyncStatus status);
136 int filter_index_;
138 DISALLOW_COPY_AND_ASSIGN(SaveFilePickerSession);
141 // Provides functionality to display the folder picker.
142 class FolderPickerSession : public FilePickerSessionBase {
143 public:
144 FolderPickerSession(ChromeAppViewAsh* app_view, const base::string16& title);
146 private:
147 HRESULT StartFilePicker() override;
149 typedef winfoundtn::IAsyncOperation<winstorage::StorageFolder*>
150 FolderPickerAsyncOp;
152 // Called asynchronously when the folder picker is done.
153 HRESULT FolderPickerDone(FolderPickerAsyncOp* async, AsyncStatus status);
155 DISALLOW_COPY_AND_ASSIGN(FolderPickerSession);
158 #endif // CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_