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 "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 GetDriveAvailableSpaceCallback(drive::FileError error
,
158 void GetMtpAvailableSpaceCallback(const MtpStorageInfo
& mtp_storage_info
,
161 void GetSizeStatsCallback(const uint64
* total_size
,
162 const uint64
* remaining_size
);
165 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
166 class FileManagerPrivateInternalValidatePathNameLengthFunction
167 : public LoggedAsyncExtensionFunction
{
169 DECLARE_EXTENSION_FUNCTION(
170 "fileManagerPrivateInternal.validatePathNameLength",
171 FILEMANAGERPRIVATEINTERNAL_VALIDATEPATHNAMELENGTH
)
174 ~FileManagerPrivateInternalValidatePathNameLengthFunction() override
{}
176 void OnFilePathLimitRetrieved(size_t current_length
, size_t max_length
);
178 // AsyncExtensionFunction overrides.
179 bool RunAsync() override
;
182 // Implements the chrome.fileManagerPrivate.formatVolume method.
183 // Formats Volume given its mount path.
184 class FileManagerPrivateFormatVolumeFunction
185 : public LoggedAsyncExtensionFunction
{
187 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
188 FILEMANAGERPRIVATE_FORMATVOLUME
)
191 ~FileManagerPrivateFormatVolumeFunction() override
{}
193 // AsyncExtensionFunction overrides.
194 bool RunAsync() override
;
197 // Implements the chrome.fileManagerPrivate.startCopy method.
198 class FileManagerPrivateInternalStartCopyFunction
199 : public LoggedAsyncExtensionFunction
{
201 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy",
202 FILEMANAGERPRIVATEINTERNAL_STARTCOPY
)
205 ~FileManagerPrivateInternalStartCopyFunction() override
{}
207 // AsyncExtensionFunction overrides.
208 bool RunAsync() override
;
211 void RunAfterGetFileMetadata(base::File::Error result
,
212 const base::File::Info
& file_info
);
214 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
216 void RunAfterFreeDiskSpace(bool available
);
218 // Part of RunAsync(). Called after Copy() is started on IO thread.
219 void RunAfterStartCopy(int operation_id
);
221 storage::FileSystemURL source_url_
;
222 storage::FileSystemURL destination_url_
;
225 // Implements the chrome.fileManagerPrivate.cancelCopy method.
226 class FileManagerPrivateCancelCopyFunction
227 : public LoggedAsyncExtensionFunction
{
229 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
230 FILEMANAGERPRIVATE_CANCELCOPY
)
233 ~FileManagerPrivateCancelCopyFunction() override
{}
235 // AsyncExtensionFunction overrides.
236 bool RunAsync() override
;
239 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
241 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
242 : public ChromeAsyncExtensionFunction
{
244 DECLARE_EXTENSION_FUNCTION(
245 "fileManagerPrivateInternal.resolveIsolatedEntries",
246 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES
)
249 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override
{}
251 // AsyncExtensionFunction overrides.
252 bool RunAsync() override
;
255 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr
<
256 file_manager::util::EntryDefinitionList
> entry_definition_list
);
259 class FileManagerPrivateInternalComputeChecksumFunction
260 : public LoggedAsyncExtensionFunction
{
262 FileManagerPrivateInternalComputeChecksumFunction();
264 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.computeChecksum",
265 FILEMANAGERPRIVATEINTERNAL_COMPUTECHECKSUM
)
268 ~FileManagerPrivateInternalComputeChecksumFunction() override
;
270 // AsyncExtensionFunction overrides.
271 bool RunAsync() override
;
274 scoped_ptr
<drive::util::FileStreamMd5Digester
> digester_
;
276 void Respond(const std::string
& hash
);
279 // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
280 class FileManagerPrivateSearchFilesByHashesFunction
281 : public LoggedAsyncExtensionFunction
{
283 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
284 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES
)
287 ~FileManagerPrivateSearchFilesByHashesFunction() override
{}
290 // AsyncExtensionFunction overrides.
291 bool RunAsync() override
;
293 // Sends a response with |results| to the extension.
294 void OnSearchByHashes(const std::set
<std::string
>& hashes
,
295 drive::FileError error
,
296 const std::vector
<drive::HashAndFilePath
>& results
);
299 // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
300 class FileManagerPrivateIsUMAEnabledFunction
301 : public UIThreadExtensionFunction
{
303 FileManagerPrivateIsUMAEnabledFunction() {}
304 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
305 FILEMANAGERPRIVATE_ISUMAENABLED
)
307 ~FileManagerPrivateIsUMAEnabledFunction() override
{}
310 ExtensionFunction::ResponseAction
Run() override
;
311 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction
);
314 // Implements the chrome.fileManagerPrivate.setEntryTag method.
315 class FileManagerPrivateInternalSetEntryTagFunction
316 : public UIThreadExtensionFunction
{
318 FileManagerPrivateInternalSetEntryTagFunction();
319 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.setEntryTag",
320 FILEMANAGERPRIVATEINTERNAL_SETENTRYTAG
)
322 ~FileManagerPrivateInternalSetEntryTagFunction() override
{}
325 const ChromeExtensionFunctionDetails chrome_details_
;
327 // Called when setting a tag is completed with either a success or an error.
328 void OnSetEntryPropertyCompleted(drive::FileError result
);
330 ExtensionFunction::ResponseAction
Run() override
;
331 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateInternalSetEntryTagFunction
);
334 } // namespace extensions
336 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_