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/extensions/file_manager/private_api_base.h"
13 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/extensions/chrome_extension_function_details.h"
15 #include "components/drive/file_errors.h"
16 #include "device/media_transfer_protocol/mtp_storage_info.pb.h"
17 #include "extensions/browser/extension_function.h"
18 #include "storage/browser/fileapi/file_system_url.h"
27 class FileSystemContext
;
29 } // namespace storage
31 namespace file_manager
{
33 struct EntryDefinition
;
34 typedef std::vector
<EntryDefinition
> EntryDefinitionList
;
36 } // namespace file_manager
40 class FileStreamMd5Digester
;
42 struct HashAndFilePath
;
45 namespace extensions
{
47 // Grant permission to request externalfile scheme. The permission is needed to
48 // start drag for external file URL.
49 class FileManagerPrivateEnableExternalFileSchemeFunction
50 : public UIThreadExtensionFunction
{
52 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.enableExternalFileScheme",
53 FILEMANAGERPRIVATE_ENABLEEXTERNALFILESCHEME
);
56 ~FileManagerPrivateEnableExternalFileSchemeFunction() override
{}
59 ExtensionFunction::ResponseAction
Run() override
;
62 // Grants R/W permissions to profile-specific directories (Drive, Downloads)
63 // from other profiles.
64 class FileManagerPrivateGrantAccessFunction
: public UIThreadExtensionFunction
{
66 FileManagerPrivateGrantAccessFunction();
68 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.grantAccess",
69 FILEMANAGERPRIVATE_GRANTACCESS
)
72 ~FileManagerPrivateGrantAccessFunction() override
{}
75 ExtensionFunction::ResponseAction
Run() override
;
76 const ChromeExtensionFunctionDetails chrome_details_
;
77 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateGrantAccessFunction
);
80 // Base class for FileManagerPrivateInternalAddFileWatchFunction and
81 // FileManagerPrivateInternalRemoveFileWatchFunction. Although it's called
83 // the class and its sub classes are used only for watching changes in
85 class FileWatchFunctionBase
: public LoggedAsyncExtensionFunction
{
87 // Calls SendResponse() with |success| converted to base::Value.
88 void Respond(bool success
);
91 ~FileWatchFunctionBase() override
{}
93 // Performs a file watch operation (ex. adds or removes a file watch).
94 virtual void PerformFileWatchOperation(
95 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
96 const storage::FileSystemURL
& file_system_url
,
97 const std::string
& extension_id
) = 0;
99 // AsyncExtensionFunction overrides.
100 bool RunAsync() override
;
103 // Implements the chrome.fileManagerPrivate.addFileWatch method.
104 // Starts watching changes in directories.
105 class FileManagerPrivateInternalAddFileWatchFunction
106 : public FileWatchFunctionBase
{
108 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.addFileWatch",
109 FILEMANAGERPRIVATEINTERNAL_ADDFILEWATCH
)
112 ~FileManagerPrivateInternalAddFileWatchFunction() override
{}
114 // FileWatchFunctionBase override.
115 void PerformFileWatchOperation(
116 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
117 const storage::FileSystemURL
& file_system_url
,
118 const std::string
& extension_id
) override
;
122 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
123 // Stops watching changes in directories.
124 class FileManagerPrivateInternalRemoveFileWatchFunction
125 : public FileWatchFunctionBase
{
127 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.removeFileWatch",
128 FILEMANAGERPRIVATEINTERNAL_REMOVEFILEWATCH
)
131 ~FileManagerPrivateInternalRemoveFileWatchFunction() override
{}
133 // FileWatchFunctionBase override.
134 void PerformFileWatchOperation(
135 scoped_refptr
<storage::FileSystemContext
> file_system_context
,
136 const storage::FileSystemURL
& file_system_url
,
137 const std::string
& extension_id
) override
;
140 // Implements the chrome.fileManagerPrivate.getSizeStats method.
141 class FileManagerPrivateGetSizeStatsFunction
142 : public LoggedAsyncExtensionFunction
{
144 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
145 FILEMANAGERPRIVATE_GETSIZESTATS
)
148 ~FileManagerPrivateGetSizeStatsFunction() override
{}
150 // AsyncExtensionFunction overrides.
151 bool RunAsync() override
;
154 void OnGetLocalSpace(uint64_t* total_size
,
155 uint64_t* remaining_size
,
158 void OnGetDriveAvailableSpace(drive::FileError error
,
162 void OnGetMtpAvailableSpace(const MtpStorageInfo
& mtp_storage_info
,
165 void OnGetSizeStats(const uint64
* total_size
, const uint64
* remaining_size
);
168 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
169 class FileManagerPrivateInternalValidatePathNameLengthFunction
170 : public LoggedAsyncExtensionFunction
{
172 DECLARE_EXTENSION_FUNCTION(
173 "fileManagerPrivateInternal.validatePathNameLength",
174 FILEMANAGERPRIVATEINTERNAL_VALIDATEPATHNAMELENGTH
)
177 ~FileManagerPrivateInternalValidatePathNameLengthFunction() override
{}
179 void OnFilePathLimitRetrieved(size_t current_length
, size_t max_length
);
181 // AsyncExtensionFunction overrides.
182 bool RunAsync() override
;
185 // Implements the chrome.fileManagerPrivate.formatVolume method.
186 // Formats Volume given its mount path.
187 class FileManagerPrivateFormatVolumeFunction
188 : public LoggedAsyncExtensionFunction
{
190 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
191 FILEMANAGERPRIVATE_FORMATVOLUME
)
194 ~FileManagerPrivateFormatVolumeFunction() override
{}
196 // AsyncExtensionFunction overrides.
197 bool RunAsync() override
;
200 // Implements the chrome.fileManagerPrivate.startCopy method.
201 class FileManagerPrivateInternalStartCopyFunction
202 : public LoggedAsyncExtensionFunction
{
204 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy",
205 FILEMANAGERPRIVATEINTERNAL_STARTCOPY
)
208 ~FileManagerPrivateInternalStartCopyFunction() override
{}
210 // AsyncExtensionFunction overrides.
211 bool RunAsync() override
;
214 void RunAfterGetFileMetadata(base::File::Error result
,
215 const base::File::Info
& file_info
);
217 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
219 void RunAfterFreeDiskSpace(bool available
);
221 // Part of RunAsync(). Called after Copy() is started on IO thread.
222 void RunAfterStartCopy(int operation_id
);
224 storage::FileSystemURL source_url_
;
225 storage::FileSystemURL destination_url_
;
228 // Implements the chrome.fileManagerPrivate.cancelCopy method.
229 class FileManagerPrivateCancelCopyFunction
230 : public LoggedAsyncExtensionFunction
{
232 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
233 FILEMANAGERPRIVATE_CANCELCOPY
)
236 ~FileManagerPrivateCancelCopyFunction() override
{}
238 // AsyncExtensionFunction overrides.
239 bool RunAsync() override
;
242 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
244 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
245 : public ChromeAsyncExtensionFunction
{
247 DECLARE_EXTENSION_FUNCTION(
248 "fileManagerPrivateInternal.resolveIsolatedEntries",
249 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES
)
252 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override
{}
254 // AsyncExtensionFunction overrides.
255 bool RunAsync() override
;
258 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr
<
259 file_manager::util::EntryDefinitionList
> entry_definition_list
);
262 class FileManagerPrivateInternalComputeChecksumFunction
263 : public LoggedAsyncExtensionFunction
{
265 FileManagerPrivateInternalComputeChecksumFunction();
267 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.computeChecksum",
268 FILEMANAGERPRIVATEINTERNAL_COMPUTECHECKSUM
)
271 ~FileManagerPrivateInternalComputeChecksumFunction() override
;
273 // AsyncExtensionFunction overrides.
274 bool RunAsync() override
;
277 scoped_ptr
<drive::util::FileStreamMd5Digester
> digester_
;
279 void Respond(const std::string
& hash
);
282 // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
283 class FileManagerPrivateSearchFilesByHashesFunction
284 : public LoggedAsyncExtensionFunction
{
286 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
287 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES
)
290 ~FileManagerPrivateSearchFilesByHashesFunction() override
{}
293 // AsyncExtensionFunction overrides.
294 bool RunAsync() override
;
296 // Sends a response with |results| to the extension.
297 void OnSearchByHashes(const std::set
<std::string
>& hashes
,
298 drive::FileError error
,
299 const std::vector
<drive::HashAndFilePath
>& results
);
302 // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
303 class FileManagerPrivateIsUMAEnabledFunction
304 : public UIThreadExtensionFunction
{
306 FileManagerPrivateIsUMAEnabledFunction() {}
307 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
308 FILEMANAGERPRIVATE_ISUMAENABLED
)
310 ~FileManagerPrivateIsUMAEnabledFunction() override
{}
313 ExtensionFunction::ResponseAction
Run() override
;
314 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction
);
317 // Implements the chrome.fileManagerPrivate.setEntryTag method.
318 class FileManagerPrivateInternalSetEntryTagFunction
319 : public UIThreadExtensionFunction
{
321 FileManagerPrivateInternalSetEntryTagFunction();
322 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.setEntryTag",
323 FILEMANAGERPRIVATEINTERNAL_SETENTRYTAG
)
325 ~FileManagerPrivateInternalSetEntryTagFunction() override
{}
328 const ChromeExtensionFunctionDetails chrome_details_
;
330 // Called when setting a tag is completed with either a success or an error.
331 void OnSetEntryPropertyCompleted(drive::FileError result
);
333 ExtensionFunction::ResponseAction
Run() override
;
334 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateInternalSetEntryTagFunction
);
337 } // namespace extensions
339 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_