OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
7 | 7 |
8 #include "chrome/browser/extensions/extension_function.h" | 8 #include "chrome/browser/extensions/extension_function.h" |
9 #include "chrome/common/extensions/api/file_system.h" | 9 #include "chrome/common/extensions/api/file_system.h" |
10 #include "ui/shell_dialogs/select_file_dialog.h" | 10 #include "ui/shell_dialogs/select_file_dialog.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 WRITABLE | 50 WRITABLE |
51 }; | 51 }; |
52 | 52 |
53 virtual ~FileSystemEntryFunction() {} | 53 virtual ~FileSystemEntryFunction() {} |
54 | 54 |
55 bool HasFileSystemWritePermission(); | 55 bool HasFileSystemWritePermission(); |
56 | 56 |
57 // This is called when a writable file entry is being returned. The function | 57 // This is called when a writable file entry is being returned. The function |
58 // will ensure the file exists, creating it if necessary, and also check that | 58 // will ensure the file exists, creating it if necessary, and also check that |
59 // the file is not a link. If it succeeds it proceeds to | 59 // the file is not a link. If it succeeds it proceeds to |
60 // RegisterFileSystemAndSendResponse, otherwise to HandleWritableFileError. | 60 // RegisterFileSystemsAndSendResponse, otherwise to HandleWritableFileError. |
61 void CheckWritableFile(const base::FilePath& path); | 61 void CheckWritableFile(const base::FilePath& path); |
62 void CheckWritableFiles(const std::vector<base::FilePath>& path, | |
benwells
2013/08/01 07:48:33
Nit: document both methods, and |multiple|.
Sam McNally
2013/08/02 05:35:31
Done.
| |
63 bool multiple); | |
62 | 64 |
63 // This will finish the choose file process. This is either called directly | 65 // This will finish the choose file process. This is either called directly |
64 // from FileSelected, or from CreateFileIfNecessary. It is called on the UI | 66 // from FilesSelected, or from WritableFileCheckHelper. It is called on the UI |
65 // thread. | 67 // thread. |multiple| should be true if multiple files were requested. |
66 void RegisterFileSystemAndSendResponse(const base::FilePath& path, | 68 void RegisterFileSystemsAndSendResponse( |
67 EntryType entry_type); | 69 const std::vector<base::FilePath>& path, |
70 EntryType entry_type, | |
71 bool multiple); | |
68 | 72 |
69 // This will finish the choose file process. This is either called directly | 73 // This will finish the choose file process. This is called from |
70 // from FileSelected, or from CreateFileIfNecessary. It is called on the UI | 74 // FileSystemIsRestorableFunction::RunImpl. |id_override| specifies the id to |
71 // thread. |id_override| specifies the id to send in the response instead of | 75 // send in the response instead of the generated id. This can be useful for |
72 // the generated id. This can be useful for creating a file entry with an id | 76 // creating a file entry with an id matching another file entry, e.g. for |
73 // matching another file entry, e.g. for restoreEntry. | 77 // restoreEntry. |
74 void RegisterFileSystemAndSendResponseWithIdOverride( | 78 void RegisterFileSystemAndSendResponseWithIdOverride( |
75 const base::FilePath& path, | 79 const base::FilePath& path, |
76 EntryType entry_type, | 80 EntryType entry_type, |
77 const std::string& id_override); | 81 const std::string& id_override); |
78 | 82 |
83 // This will finish the choose file process. This is called from | |
84 // FileSystemIsRestorableFunction::RunImpl. This can be useful for creating a | |
85 // file entry with an id matching another file entry, e.g. for restoreEntry. | |
86 void RegisterFileSystemsAndSendResponseWithIdOverrides( | |
87 const std::vector<std::pair<base::FilePath, std::string> >& | |
88 paths_and_overrides, | |
89 EntryType entry_type, | |
90 bool multiple); | |
91 | |
92 base::DictionaryValue* BuildEntryDict(const base::FilePath& path, | |
93 EntryType entry_type, | |
94 const std::string& id); | |
95 | |
79 // called on the UI thread if there is a problem checking a writable file. | 96 // called on the UI thread if there is a problem checking a writable file. |
80 void HandleWritableFileError(); | 97 void HandleWritableFileError(const std::string& error); |
81 }; | 98 }; |
82 | 99 |
83 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { | 100 class FileSystemGetWritableEntryFunction : public FileSystemEntryFunction { |
84 public: | 101 public: |
85 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", | 102 DECLARE_EXTENSION_FUNCTION("fileSystem.getWritableEntry", |
86 FILESYSTEM_GETWRITABLEENTRY) | 103 FILESYSTEM_GETWRITABLEENTRY) |
87 | 104 |
88 protected: | 105 protected: |
89 virtual ~FileSystemGetWritableEntryFunction() {} | 106 virtual ~FileSystemGetWritableEntryFunction() {} |
90 virtual bool RunImpl() OVERRIDE; | 107 virtual bool RunImpl() OVERRIDE; |
91 }; | 108 }; |
92 | 109 |
93 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { | 110 class FileSystemIsWritableEntryFunction : public SyncExtensionFunction { |
94 public: | 111 public: |
95 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", | 112 DECLARE_EXTENSION_FUNCTION("fileSystem.isWritableEntry", |
96 FILESYSTEM_ISWRITABLEENTRY) | 113 FILESYSTEM_ISWRITABLEENTRY) |
97 | 114 |
98 protected: | 115 protected: |
99 virtual ~FileSystemIsWritableEntryFunction() {} | 116 virtual ~FileSystemIsWritableEntryFunction() {} |
100 virtual bool RunImpl() OVERRIDE; | 117 virtual bool RunImpl() OVERRIDE; |
101 }; | 118 }; |
102 | 119 |
103 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { | 120 class FileSystemChooseEntryFunction : public FileSystemEntryFunction { |
104 public: | 121 public: |
105 // Allow picker UI to be skipped in testing. | 122 // Allow picker UI to be skipped in testing. |
106 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); | 123 static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); |
124 static void SkipPickerAndAlwaysSelectPathsForTest( | |
125 std::vector<base::FilePath>* paths); | |
107 static void SkipPickerAndSelectSuggestedPathForTest(); | 126 static void SkipPickerAndSelectSuggestedPathForTest(); |
108 static void SkipPickerAndAlwaysCancelForTest(); | 127 static void SkipPickerAndAlwaysCancelForTest(); |
109 static void StopSkippingPickerForTest(); | 128 static void StopSkippingPickerForTest(); |
110 // Call this with the directory for test file paths. On Chrome OS, accessed | 129 // Call this with the directory for test file paths. On Chrome OS, accessed |
111 // path needs to be explicitly registered for smooth integration with Google | 130 // path needs to be explicitly registered for smooth integration with Google |
112 // Drive support. | 131 // Drive support. |
113 static void RegisterTempExternalFileSystemForTest(const std::string& name, | 132 static void RegisterTempExternalFileSystemForTest(const std::string& name, |
114 const base::FilePath& path); | 133 const base::FilePath& path); |
115 | 134 |
116 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) | 135 DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) |
(...skipping 10 matching lines...) Expand all Loading... | |
127 base::FilePath* suggested_name, | 146 base::FilePath* suggested_name, |
128 base::FilePath::StringType* suggested_extension); | 147 base::FilePath::StringType* suggested_extension); |
129 | 148 |
130 protected: | 149 protected: |
131 class FilePicker; | 150 class FilePicker; |
132 | 151 |
133 virtual ~FileSystemChooseEntryFunction() {} | 152 virtual ~FileSystemChooseEntryFunction() {} |
134 virtual bool RunImpl() OVERRIDE; | 153 virtual bool RunImpl() OVERRIDE; |
135 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, | 154 void ShowPicker(const ui::SelectFileDialog::FileTypeInfo& file_type_info, |
136 ui::SelectFileDialog::Type picker_type, | 155 ui::SelectFileDialog::Type picker_type, |
137 EntryType entry_type); | 156 EntryType entry_type, |
157 bool multiple); | |
138 | 158 |
139 private: | 159 private: |
140 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, | 160 void SetInitialPathOnFileThread(const base::FilePath& suggested_name, |
141 const base::FilePath& previous_path); | 161 const base::FilePath& previous_path); |
142 | 162 |
143 // FileSelected and FileSelectionCanceled are called by the file picker. | 163 // FilesSelected and FileSelectionCanceled are called by the file picker. |
144 void FileSelected(const base::FilePath& path, EntryType entry_type); | 164 void FilesSelected(const std::vector<base::FilePath>& path, |
165 EntryType entry_type, | |
166 bool multiple); | |
145 void FileSelectionCanceled(); | 167 void FileSelectionCanceled(); |
146 | 168 |
147 base::FilePath initial_path_; | 169 base::FilePath initial_path_; |
148 }; | 170 }; |
149 | 171 |
150 class FileSystemRetainEntryFunction : public SyncExtensionFunction { | 172 class FileSystemRetainEntryFunction : public SyncExtensionFunction { |
151 public: | 173 public: |
152 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) | 174 DECLARE_EXTENSION_FUNCTION("fileSystem.retainEntry", FILESYSTEM_RETAINENTRY) |
153 | 175 |
154 protected: | 176 protected: |
(...skipping 20 matching lines...) Expand all Loading... | |
175 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) | 197 DECLARE_EXTENSION_FUNCTION("fileSystem.restoreEntry", FILESYSTEM_RESTOREENTRY) |
176 | 198 |
177 protected: | 199 protected: |
178 virtual ~FileSystemRestoreEntryFunction() {} | 200 virtual ~FileSystemRestoreEntryFunction() {} |
179 virtual bool RunImpl() OVERRIDE; | 201 virtual bool RunImpl() OVERRIDE; |
180 }; | 202 }; |
181 | 203 |
182 } // namespace extensions | 204 } // namespace extensions |
183 | 205 |
184 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ | 206 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_API_H_ |
OLD | NEW |