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::File::Error 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::File::Error 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,
56 scoped_refptr<const extensions::Extension> extension);
59 // Base class for FileBrowserPrivateAddFileWatchFunction and
60 // FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
61 // the class and its sub classes are used only for watching changes in
63 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
65 virtual ~FileWatchFunctionBase() {}
67 // Performs a file watch operation (ex. adds or removes a file watch).
68 virtual void PerformFileWatchOperation(
69 const base::FilePath& local_path,
70 const base::FilePath& virtual_path,
71 const std::string& extension_id) = 0;
73 // AsyncExtensionFunction overrides.
74 virtual bool RunImpl() OVERRIDE;
76 // Calls SendResponse() with |success| converted to base::Value.
77 void Respond(bool success);
80 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
81 // Starts watching changes in directories.
82 class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase {
84 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
85 FILEBROWSERPRIVATE_ADDFILEWATCH)
88 virtual ~FileBrowserPrivateAddFileWatchFunction() {}
90 // FileWatchFunctionBase override.
91 virtual void PerformFileWatchOperation(
92 const base::FilePath& local_path,
93 const base::FilePath& virtual_path,
94 const std::string& extension_id) OVERRIDE;
98 // Implements the chrome.fileBrowserPrivate.removeFileWatch method.
99 // Stops watching changes in directories.
100 class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
102 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
103 FILEBROWSERPRIVATE_REMOVEFILEWATCH)
106 virtual ~FileBrowserPrivateRemoveFileWatchFunction() {}
108 // FileWatchFunctionBase override.
109 virtual void PerformFileWatchOperation(
110 const base::FilePath& local_path,
111 const base::FilePath& virtual_path,
112 const std::string& extension_id) OVERRIDE;
115 // Implements the chrome.fileBrowserPrivate.getSizeStats method.
116 class FileBrowserPrivateGetSizeStatsFunction
117 : public LoggedAsyncExtensionFunction {
119 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
120 FILEBROWSERPRIVATE_GETSIZESTATS)
123 virtual ~FileBrowserPrivateGetSizeStatsFunction() {}
125 // AsyncExtensionFunction overrides.
126 virtual bool RunImpl() OVERRIDE;
129 void GetDriveAvailableSpaceCallback(drive::FileError error,
133 void GetSizeStatsCallback(const uint64* total_size,
134 const uint64* remaining_size);
137 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
138 class FileBrowserPrivateValidatePathNameLengthFunction
139 : public LoggedAsyncExtensionFunction {
141 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
142 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH)
145 virtual ~FileBrowserPrivateValidatePathNameLengthFunction() {}
147 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
149 // AsyncExtensionFunction overrides.
150 virtual bool RunImpl() OVERRIDE;
153 // Implements the chrome.fileBrowserPrivate.formatVolume method.
154 // Formats Volume given its mount path.
155 class FileBrowserPrivateFormatVolumeFunction
156 : public LoggedAsyncExtensionFunction {
158 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatVolume",
159 FILEBROWSERPRIVATE_FORMATVOLUME)
162 virtual ~FileBrowserPrivateFormatVolumeFunction() {}
164 // AsyncExtensionFunction overrides.
165 virtual bool RunImpl() OVERRIDE;
168 // Implements the chrome.fileBrowserPrivate.startCopy method.
169 class FileBrowserPrivateStartCopyFunction
170 : public LoggedAsyncExtensionFunction {
172 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.startCopy",
173 FILEBROWSERPRIVATE_STARTCOPY)
176 virtual ~FileBrowserPrivateStartCopyFunction() {}
178 // AsyncExtensionFunction overrides.
179 virtual bool RunImpl() OVERRIDE;
182 // Part of RunImpl(). Called after Copy() is started on IO thread.
183 void RunAfterStartCopy(int operation_id);
186 // Implements the chrome.fileBrowserPrivate.cancelCopy method.
187 class FileBrowserPrivateCancelCopyFunction
188 : public LoggedAsyncExtensionFunction {
190 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelCopy",
191 FILEBROWSERPRIVATE_CANCELCOPY)
194 virtual ~FileBrowserPrivateCancelCopyFunction() {}
196 // AsyncExtensionFunction overrides.
197 virtual bool RunImpl() OVERRIDE;
200 } // namespace extensions
202 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_