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 "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
22 class FileSystemContext;
24 } // namespace storage
26 namespace file_manager {
28 struct EntryDefinition;
29 typedef std::vector<EntryDefinition> EntryDefinitionList;
31 } // namespace file_manager
33 namespace extensions {
35 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
36 class FileManagerPrivateRequestFileSystemFunction
37 : public LoggedAsyncExtensionFunction {
39 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
40 FILEMANAGERPRIVATE_REQUESTFILESYSTEM)
43 virtual ~FileManagerPrivateRequestFileSystemFunction() {}
45 // AsyncExtensionFunction overrides.
46 virtual bool RunAsync() override;
49 void RespondSuccessOnUIThread(const std::string& name,
50 const GURL& root_url);
51 void RespondFailedOnUIThread(base::File::Error error_code);
53 // Called when something goes wrong. Records the error to |error_| per the
54 // error code and reports that the private API function failed.
55 void DidFail(base::File::Error error_code);
57 // Sets up file system access permissions to the extension identified by
59 bool SetupFileSystemAccessPermissions(
60 scoped_refptr<storage::FileSystemContext> file_system_context,
63 scoped_refptr<const extensions::Extension> extension);
65 // Called when the entry definition is computed.
66 void OnEntryDefinition(
67 const file_manager::util::EntryDefinition& entry_definition);
70 // Base class for FileManagerPrivateAddFileWatchFunction and
71 // FileManagerPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
72 // the class and its sub classes are used only for watching changes in
74 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
76 // Calls SendResponse() with |success| converted to base::Value.
77 void Respond(bool success);
80 virtual ~FileWatchFunctionBase() {}
82 // Performs a file watch operation (ex. adds or removes a file watch).
83 virtual void PerformFileWatchOperation(
84 scoped_refptr<storage::FileSystemContext> file_system_context,
85 const storage::FileSystemURL& file_system_url,
86 const std::string& extension_id) = 0;
88 // AsyncExtensionFunction overrides.
89 virtual bool RunAsync() override;
92 // Implements the chrome.fileManagerPrivate.addFileWatch method.
93 // Starts watching changes in directories.
94 class FileManagerPrivateAddFileWatchFunction : public FileWatchFunctionBase {
96 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
97 FILEMANAGERPRIVATE_ADDFILEWATCH)
100 virtual ~FileManagerPrivateAddFileWatchFunction() {}
102 // FileWatchFunctionBase override.
103 virtual void PerformFileWatchOperation(
104 scoped_refptr<storage::FileSystemContext> file_system_context,
105 const storage::FileSystemURL& file_system_url,
106 const std::string& extension_id) override;
110 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
111 // Stops watching changes in directories.
112 class FileManagerPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
114 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
115 FILEMANAGERPRIVATE_REMOVEFILEWATCH)
118 virtual ~FileManagerPrivateRemoveFileWatchFunction() {}
120 // FileWatchFunctionBase override.
121 virtual void PerformFileWatchOperation(
122 scoped_refptr<storage::FileSystemContext> file_system_context,
123 const storage::FileSystemURL& file_system_url,
124 const std::string& extension_id) override;
127 // Implements the chrome.fileManagerPrivate.getSizeStats method.
128 class FileManagerPrivateGetSizeStatsFunction
129 : public LoggedAsyncExtensionFunction {
131 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
132 FILEMANAGERPRIVATE_GETSIZESTATS)
135 virtual ~FileManagerPrivateGetSizeStatsFunction() {}
137 // AsyncExtensionFunction overrides.
138 virtual bool RunAsync() override;
141 void GetDriveAvailableSpaceCallback(drive::FileError error,
145 void GetSizeStatsCallback(const uint64* total_size,
146 const uint64* remaining_size);
149 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
150 class FileManagerPrivateValidatePathNameLengthFunction
151 : public LoggedAsyncExtensionFunction {
153 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
154 FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH)
157 virtual ~FileManagerPrivateValidatePathNameLengthFunction() {}
159 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
161 // AsyncExtensionFunction overrides.
162 virtual bool RunAsync() override;
165 // Implements the chrome.fileManagerPrivate.formatVolume method.
166 // Formats Volume given its mount path.
167 class FileManagerPrivateFormatVolumeFunction
168 : public LoggedAsyncExtensionFunction {
170 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
171 FILEMANAGERPRIVATE_FORMATVOLUME)
174 virtual ~FileManagerPrivateFormatVolumeFunction() {}
176 // AsyncExtensionFunction overrides.
177 virtual bool RunAsync() override;
180 // Implements the chrome.fileManagerPrivate.startCopy method.
181 class FileManagerPrivateStartCopyFunction
182 : public LoggedAsyncExtensionFunction {
184 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
185 FILEMANAGERPRIVATE_STARTCOPY)
188 virtual ~FileManagerPrivateStartCopyFunction() {}
190 // AsyncExtensionFunction overrides.
191 virtual bool RunAsync() override;
194 // Part of RunAsync(). Called after Copy() is started on IO thread.
195 void RunAfterStartCopy(int operation_id);
198 // Implements the chrome.fileManagerPrivate.cancelCopy method.
199 class FileManagerPrivateCancelCopyFunction
200 : public LoggedAsyncExtensionFunction {
202 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
203 FILEMANAGERPRIVATE_CANCELCOPY)
206 virtual ~FileManagerPrivateCancelCopyFunction() {}
208 // AsyncExtensionFunction overrides.
209 virtual bool RunAsync() override;
212 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
214 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
215 : public ChromeAsyncExtensionFunction {
217 DECLARE_EXTENSION_FUNCTION(
218 "fileManagerPrivateInternal.resolveIsolatedEntries",
219 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
222 virtual ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() {}
224 // AsyncExtensionFunction overrides.
225 virtual bool RunAsync() override;
228 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
229 file_manager::util::EntryDefinitionList> entry_definition_list);
232 } // namespace extensions
234 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_