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

Side by Side Diff: extensions/browser/api/file_system/file_system_api.h

Issue 2934143002: Move chrome.fileSystem implementation to //extensions (Closed)
Patch Set: benwells, test fix Created 3 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 5 #ifndef EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 6 #define EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file.h" 12 #include "base/files/file.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 #include "chrome/browser/extensions/chrome_extension_function.h"
19 #include "chrome/browser/extensions/chrome_extension_function_details.h"
20 #include "chrome/common/extensions/api/file_system.h"
21 #include "extensions/browser/extension_function.h" 17 #include "extensions/browser/extension_function.h"
18 #include "extensions/common/api/file_system.h"
22 #include "ui/shell_dialogs/select_file_dialog.h" 19 #include "ui/shell_dialogs/select_file_dialog.h"
23 20
24 #if defined(OS_CHROMEOS)
25 #include "chrome/browser/extensions/api/file_system/consent_provider.h"
26 #endif
27
28 namespace extensions { 21 namespace extensions {
29 class ExtensionPrefs; 22 class ExtensionPrefs;
30 23
31 namespace file_system_api { 24 namespace file_system_api {
32 25
33 // Methods to get and set the path of the directory containing the last file 26 // Methods to get and set the path of the directory containing the last file
34 // chosen by the user in response to a chrome.fileSystem.chooseEntry() call for 27 // chosen by the user in response to a chrome.fileSystem.chooseEntry() call for
35 // the given extension. 28 // the given extension.
36 29
37 // Returns an empty path on failure. 30 // Returns an empty path on failure.
38 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs, 31 base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
39 const std::string& extension_id); 32 const std::string& extension_id);
40 33
41 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs, 34 void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
42 const std::string& extension_id, 35 const std::string& extension_id,
43 const base::FilePath& path); 36 const base::FilePath& path);
44 37
45 #if defined(OS_CHROMEOS)
46 // Dispatches an event about a mounted on unmounted volume in the system to
47 // each extension which can request it.
48 void DispatchVolumeListChangeEvent(Profile* profile);
49 #endif
50
51 } // namespace file_system_api 38 } // namespace file_system_api
52 39
53 class FileSystemGetDisplayPathFunction : public UIThreadExtensionFunction { 40 class FileSystemGetDisplayPathFunction : public UIThreadExtensionFunction {
54 public: 41 public:
55 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath", 42 DECLARE_EXTENSION_FUNCTION("fileSystem.getDisplayPath",
56 FILESYSTEM_GETDISPLAYPATH) 43 FILESYSTEM_GETDISPLAYPATH)
57 44
58 protected: 45 protected:
59 ~FileSystemGetDisplayPathFunction() override {} 46 ~FileSystemGetDisplayPathFunction() override {}
60 ResponseAction Run() override; 47 ResponseAction Run() override;
61 }; 48 };
62 49
63 class FileSystemEntryFunction : public ChromeAsyncExtensionFunction { 50 class FileSystemEntryFunction : public UIThreadExtensionFunction {
64 protected: 51 protected:
65 FileSystemEntryFunction(); 52 FileSystemEntryFunction();
66 53
67 ~FileSystemEntryFunction() override {} 54 ~FileSystemEntryFunction() override {}
68 55
69 // This is called when writable file entries are being returned. The function 56 // This is called when writable file entries are being returned. The function
70 // will ensure the files exist, creating them if necessary, and also check 57 // will ensure the files exist, creating them if necessary, and also check
71 // that none of the files are links. If it succeeds it proceeds to 58 // that none of the files are links. If it succeeds it proceeds to
72 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError. 59 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError.
73 void PrepareFilesForWritableApp(const std::vector<base::FilePath>& path); 60 void PrepareFilesForWritableApp(const std::vector<base::FilePath>& path);
(...skipping 22 matching lines...) Expand all
96 bool is_directory_; 83 bool is_directory_;
97 }; 84 };
98 85
99 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { 86 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction {
100 public: 87 public:
101 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", 88 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry",
102 FILESYSTEM_GETWRITABLEENTRY) 89 FILESYSTEM_GETWRITABLEENTRY)
103 90
104 protected: 91 protected:
105 ~FileSystemGetWritableEntryFunction() override {} 92 ~FileSystemGetWritableEntryFunction() override {}
106 bool RunAsync() override; 93 ResponseAction Run() override;
107 94
108 private: 95 private:
109 void CheckPermissionAndSendResponse(); 96 void CheckPermissionAndSendResponse();
110 void SetIsDirectoryAsync(); 97 void SetIsDirectoryAsync();
111 98
112 // The path to the file for which a writable entry has been requested. 99 // The path to the file for which a writable entry has been requested.
113 base::FilePath path_; 100 base::FilePath path_;
114 }; 101 };
115 102
116 class FileSystemIsWritableEntryFunction : public UIThreadExtensionFunction { 103 class FileSystemIsWritableEntryFunction : public UIThreadExtensionFunction {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const AcceptOptions* accepts, 138 const AcceptOptions* accepts,
152 const bool* acceptsAllTypes); 139 const bool* acceptsAllTypes);
153 static void BuildSuggestion(const std::string* opt_name, 140 static void BuildSuggestion(const std::string* opt_name,
154 base::FilePath* suggested_name, 141 base::FilePath* suggested_name,
155 base::FilePath::StringType* suggested_extension); 142 base::FilePath::StringType* suggested_extension);
156 143
157 protected: 144 protected:
158 class FilePicker; 145 class FilePicker;
159 146
160 ~FileSystemChooseEntryFunction() override {} 147 ~FileSystemChooseEntryFunction() override {}
161 bool RunAsync() override; 148 ResponseAction Run() override;
162 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, 149 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info,
163 ui::SelectFileDialog::Type picker_type); 150 ui::SelectFileDialog::Type picker_type);
164 151
165 private: 152 private:
166 void SetInitialPathAndShowPicker( 153 void SetInitialPathAndShowPicker(
167 const base::FilePath& previous_path, 154 const base::FilePath& previous_path,
168 const base::FilePath& suggested_name, 155 const base::FilePath& suggested_name,
169 const ui::SelectFileDialog::FileTypeInfo& file_type_info, 156 const ui::SelectFileDialog::FileTypeInfo& file_type_info,
170 ui::SelectFileDialog::Type picker_type, 157 ui::SelectFileDialog::Type picker_type,
171 bool is_path_non_native_directory); 158 bool is_path_non_native_directory);
172 159
173 // FilesSelected and FileSelectionCanceled are called by the file picker. 160 // FilesSelected and FileSelectionCanceled are called by the file picker.
174 void FilesSelected(const std::vector<base::FilePath>& path); 161 void FilesSelected(const std::vector<base::FilePath>& path);
175 void FileSelectionCanceled(); 162 void FileSelectionCanceled();
176 163
177 // Check if the chosen directory is or is an ancestor of a sensitive 164 // Check if the chosen directory is or is an ancestor of a sensitive
178 // directory. If so, show a dialog to confirm that the user wants to open the 165 // directory. If so, calls ConfirmSensitiveDirectoryAccess. Otherwise, calls
179 // directory. Calls OnDirectoryAccessConfirmed if the directory isn't 166 // OnDirectoryAccessConfirmed.
180 // sensitive or the user chooses to open it. Otherwise, calls
181 // FileSelectionCanceled.
182 void ConfirmDirectoryAccessAsync(bool non_native_path, 167 void ConfirmDirectoryAccessAsync(bool non_native_path,
183 const std::vector<base::FilePath>& paths, 168 const std::vector<base::FilePath>& paths,
184 content::WebContents* web_contents); 169 content::WebContents* web_contents);
Devlin 2017/06/14 14:53:22 \n
michaelpg 2017/06/21 00:40:08 Done.
170 // Shows a dialog to confirm whether the user wants to open the directory.
171 // Calls OnDirectoryAccessConfirmed or FileSelectionCanceled.
172 void ConfirmSensitiveDirectoryAccess(const std::vector<base::FilePath>& paths,
173 content::WebContents* web_contents);
Devlin 2017/06/14 14:53:22 \n
michaelpg 2017/06/21 00:40:07 Done.
185 void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths); 174 void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths);
186 175
187 base::FilePath initial_path_; 176 base::FilePath initial_path_;
188 }; 177 };
189 178
190 class FileSystemRetainEntryFunction : public ChromeAsyncExtensionFunction { 179 class FileSystemRetainEntryFunction : public UIThreadExtensionFunction {
191 public: 180 public:
192 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) 181 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY)
193 182
194 protected: 183 protected:
195 ~FileSystemRetainEntryFunction() override {} 184 ~FileSystemRetainEntryFunction() override {}
196 bool RunAsync() override; 185 ResponseAction Run() override;
197 186
198 private: 187 private:
199 // Retains the file entry referenced by |entry_id| in apps::SavedFilesService. 188 // Retains the file entry referenced by |entry_id| in apps::SavedFilesService.
200 // |entry_id| must refer to an entry in an isolated file system. |path| is a 189 // |entry_id| must refer to an entry in an isolated file system. |path| is a
201 // path of the entry. |file_info| is base::File::Info of the entry if it can 190 // path of the entry. |file_info| is base::File::Info of the entry if it can
202 // be obtained. 191 // be obtained.
203 void RetainFileEntry(const std::string& entry_id, 192 void RetainFileEntry(const std::string& entry_id,
204 const base::FilePath& path, 193 const base::FilePath& path,
205 std::unique_ptr<base::File::Info> file_info); 194 std::unique_ptr<base::File::Info> file_info);
206 }; 195 };
207 196
208 class FileSystemIsRestorableFunction : public UIThreadExtensionFunction { 197 class FileSystemIsRestorableFunction : public UIThreadExtensionFunction {
209 public: 198 public:
210 DECLARE_EXTENSION_FUNCTION("fileSystem.isRestorable", FILESYSTEM_ISRESTORABLE) 199 DECLARE_EXTENSION_FUNCTION("fileSystem.isRestorable", FILESYSTEM_ISRESTORABLE)
211 200
212 protected: 201 protected:
213 ~FileSystemIsRestorableFunction() override {} 202 ~FileSystemIsRestorableFunction() override {}
214 ResponseAction Run() override; 203 ResponseAction Run() override;
215 }; 204 };
216 205
217 class FileSystemRestoreEntryFunction : public FileSystemEntryFunction { 206 class FileSystemRestoreEntryFunction : public FileSystemEntryFunction {
218 public: 207 public:
219 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) 208 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY)
220 209
221 protected: 210 protected:
222 ~FileSystemRestoreEntryFunction() override {} 211 ~FileSystemRestoreEntryFunction() override {}
223 bool RunAsync() override; 212 ResponseAction Run() override;
224 }; 213 };
225 214
226 class FileSystemObserveDirectoryFunction : public UIThreadExtensionFunction { 215 class FileSystemObserveDirectoryFunction : public UIThreadExtensionFunction {
227 public: 216 public:
228 DECLARE_EXTENSION_FUNCTION("fileSystem.observeDirectory", 217 DECLARE_EXTENSION_FUNCTION("fileSystem.observeDirectory",
229 FILESYSTEM_OBSERVEDIRECTORY) 218 FILESYSTEM_OBSERVEDIRECTORY)
230 219
231 protected: 220 protected:
232 ~FileSystemObserveDirectoryFunction() override {} 221 ~FileSystemObserveDirectoryFunction() override {}
233 ResponseAction Run() override; 222 ResponseAction Run() override;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 279
291 protected: 280 protected:
292 ~FileSystemRequestFileSystemFunction() override; 281 ~FileSystemRequestFileSystemFunction() override;
293 282
294 // UIThreadExtensionFunction overrides. 283 // UIThreadExtensionFunction overrides.
295 ExtensionFunction::ResponseAction Run() override; 284 ExtensionFunction::ResponseAction Run() override;
296 285
297 private: 286 private:
298 // Called when a user grants or rejects permissions for the file system 287 // Called when a user grants or rejects permissions for the file system
299 // access. 288 // access.
300 void OnConsentReceived(const base::WeakPtr<file_manager::Volume>& volume, 289 void OnGotFileSystem(const std::string& id, const std::string& path);
301 bool writable, 290 void OnError(const std::string& error);
302 file_system_api::ConsentProvider::Consent result);
303
304 ChromeExtensionFunctionDetails chrome_details_;
305 }; 291 };
306 292
307 // Requests a list of available volumes. 293 // Requests a list of available volumes.
308 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction { 294 class FileSystemGetVolumeListFunction : public UIThreadExtensionFunction {
309 public: 295 public:
310 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList", 296 DECLARE_EXTENSION_FUNCTION("fileSystem.getVolumeList",
311 FILESYSTEM_GETVOLUMELIST); 297 FILESYSTEM_GETVOLUMELIST);
312 FileSystemGetVolumeListFunction(); 298 FileSystemGetVolumeListFunction();
313 299
314 protected: 300 protected:
315 ~FileSystemGetVolumeListFunction() override; 301 ~FileSystemGetVolumeListFunction() override;
316 302
317 // UIThreadExtensionFunction overrides. 303 // UIThreadExtensionFunction overrides.
318 ExtensionFunction::ResponseAction Run() override; 304 ExtensionFunction::ResponseAction Run() override;
319 305
320 private: 306 private:
321 ChromeExtensionFunctionDetails chrome_details_; 307 void OnGotVolumeList(const std::vector<api::file_system::Volume>& volumes);
308 void OnError(const std::string& error);
322 }; 309 };
323 #endif 310 #endif
324 311
325 } // namespace extensions 312 } // namespace extensions
326 313
327 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ 314 #endif // EXTENSIONS_BROWSER_API_FILE_SYSTEM_FILE_SYSTEM_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698