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 // Creates a file picker for open_file_name.
25 explicit FilePickerSessionBase(ChromeAppViewAsh
* app_view
,
26 const string16
& title
,
27 const string16
& filter
,
28 const base::FilePath
& default_path
);
30 virtual ~FilePickerSessionBase() {
33 // Runs the picker, returns true on success.
36 const string16
& result() const {
40 bool success() const {
45 // Creates, configures and starts a file picker.
46 // If the HRESULT returned is a failure code the file picker has not started,
47 // so no callbacks should be expected.
48 virtual HRESULT
StartFilePicker() = 0;
50 // True iff a file picker has successfully finished.
53 // The title of the file picker.
56 // The file type filter.
59 // The starting directory/file name.
60 base::FilePath default_path_
;
62 // Pointer to the ChromeAppViewAsh instance. We notify the ChromeAppViewAsh
63 // instance when the file open/save operations complete.
64 ChromeAppViewAsh
* app_view_
;
69 // Initiate a file picker, must be called on the main metro thread.
70 // Returns true on success.
73 DISALLOW_COPY_AND_ASSIGN(FilePickerSessionBase
);
76 // Provides functionality to display the open file/multiple open file pickers
78 class OpenFilePickerSession
: public FilePickerSessionBase
{
80 explicit OpenFilePickerSession(ChromeAppViewAsh
* app_view
,
81 const string16
& title
,
82 const string16
& filter
,
83 const base::FilePath
& default_path
,
84 bool allow_multi_select
);
86 const std::vector
<base::FilePath
>& filenames() const {
90 const bool allow_multi_select() const {
91 return allow_multi_select_
;
95 virtual HRESULT
StartFilePicker() OVERRIDE
;
97 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFile
*>
99 typedef winfoundtn::Collections::IVectorView
<
100 winstorage::StorageFile
*> StorageFileVectorCollection
;
101 typedef winfoundtn::IAsyncOperation
<StorageFileVectorCollection
*>
104 // Called asynchronously when a single file picker is done.
105 HRESULT
SinglePickerDone(SingleFileAsyncOp
* async
, AsyncStatus status
);
107 // Called asynchronously when a multi file picker is done.
108 HRESULT
MultiPickerDone(MultiFileAsyncOp
* async
, AsyncStatus status
);
110 // Composes a multi-file result string suitable for returning to a
111 // from a storage file collection.
112 static HRESULT
ComposeMultiFileResult(StorageFileVectorCollection
* files
,
116 // True if the multi file picker is to be displayed.
117 bool allow_multi_select_
;
118 // If multi select is true then this member contains the list of filenames
119 // to be returned back.
120 std::vector
<base::FilePath
> filenames_
;
122 DISALLOW_COPY_AND_ASSIGN(OpenFilePickerSession
);
125 // Provides functionality to display the save file picker.
126 class SaveFilePickerSession
: public FilePickerSessionBase
{
128 explicit SaveFilePickerSession(
129 ChromeAppViewAsh
* app_view
,
130 const MetroViewerHostMsg_SaveAsDialogParams
& params
);
132 int SaveFilePickerSession::filter_index() const;
135 virtual HRESULT
StartFilePicker() OVERRIDE
;
137 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFile
*>
140 // Called asynchronously when the save file picker is done.
141 HRESULT
FilePickerDone(SaveFileAsyncOp
* async
, AsyncStatus status
);
145 DISALLOW_COPY_AND_ASSIGN(SaveFilePickerSession
);
148 // Provides functionality to display the folder picker.
149 class FolderPickerSession
: public FilePickerSessionBase
{
151 explicit FolderPickerSession(ChromeAppViewAsh
* app_view
,
152 const string16
& title
);
155 virtual HRESULT
StartFilePicker() OVERRIDE
;
157 typedef winfoundtn::IAsyncOperation
<winstorage::StorageFolder
*>
160 // Called asynchronously when the folder picker is done.
161 HRESULT
FolderPickerDone(FolderPickerAsyncOp
* async
, AsyncStatus status
);
163 DISALLOW_COPY_AND_ASSIGN(FolderPickerSession
);
166 #endif // CHROME_BROWSER_UI_METRO_DRIVER_FILE_PICKER_ASH_H_