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"
14 #include "chrome/browser/extensions/chrome_extension_function.h"
15 #include "chrome/browser/extensions/chrome_extension_function_details.h"
16 #include "storage/browser/fileapi/file_system_url.h"
25 class FileSystemContext
;
27 } // namespace storage
29 namespace file_manager
{
31 struct EntryDefinition
;
32 typedef std::vector
<EntryDefinition
> EntryDefinitionList
;
34 } // namespace file_manager
38 class FileStreamMd5Digester
;
40 struct HashAndFilePath
;
43 namespace extensions
{
45 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
46 class FileManagerPrivateRequestFileSystemFunction
47 : public LoggedAsyncExtensionFunction
{
49 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
50 FILEMANAGERPRIVATE_REQUESTFILESYSTEM
)
53 ~FileManagerPrivateRequestFileSystemFunction() override
{}
55 // AsyncExtensionFunction overrides.
56 bool RunAsync() override
;
59 void RespondSuccessOnUIThread(const std::string
& name
,
60 const GURL
& root_url
);
61 void RespondFailedOnUIThread(base::File::Error error_code
);
63 // Called when something goes wrong. Records the error to |error_| per the
64 // error code and reports that the private API function failed.
65 void DidFail(base::File::Error error_code
);
67 // Sets up file system access permissions to the extension identified by
69 bool SetupFileSystemAccessPermissions(
70 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
73 scoped_refptr
<const extensions::Extension
> extension
);
75 // Called when the entry definition is computed.
76 void OnEntryDefinition(
77 const file_manager::util::EntryDefinition
& entry_definition
);
80 // Base class for FileManagerPrivateAddFileWatchFunction and
81 // FileManagerPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
82 // the class and its sub classes are used only for watching changes in
84 class FileWatchFunctionBase
: public LoggedAsyncExtensionFunction
{
86 // Calls SendResponse() with |success| converted to base::Value.
87 void Respond(bool success
);
90 ~FileWatchFunctionBase() override
{}
92 // Performs a file watch operation (ex. adds or removes a file watch).
93 virtual void PerformFileWatchOperation(
94 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
95 const storage::FileSystemURL
& file_system_url
,
96 const std::string
& extension_id
) = 0;
98 // AsyncExtensionFunction overrides.
99 bool RunAsync() override
;
102 // Implements the chrome.fileManagerPrivate.addFileWatch method.
103 // Starts watching changes in directories.
104 class FileManagerPrivateAddFileWatchFunction
: public FileWatchFunctionBase
{
106 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
107 FILEMANAGERPRIVATE_ADDFILEWATCH
)
110 ~FileManagerPrivateAddFileWatchFunction() override
{}
112 // FileWatchFunctionBase override.
113 void PerformFileWatchOperation(
114 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
115 const storage::FileSystemURL
& file_system_url
,
116 const std::string
& extension_id
) override
;
120 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
121 // Stops watching changes in directories.
122 class FileManagerPrivateRemoveFileWatchFunction
: public FileWatchFunctionBase
{
124 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
125 FILEMANAGERPRIVATE_REMOVEFILEWATCH
)
128 ~FileManagerPrivateRemoveFileWatchFunction() override
{}
130 // FileWatchFunctionBase override.
131 void PerformFileWatchOperation(
132 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
133 const storage::FileSystemURL
& file_system_url
,
134 const std::string
& extension_id
) override
;
137 // Implements the chrome.fileManagerPrivate.getSizeStats method.
138 class FileManagerPrivateGetSizeStatsFunction
139 : public LoggedAsyncExtensionFunction
{
141 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
142 FILEMANAGERPRIVATE_GETSIZESTATS
)
145 ~FileManagerPrivateGetSizeStatsFunction() override
{}
147 // AsyncExtensionFunction overrides.
148 bool RunAsync() override
;
151 void GetDriveAvailableSpaceCallback(drive::FileError error
,
155 void GetSizeStatsCallback(const uint64
* total_size
,
156 const uint64
* remaining_size
);
159 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
160 class FileManagerPrivateValidatePathNameLengthFunction
161 : public LoggedAsyncExtensionFunction
{
163 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
164 FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH
)
167 ~FileManagerPrivateValidatePathNameLengthFunction() override
{}
169 void OnFilePathLimitRetrieved(size_t current_length
, size_t max_length
);
171 // AsyncExtensionFunction overrides.
172 bool RunAsync() override
;
175 // Implements the chrome.fileManagerPrivate.formatVolume method.
176 // Formats Volume given its mount path.
177 class FileManagerPrivateFormatVolumeFunction
178 : public LoggedAsyncExtensionFunction
{
180 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
181 FILEMANAGERPRIVATE_FORMATVOLUME
)
184 ~FileManagerPrivateFormatVolumeFunction() override
{}
186 // AsyncExtensionFunction overrides.
187 bool RunAsync() override
;
190 // Implements the chrome.fileManagerPrivate.startCopy method.
191 class FileManagerPrivateStartCopyFunction
192 : public LoggedAsyncExtensionFunction
{
194 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
195 FILEMANAGERPRIVATE_STARTCOPY
)
198 ~FileManagerPrivateStartCopyFunction() override
{}
200 // AsyncExtensionFunction overrides.
201 bool RunAsync() override
;
204 void RunAfterGetFileMetadata(base::File::Error result
,
205 const base::File::Info
& file_info
);
207 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
209 void RunAfterFreeDiskSpace(bool available
);
211 // Part of RunAsync(). Called after Copy() is started on IO thread.
212 void RunAfterStartCopy(int operation_id
);
214 storage::FileSystemURL source_url_
;
215 storage::FileSystemURL destination_url_
;
218 // Implements the chrome.fileManagerPrivate.cancelCopy method.
219 class FileManagerPrivateCancelCopyFunction
220 : public LoggedAsyncExtensionFunction
{
222 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
223 FILEMANAGERPRIVATE_CANCELCOPY
)
226 ~FileManagerPrivateCancelCopyFunction() override
{}
228 // AsyncExtensionFunction overrides.
229 bool RunAsync() override
;
232 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
234 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
235 : public ChromeAsyncExtensionFunction
{
237 DECLARE_EXTENSION_FUNCTION(
238 "fileManagerPrivateInternal.resolveIsolatedEntries",
239 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES
)
242 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override
{}
244 // AsyncExtensionFunction overrides.
245 bool RunAsync() override
;
248 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr
<
249 file_manager::util::EntryDefinitionList
> entry_definition_list
);
252 class FileManagerPrivateComputeChecksumFunction
253 : public LoggedAsyncExtensionFunction
{
255 FileManagerPrivateComputeChecksumFunction();
257 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.computeChecksum",
258 FILEMANAGERPRIVATE_COMPUTECHECKSUM
)
261 ~FileManagerPrivateComputeChecksumFunction() override
;
263 // AsyncExtensionFunction overrides.
264 bool RunAsync() override
;
267 scoped_ptr
<drive::util::FileStreamMd5Digester
> digester_
;
269 void Respond(const std::string
& hash
);
272 // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
273 class FileManagerPrivateSearchFilesByHashesFunction
274 : public LoggedAsyncExtensionFunction
{
276 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
277 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES
)
280 ~FileManagerPrivateSearchFilesByHashesFunction() override
{}
283 // AsyncExtensionFunction overrides.
284 bool RunAsync() override
;
286 // Sends a response with |results| to the extension.
287 void OnSearchByHashes(const std::set
<std::string
>& hashes
,
288 drive::FileError error
,
289 const std::vector
<drive::HashAndFilePath
>& results
);
292 // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
293 class FileManagerPrivateIsUMAEnabledFunction
294 : public UIThreadExtensionFunction
{
296 FileManagerPrivateIsUMAEnabledFunction() {}
297 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
298 FILEMANAGERPRIVATE_ISUMAENABLED
)
300 ~FileManagerPrivateIsUMAEnabledFunction() override
{}
303 ExtensionFunction::ResponseAction
Run() override
;
304 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction
);
307 // Implements the chrome.fileManagerPrivate.setEntryTag method.
308 class FileManagerPrivateSetEntryTagFunction
: public UIThreadExtensionFunction
{
310 FileManagerPrivateSetEntryTagFunction();
311 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.setEntryTag",
312 FILEMANAGERPRIVATE_SETENTRYTAG
)
314 ~FileManagerPrivateSetEntryTagFunction() override
{}
317 const ChromeExtensionFunctionDetails chrome_details_
;
319 // Called when setting a tag is completed with either a success or an error.
320 void OnSetEntryPropertyCompleted(drive::FileError result
);
322 ExtensionFunction::ResponseAction
Run() override
;
323 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateSetEntryTagFunction
);
326 } // namespace extensions
328 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_