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

Side by Side Diff: chrome/browser/extensions/extension_file_browser_private_api.h

Issue 8497007: Switch from MountLibrary to CrosDisksLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on ToT Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "chrome/browser/extensions/extension_function.h" 14 #include "chrome/browser/extensions/extension_function.h"
15 #include "googleurl/src/url_util.h" 15 #include "googleurl/src/url_util.h"
16 #include "webkit/fileapi/file_system_callback_dispatcher.h" 16 #include "webkit/fileapi/file_system_callback_dispatcher.h"
17 17
18 #ifdef OS_CHROMEOS 18 #ifdef OS_CHROMEOS
19 #include "chrome/browser/chromeos/cros/mount_library.h" 19 #include "chrome/browser/chromeos/disks/disk_mount_manager.h"
20 #endif 20 #endif
21 21
22 class GURL; 22 class GURL;
23 23
24 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. 24 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method.
25 class RequestLocalFileSystemFunction : public AsyncExtensionFunction { 25 class RequestLocalFileSystemFunction : public AsyncExtensionFunction {
26 protected: 26 protected:
27 friend class LocalFileSystemCallbackDispatcher;
28 // AsyncExtensionFunction overrides. 27 // AsyncExtensionFunction overrides.
29 virtual bool RunImpl() OVERRIDE; 28 virtual bool RunImpl() OVERRIDE;
29
30 private:
31 class LocalFileSystemCallbackDispatcher;
32
30 void RespondSuccessOnUIThread(const std::string& name, 33 void RespondSuccessOnUIThread(const std::string& name,
31 const GURL& root_path); 34 const GURL& root_path);
32 void RespondFailedOnUIThread(base::PlatformFileError error_code); 35 void RespondFailedOnUIThread(base::PlatformFileError error_code);
33 void RequestOnFileThread(const GURL& source_url, int child_id); 36 void RequestOnFileThread(const GURL& source_url, int child_id);
34 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); 37 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem");
35 }; 38 };
36 39
37 // Implements the chrome.fileBrowserPrivate.addFileWatch method. 40 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
38 class FileWatchBrowserFunctionBase : public AsyncExtensionFunction { 41 class FileWatchBrowserFunctionBase : public AsyncExtensionFunction {
39 protected: 42 protected:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // AsyncExtensionFunction overrides. 95 // AsyncExtensionFunction overrides.
93 virtual bool RunImpl() OVERRIDE; 96 virtual bool RunImpl() OVERRIDE;
94 97
95 private: 98 private:
96 struct FileDefinition { 99 struct FileDefinition {
97 GURL target_file_url; 100 GURL target_file_url;
98 FilePath virtual_path; 101 FilePath virtual_path;
99 bool is_directory; 102 bool is_directory;
100 }; 103 };
101 typedef std::vector<FileDefinition> FileDefinitionList; 104 typedef std::vector<FileDefinition> FileDefinitionList;
102 friend class ExecuteTasksFileSystemCallbackDispatcher; 105 class ExecuteTasksFileSystemCallbackDispatcher;
103 // Initates execution of context menu tasks identified with |task_id| for 106 // Initates execution of context menu tasks identified with |task_id| for
104 // each element of |files_list|. 107 // each element of |files_list|.
105 bool InitiateFileTaskExecution(const std::string& task_id, 108 bool InitiateFileTaskExecution(const std::string& task_id,
106 base::ListValue* files_list); 109 base::ListValue* files_list);
107 void RequestFileEntryOnFileThread(const GURL& source_url, 110 void RequestFileEntryOnFileThread(const GURL& source_url,
108 const std::string& task_id, 111 const std::string& task_id,
109 const std::vector<GURL>& file_urls); 112 const std::vector<GURL>& file_urls);
110 void RespondFailedOnUIThread(base::PlatformFileError error_code); 113 void RespondFailedOnUIThread(base::PlatformFileError error_code);
111 void ExecuteFileActionsOnUIThread(const std::string& task_id, 114 void ExecuteFileActionsOnUIThread(const std::string& task_id,
112 const std::string& file_system_name, 115 const std::string& file_system_name,
113 const GURL& file_system_root, 116 const GURL& file_system_root,
114 const FileDefinitionList& file_list); 117 const FileDefinitionList& file_list);
115 void ExecuteFailedOnUIThread(); 118 void ExecuteFailedOnUIThread();
116 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask"); 119 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask");
117 }; 120 };
118 121
119 // Parent class for the chromium extension APIs for the file dialog. 122 // Parent class for the chromium extension APIs for the file dialog.
120 class FileBrowserFunction 123 class FileBrowserFunction
121 : public AsyncExtensionFunction { 124 : public AsyncExtensionFunction {
122 public: 125 public:
123 FileBrowserFunction(); 126 FileBrowserFunction();
124 127
125 protected: 128 protected:
126 typedef std::vector<GURL> UrlList; 129 typedef std::vector<GURL> UrlList;
127 typedef std::vector<FilePath> FilePathList; 130 typedef std::vector<FilePath> FilePathList;
131 typedef base::Callback<void(const FilePathList&)> GetLocalPathsCallback;
128 132
129 virtual ~FileBrowserFunction(); 133 virtual ~FileBrowserFunction();
130 134
131 // Convert virtual paths to local paths on the file thread. 135 // Converts virtual paths to local paths by calling GetLocalPathsOnFileThread
132 void GetLocalPathsOnFileThread(const UrlList& file_urls, 136 // on the file thread and call |callback| on the UI thread with the result.
133 void* context); 137 void GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
134 138 const UrlList& file_urls,
135 // Callback with converted local paths. 139 GetLocalPathsCallback callback);
136 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files,
137 void* context) {}
138 140
139 // Figure out the tab_id of the hosting tab. 141 // Figure out the tab_id of the hosting tab.
140 int32 GetTabId() const; 142 int32 GetTabId() const;
143
144 private:
145 // Converts virtual paths to local paths and call |callback| (on the UI
146 // thread) with the results.
147 // This method must be called from the file thread.
148 void GetLocalPathsOnFileThread(const UrlList& file_urls,
149 GetLocalPathsCallback callback);
141 }; 150 };
142 151
143 // Select a single file. Closes the dialog window. 152 // Select a single file. Closes the dialog window.
144 class SelectFileFunction 153 class SelectFileFunction
145 : public FileBrowserFunction { 154 : public FileBrowserFunction {
146 public: 155 public:
147 SelectFileFunction() {} 156 SelectFileFunction() {}
148 157
149 protected: 158 protected:
150 virtual ~SelectFileFunction() {} 159 virtual ~SelectFileFunction() {}
151 160
152 // AsyncExtensionFunction overrides. 161 // AsyncExtensionFunction overrides.
153 virtual bool RunImpl() OVERRIDE; 162 virtual bool RunImpl() OVERRIDE;
154 163
155 // FileBrowserFunction overrides. 164 private:
156 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, 165 // A callback method to handle the result of
157 void* context) OVERRIDE; 166 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
167 void GetLocalPathsResponseOnUIThread(const FilePathList& files);
158 168
159 private:
160 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile"); 169 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile");
161 }; 170 };
162 171
163 // View multiple selected files. Window stays open. 172 // View multiple selected files. Window stays open.
164 class ViewFilesFunction 173 class ViewFilesFunction
165 : public FileBrowserFunction { 174 : public FileBrowserFunction {
166 public: 175 public:
167 ViewFilesFunction(); 176 ViewFilesFunction();
168 177
169 protected: 178 protected:
170 virtual ~ViewFilesFunction(); 179 virtual ~ViewFilesFunction();
171 180
172 // AsyncExtensionFunction overrides. 181 // AsyncExtensionFunction overrides.
173 virtual bool RunImpl() OVERRIDE; 182 virtual bool RunImpl() OVERRIDE;
174 183
175 // FileBrowserFunction overrides. 184 private:
176 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, 185 // A callback method to handle the result of
177 void* context) OVERRIDE; 186 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
187 void GetLocalPathsResponseOnUIThread(const std::string& internal_task_id,
188 const FilePathList& files);
178 189
179 private:
180 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles"); 190 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles");
181 }; 191 };
182 192
183 // Select multiple files. Closes the dialog window. 193 // Select multiple files. Closes the dialog window.
184 class SelectFilesFunction 194 class SelectFilesFunction
185 : public FileBrowserFunction { 195 : public FileBrowserFunction {
186 public: 196 public:
187 SelectFilesFunction(); 197 SelectFilesFunction();
188 198
189 protected: 199 protected:
190 virtual ~SelectFilesFunction(); 200 virtual ~SelectFilesFunction();
191 201
192 // AsyncExtensionFunction overrides. 202 // AsyncExtensionFunction overrides.
193 virtual bool RunImpl() OVERRIDE; 203 virtual bool RunImpl() OVERRIDE;
194 204
195 // FileBrowserFunction overrides. 205 private:
196 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, 206 // A callback method to handle the result of
197 void* context) OVERRIDE; 207 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
208 void GetLocalPathsResponseOnUIThread(const FilePathList& files);
198 209
199 private:
200 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles"); 210 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles");
201 }; 211 };
202 212
203 // Cancel file selection Dialog. Closes the dialog window. 213 // Cancel file selection Dialog. Closes the dialog window.
204 class CancelFileDialogFunction 214 class CancelFileDialogFunction
205 : public FileBrowserFunction { 215 : public FileBrowserFunction {
206 public: 216 public:
207 CancelFileDialogFunction() {} 217 CancelFileDialogFunction() {}
208 218
209 protected: 219 protected:
210 virtual ~CancelFileDialogFunction() {} 220 virtual ~CancelFileDialogFunction() {}
211 221
212 // AsyncExtensionFunction overrides. 222 // AsyncExtensionFunction overrides.
213 virtual bool RunImpl() OVERRIDE; 223 virtual bool RunImpl() OVERRIDE;
214 224
215 private: 225 private:
216 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.cancelDialog"); 226 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.cancelDialog");
217 }; 227 };
218 228
219 // Mount a device or a file. 229 // Mount a device or a file.
220 class AddMountFunction 230 class AddMountFunction
221 : public FileBrowserFunction { 231 : public FileBrowserFunction {
222 public: 232 public:
223 AddMountFunction(); 233 AddMountFunction();
224 234
225 protected: 235 protected:
226 virtual ~AddMountFunction(); 236 virtual ~AddMountFunction();
227 237
238 // AsyncExtensionFunction overrides.
228 virtual bool RunImpl() OVERRIDE; 239 virtual bool RunImpl() OVERRIDE;
229 240
230 // FileBrowserFunction overrides.
231 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files,
232 void* context) OVERRIDE;
233
234 private: 241 private:
235 #if defined(OS_CHROMEOS) 242 // A callback method to handle the result of
236 struct MountParamaters { 243 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
237 MountParamaters(const std::string& type, 244 void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str,
238 const chromeos::MountPathOptions& options) 245 const FilePathList& files);
239 : mount_type(type), mount_options(options) {}
240 ~MountParamaters() {}
241 std::string mount_type;
242 chromeos::MountPathOptions mount_options;
243 };
244 #endif
245 246
246 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount"); 247 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount");
247 }; 248 };
248 249
249 // Unmounts selected device. Expects mount point path as an argument. 250 // Unmounts selected device. Expects mount point path as an argument.
250 class RemoveMountFunction 251 class RemoveMountFunction
251 : public FileBrowserFunction { 252 : public FileBrowserFunction {
252 public: 253 public:
253 RemoveMountFunction(); 254 RemoveMountFunction();
254 255
255 protected: 256 protected:
256 virtual ~RemoveMountFunction(); 257 virtual ~RemoveMountFunction();
257 258
258 // FileBrowserFunction overrides. 259 // AsyncExtensionFunction overrides.
259 virtual bool RunImpl() OVERRIDE; 260 virtual bool RunImpl() OVERRIDE;
260 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files,
261 void* context) OVERRIDE;
262 261
263 private: 262 private:
263 // A callback method to handle the result of
264 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
265 void GetLocalPathsResponseOnUIThread(const FilePathList& files);
266
264 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); 267 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount");
265 }; 268 };
266 269
267 class GetMountPointsFunction 270 class GetMountPointsFunction
268 : public AsyncExtensionFunction { 271 : public AsyncExtensionFunction {
269 public: 272 public:
270 GetMountPointsFunction(); 273 GetMountPointsFunction();
271 274
272 protected: 275 protected:
273 virtual ~GetMountPointsFunction(); 276 virtual ~GetMountPointsFunction();
274 277
278 // AsyncExtensionFunction overrides.
275 virtual bool RunImpl() OVERRIDE; 279 virtual bool RunImpl() OVERRIDE;
276 280
277 private: 281 private:
278 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints"); 282 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints");
279 }; 283 };
280 284
281 // Formats Device given its mount path. 285 // Formats Device given its mount path.
282 class FormatDeviceFunction 286 class FormatDeviceFunction
283 : public FileBrowserFunction { 287 : public FileBrowserFunction {
284 public: 288 public:
285 FormatDeviceFunction(); 289 FormatDeviceFunction();
286 290
287 protected: 291 protected:
288 virtual ~FormatDeviceFunction(); 292 virtual ~FormatDeviceFunction();
289 293
294 // AsyncExtensionFunction overrides.
290 virtual bool RunImpl() OVERRIDE; 295 virtual bool RunImpl() OVERRIDE;
291 296
292 // FileBrowserFunction overrides. 297 private:
293 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, 298 // A callback method to handle the result of
294 void* context) OVERRIDE; 299 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
300 void GetLocalPathsResponseOnUIThread(const FilePathList& files);
295 301
296 private:
297 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice"); 302 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice");
298 }; 303 };
299 304
300 class GetSizeStatsFunction 305 class GetSizeStatsFunction
301 : public FileBrowserFunction { 306 : public FileBrowserFunction {
302 public: 307 public:
303 GetSizeStatsFunction(); 308 GetSizeStatsFunction();
304 309
305 protected: 310 protected:
306 virtual ~GetSizeStatsFunction(); 311 virtual ~GetSizeStatsFunction();
307 312
308 // FileBrowserFunction overrides. 313 // AsyncExtensionFunction overrides.
309 virtual bool RunImpl() OVERRIDE; 314 virtual bool RunImpl() OVERRIDE;
310 virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files,
311 void* context) OVERRIDE;
312 315
313 private: 316 private:
314 void GetSizeStatsCallbackOnUIThread(const char* mount_path, 317 // A callback method to handle the result of
318 // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
319 void GetLocalPathsResponseOnUIThread(const FilePathList& files);
320
321 void GetSizeStatsCallbackOnUIThread(const std::string& mount_path,
315 size_t total_size_kb, 322 size_t total_size_kb,
316 size_t remaining_size_kb); 323 size_t remaining_size_kb);
317 void CallGetSizeStatsOnFileThread(const char* mount_path); 324 void CallGetSizeStatsOnFileThread(const std::string& mount_path);
318 325
319 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getSizeStats"); 326 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getSizeStats");
320 }; 327 };
321 328
322 // Retrieves devices meta-data. Expects volume's device path as an argument. 329 // Retrieves devices meta-data. Expects volume's device path as an argument.
323 class GetVolumeMetadataFunction 330 class GetVolumeMetadataFunction
324 : public SyncExtensionFunction { 331 : public SyncExtensionFunction {
325 public: 332 public:
326 GetVolumeMetadataFunction(); 333 GetVolumeMetadataFunction();
327 334
(...skipping 19 matching lines...) Expand all
347 virtual ~FileDialogStringsFunction() {} 354 virtual ~FileDialogStringsFunction() {}
348 355
349 // SyncExtensionFunction overrides. 356 // SyncExtensionFunction overrides.
350 virtual bool RunImpl() OVERRIDE; 357 virtual bool RunImpl() OVERRIDE;
351 358
352 private: 359 private:
353 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getStrings"); 360 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getStrings");
354 }; 361 };
355 362
356 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ 363 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698