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_
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
;
21 // Base class for the file pickers.
22 class FilePickerSessionBase
{
24 virtual ~FilePickerSessionBase();
26 // Runs the picker, returns true on success.
29 const base::string16
& result() const { return result_
; }
31 bool success() const { return success_
; }
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.
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_
;
64 // Initiate a file picker, must be called on the main metro thread.
65 // Returns true on success.
68 DISALLOW_COPY_AND_ASSIGN(FilePickerSessionBase
);
71 // Provides functionality to display the open file/multiple open file pickers
73 class OpenFilePickerSession
: public FilePickerSessionBase
{
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 {
86 const bool allow_multi_select() const {
87 return allow_multi_select_
;
91 HRESULT
StartFilePicker() override
;
93 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFile
*>
95 typedef winfoundtn::Collections::IVectorView
<
96 winstorage::StorageFile
*> StorageFileVectorCollection
;
97 typedef winfoundtn::IAsyncOperation
<StorageFileVectorCollection
*>
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
{
123 SaveFilePickerSession(ChromeAppViewAsh
* app_view
,
124 const MetroViewerHostMsg_SaveAsDialogParams
& params
);
126 int SaveFilePickerSession::filter_index() const;
129 HRESULT
StartFilePicker() override
;
131 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFile
*>
134 // Called asynchronously when the save file picker is done.
135 HRESULT
FilePickerDone(SaveFileAsyncOp
* async
, AsyncStatus status
);
139 DISALLOW_COPY_AND_ASSIGN(SaveFilePickerSession
);
142 // Provides functionality to display the folder picker.
143 class FolderPickerSession
: public FilePickerSessionBase
{
145 FolderPickerSession(ChromeAppViewAsh
* app_view
, const base::string16
& title
);
148 HRESULT
StartFilePicker() override
;
150 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFolder
*>
153 // Called asynchronously when the folder picker is done.
154 HRESULT
FolderPickerDone(FolderPickerAsyncOp
* async
, AsyncStatus status
);
156 DISALLOW_COPY_AND_ASSIGN(FolderPickerSession
);
159 #endif // CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_