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 "extensions/browser/extension_function.h"
17 #include "storage/browser/fileapi/file_system_url.h"
26 class FileSystemContext
;
28 } // namespace storage
30 namespace file_manager
{
32 struct EntryDefinition
;
33 typedef std::vector
<EntryDefinition
> EntryDefinitionList
;
35 } // namespace file_manager
39 class FileStreamMd5Digester
;
41 struct HashAndFilePath
;
44 namespace extensions
{
46 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
47 class FileManagerPrivateRequestFileSystemFunction
48 : public LoggedAsyncExtensionFunction
{
50 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
51 FILEMANAGERPRIVATE_REQUESTFILESYSTEM
)
54 ~FileManagerPrivateRequestFileSystemFunction() override
{}
56 // AsyncExtensionFunction overrides.
57 bool RunAsync() override
;
60 void RespondSuccessOnUIThread(const std::string
& name
,
61 const GURL
& root_url
);
62 void RespondFailedOnUIThread(base::File::Error error_code
);
64 // Called when something goes wrong. Records the error to |error_| per the
65 // error code and reports that the private API function failed.
66 void DidFail(base::File::Error error_code
);
68 // Sets up file system access permissions to the extension identified by
70 bool SetupFileSystemAccessPermissions(
71 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
74 scoped_refptr
<const extensions::Extension
> extension
);
76 // Called when the entry definition is computed.
77 void OnEntryDefinition(
78 const file_manager::util::EntryDefinition
& entry_definition
);
81 // Grants R/W permissions to profile-specific directories (Drive, Downloads)
82 // from other profiles.
83 class FileManagerPrivateGrantAccessFunction
: public UIThreadExtensionFunction
{
85 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.grantAccess",
86 FILEMANAGERPRIVATE_GRANTACCESS
)
89 ~FileManagerPrivateGrantAccessFunction() override
{}
92 ExtensionFunction::ResponseAction
Run() override
;
95 // Base class for FileManagerPrivateAddFileWatchFunction and
96 // FileManagerPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
97 // the class and its sub classes are used only for watching changes in
99 class FileWatchFunctionBase
: public LoggedAsyncExtensionFunction
{
101 // Calls SendResponse() with |success| converted to base::Value.
102 void Respond(bool success
);
105 ~FileWatchFunctionBase() override
{}
107 // Performs a file watch operation (ex. adds or removes a file watch).
108 virtual void PerformFileWatchOperation(
109 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
110 const storage::FileSystemURL
& file_system_url
,
111 const std::string
& extension_id
) = 0;
113 // AsyncExtensionFunction overrides.
114 bool RunAsync() override
;
117 // Implements the chrome.fileManagerPrivate.addFileWatch method.
118 // Starts watching changes in directories.
119 class FileManagerPrivateAddFileWatchFunction
: public FileWatchFunctionBase
{
121 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
122 FILEMANAGERPRIVATE_ADDFILEWATCH
)
125 ~FileManagerPrivateAddFileWatchFunction() override
{}
127 // FileWatchFunctionBase override.
128 void PerformFileWatchOperation(
129 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
130 const storage::FileSystemURL
& file_system_url
,
131 const std::string
& extension_id
) override
;
135 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
136 // Stops watching changes in directories.
137 class FileManagerPrivateRemoveFileWatchFunction
: public FileWatchFunctionBase
{
139 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
140 FILEMANAGERPRIVATE_REMOVEFILEWATCH
)
143 ~FileManagerPrivateRemoveFileWatchFunction() override
{}
145 // FileWatchFunctionBase override.
146 void PerformFileWatchOperation(
147 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
148 const storage::FileSystemURL
& file_system_url
,
149 const std::string
& extension_id
) override
;
152 // Implements the chrome.fileManagerPrivate.getSizeStats method.
153 class FileManagerPrivateGetSizeStatsFunction
154 : public LoggedAsyncExtensionFunction
{
156 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
157 FILEMANAGERPRIVATE_GETSIZESTATS
)
160 ~FileManagerPrivateGetSizeStatsFunction() override
{}
162 // AsyncExtensionFunction overrides.
163 bool RunAsync() override
;
166 void GetDriveAvailableSpaceCallback(drive::FileError error
,
170 void GetSizeStatsCallback(const uint64
* total_size
,
171 const uint64
* remaining_size
);
174 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
175 class FileManagerPrivateValidatePathNameLengthFunction
176 : public LoggedAsyncExtensionFunction
{
178 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
179 FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH
)
182 ~FileManagerPrivateValidatePathNameLengthFunction() override
{}
184 void OnFilePathLimitRetrieved(size_t current_length
, size_t max_length
);
186 // AsyncExtensionFunction overrides.
187 bool RunAsync() override
;
190 // Implements the chrome.fileManagerPrivate.formatVolume method.
191 // Formats Volume given its mount path.
192 class FileManagerPrivateFormatVolumeFunction
193 : public LoggedAsyncExtensionFunction
{
195 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
196 FILEMANAGERPRIVATE_FORMATVOLUME
)
199 ~FileManagerPrivateFormatVolumeFunction() override
{}
201 // AsyncExtensionFunction overrides.
202 bool RunAsync() override
;
205 // Implements the chrome.fileManagerPrivate.startCopy method.
206 class FileManagerPrivateStartCopyFunction
207 : public LoggedAsyncExtensionFunction
{
209 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
210 FILEMANAGERPRIVATE_STARTCOPY
)
213 ~FileManagerPrivateStartCopyFunction() override
{}
215 // AsyncExtensionFunction overrides.
216 bool RunAsync() override
;
219 void RunAfterGetFileMetadata(base::File::Error result
,
220 const base::File::Info
& file_info
);
222 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
224 void RunAfterFreeDiskSpace(bool available
);
226 // Part of RunAsync(). Called after Copy() is started on IO thread.
227 void RunAfterStartCopy(int operation_id
);
229 storage::FileSystemURL source_url_
;
230 storage::FileSystemURL destination_url_
;
233 // Implements the chrome.fileManagerPrivate.cancelCopy method.
234 class FileManagerPrivateCancelCopyFunction
235 : public LoggedAsyncExtensionFunction
{
237 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
238 FILEMANAGERPRIVATE_CANCELCOPY
)
241 ~FileManagerPrivateCancelCopyFunction() override
{}
243 // AsyncExtensionFunction overrides.
244 bool RunAsync() override
;
247 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
249 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
250 : public ChromeAsyncExtensionFunction
{
252 DECLARE_EXTENSION_FUNCTION(
253 "fileManagerPrivateInternal.resolveIsolatedEntries",
254 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES
)
257 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override
{}
259 // AsyncExtensionFunction overrides.
260 bool RunAsync() override
;
263 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr
<
264 file_manager::util::EntryDefinitionList
> entry_definition_list
);
267 class FileManagerPrivateComputeChecksumFunction
268 : public LoggedAsyncExtensionFunction
{
270 FileManagerPrivateComputeChecksumFunction();
272 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.computeChecksum",
273 FILEMANAGERPRIVATE_COMPUTECHECKSUM
)
276 ~FileManagerPrivateComputeChecksumFunction() override
;
278 // AsyncExtensionFunction overrides.
279 bool RunAsync() override
;
282 scoped_ptr
<drive::util::FileStreamMd5Digester
> digester_
;
284 void Respond(const std::string
& hash
);
287 // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
288 class FileManagerPrivateSearchFilesByHashesFunction
289 : public LoggedAsyncExtensionFunction
{
291 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
292 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES
)
295 ~FileManagerPrivateSearchFilesByHashesFunction() override
{}
298 // AsyncExtensionFunction overrides.
299 bool RunAsync() override
;
301 // Sends a response with |results| to the extension.
302 void OnSearchByHashes(const std::set
<std::string
>& hashes
,
303 drive::FileError error
,
304 const std::vector
<drive::HashAndFilePath
>& results
);
307 // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
308 class FileManagerPrivateIsUMAEnabledFunction
309 : public UIThreadExtensionFunction
{
311 FileManagerPrivateIsUMAEnabledFunction() {}
312 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
313 FILEMANAGERPRIVATE_ISUMAENABLED
)
315 ~FileManagerPrivateIsUMAEnabledFunction() override
{}
318 ExtensionFunction::ResponseAction
Run() override
;
319 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction
);
322 // Implements the chrome.fileManagerPrivate.setEntryTag method.
323 class FileManagerPrivateSetEntryTagFunction
: public UIThreadExtensionFunction
{
325 FileManagerPrivateSetEntryTagFunction();
326 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.setEntryTag",
327 FILEMANAGERPRIVATE_SETENTRYTAG
)
329 ~FileManagerPrivateSetEntryTagFunction() override
{}
332 const ChromeExtensionFunctionDetails chrome_details_
;
334 // Called when setting a tag is completed with either a success or an error.
335 void OnSetEntryPropertyCompleted(drive::FileError result
);
337 ExtensionFunction::ResponseAction
Run() override
;
338 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateSetEntryTagFunction
);
341 } // namespace extensions
343 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_