1 // Copyright 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.
5 // This file provides file system related API functions.
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_
12 #include "base/platform_file.h"
13 #include "chrome/browser/chromeos/drive/file_errors.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
23 class FileSystemContext;
26 namespace extensions {
28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method.
29 class FileBrowserPrivateRequestFileSystemFunction
30 : public LoggedAsyncExtensionFunction {
32 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem",
33 FILEBROWSERPRIVATE_REQUESTFILESYSTEM)
36 virtual ~FileBrowserPrivateRequestFileSystemFunction() {}
38 // AsyncExtensionFunction overrides.
39 virtual bool RunImpl() OVERRIDE;
42 void RespondSuccessOnUIThread(const std::string& name,
43 const GURL& root_url);
44 void RespondFailedOnUIThread(base::PlatformFileError error_code);
46 // Called when something goes wrong. Records the error to |error_| per the
47 // error code and reports that the private API function failed.
48 void DidFail(base::PlatformFileError error_code);
50 // Sets up file system access permissions to the extension identified by
52 bool SetupFileSystemAccessPermissions(
53 scoped_refptr<fileapi::FileSystemContext> file_system_context,
55 scoped_refptr<const extensions::Extension> extension);
58 // Base class for FileBrowserPrivateAddFileWatchFunction and
59 // FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
60 // the class and its sub classes are used only for watching changes in
62 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
64 virtual ~FileWatchFunctionBase() {}
66 // Performs a file watch operation (ex. adds or removes a file watch).
67 virtual void PerformFileWatchOperation(
68 const base::FilePath& local_path,
69 const base::FilePath& virtual_path,
70 const std::string& extension_id) = 0;
72 // AsyncExtensionFunction overrides.
73 virtual bool RunImpl() OVERRIDE;
75 // Calls SendResponse() with |success| converted to base::Value.
76 void Respond(bool success);
79 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
80 // Starts watching changes in directories.
81 class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase {
83 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
84 FILEBROWSERPRIVATE_ADDFILEWATCH)
87 virtual ~FileBrowserPrivateAddFileWatchFunction() {}
89 // FileWatchFunctionBase override.
90 virtual void PerformFileWatchOperation(
91 const base::FilePath& local_path,
92 const base::FilePath& virtual_path,
93 const std::string& extension_id) OVERRIDE;
97 // Implements the chrome.fileBrowserPrivate.removeFileWatch method.
98 // Stops watching changes in directories.
99 class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
101 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
102 FILEBROWSERPRIVATE_REMOVEFILEWATCH)
105 virtual ~FileBrowserPrivateRemoveFileWatchFunction() {}
107 // FileWatchFunctionBase override.
108 virtual void PerformFileWatchOperation(
109 const base::FilePath& local_path,
110 const base::FilePath& virtual_path,
111 const std::string& extension_id) OVERRIDE;
114 // Implements the chrome.fileBrowserPrivate.getSizeStats method.
115 class FileBrowserPrivateGetSizeStatsFunction
116 : public LoggedAsyncExtensionFunction {
118 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
119 FILEBROWSERPRIVATE_GETSIZESTATS)
122 virtual ~FileBrowserPrivateGetSizeStatsFunction() {}
124 // AsyncExtensionFunction overrides.
125 virtual bool RunImpl() OVERRIDE;
128 void GetDriveAvailableSpaceCallback(drive::FileError error,
132 void GetSizeStatsCallback(const uint64* total_size,
133 const uint64* remaining_size);
136 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
137 class FileBrowserPrivateValidatePathNameLengthFunction
138 : public LoggedAsyncExtensionFunction {
140 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
141 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH)
144 virtual ~FileBrowserPrivateValidatePathNameLengthFunction() {}
146 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
148 // AsyncExtensionFunction overrides.
149 virtual bool RunImpl() OVERRIDE;
152 // Implements the chrome.fileBrowserPrivate.formatDevice method.
153 // Formats Device given its mount path.
154 class FileBrowserPrivateFormatDeviceFunction
155 : public LoggedAsyncExtensionFunction {
157 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice",
158 FILEBROWSERPRIVATE_FORMATDEVICE)
161 virtual ~FileBrowserPrivateFormatDeviceFunction() {}
163 // AsyncExtensionFunction overrides.
164 virtual bool RunImpl() OVERRIDE;
167 // Implements the chrome.fileBrowserPrivate.startCopy method.
168 class FileBrowserPrivateStartCopyFunction
169 : public LoggedAsyncExtensionFunction {
171 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.startCopy",
172 FILEBROWSERPRIVATE_STARTCOPY)
175 virtual ~FileBrowserPrivateStartCopyFunction() {}
177 // AsyncExtensionFunction overrides.
178 virtual bool RunImpl() OVERRIDE;
181 // Part of RunImpl(). Called after Copy() is started on IO thread.
182 void RunAfterStartCopy(int operation_id);
185 // Implements the chrome.fileBrowserPrivate.cancelCopy method.
186 class FileBrowserPrivateCancelCopyFunction
187 : public LoggedAsyncExtensionFunction {
189 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelCopy",
190 FILEBROWSERPRIVATE_CANCELCOPY)
193 virtual ~FileBrowserPrivateCancelCopyFunction() {}
195 // AsyncExtensionFunction overrides.
196 virtual bool RunImpl() OVERRIDE;
199 } // namespace extensions
201 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_