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 "base/platform_file.h"
13 #include "chrome/browser/chromeos/drive/file_errors.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
23 class FileSystemContext
;
26 namespace file_manager
{
28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method.
29 class RequestFileSystemFunction
: public LoggedAsyncExtensionFunction
{
31 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem",
32 FILEBROWSERPRIVATE_REQUESTFILESYSTEM
)
34 RequestFileSystemFunction();
37 virtual ~RequestFileSystemFunction();
39 // AsyncExtensionFunction overrides.
40 virtual bool RunImpl() OVERRIDE
;
43 void RespondSuccessOnUIThread(const std::string
& name
,
44 const GURL
& root_path
);
45 void RespondFailedOnUIThread(base::PlatformFileError error_code
);
47 // Called when FileSystemContext::OpenFileSystem() is done.
48 void DidOpenFileSystem(
49 scoped_refptr
<fileapi::FileSystemContext
> file_system_context
,
50 base::PlatformFileError result
,
51 const std::string
& name
,
52 const GURL
& root_path
);
54 // Called when something goes wrong. Records the error to |error_| per the
55 // error code and reports that the private API function failed.
56 void DidFail(base::PlatformFileError error_code
);
58 // Sets up file system access permissions to the extension identified by
60 bool SetupFileSystemAccessPermissions(
61 scoped_refptr
<fileapi::FileSystemContext
> file_system_context
,
63 scoped_refptr
<const extensions::Extension
> extension
);
66 // Base class for AddFileWatchFunction and RemoveFileWatchFunction. Although
67 // it's called "FileWatch", the class and its sub classes are used only for
68 // watching changes in directories.
69 class FileWatchFunctionBase
: public LoggedAsyncExtensionFunction
{
71 FileWatchFunctionBase();
74 virtual ~FileWatchFunctionBase();
76 // Performs a file watch operation (ex. adds or removes a file watch).
77 virtual void PerformFileWatchOperation(
78 const base::FilePath
& local_path
,
79 const base::FilePath
& virtual_path
,
80 const std::string
& extension_id
) = 0;
82 // AsyncExtensionFunction overrides.
83 virtual bool RunImpl() OVERRIDE
;
85 // Calls SendResponse() with |success| converted to base::Value.
86 void Respond(bool success
);
89 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
90 // Starts watching changes in directories.
91 class AddFileWatchFunction
: public FileWatchFunctionBase
{
93 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
94 FILEBROWSERPRIVATE_ADDFILEWATCH
)
96 AddFileWatchFunction();
99 virtual ~AddFileWatchFunction();
101 // FileWatchFunctionBase override.
102 virtual void PerformFileWatchOperation(
103 const base::FilePath
& local_path
,
104 const base::FilePath
& virtual_path
,
105 const std::string
& extension_id
) OVERRIDE
;
109 // Implements the chrome.fileBrowserPrivate.removeFileWatch method.
110 // Stops watching changes in directories.
111 class RemoveFileWatchFunction
: public FileWatchFunctionBase
{
113 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
114 FILEBROWSERPRIVATE_REMOVEFILEWATCH
)
116 RemoveFileWatchFunction();
119 virtual ~RemoveFileWatchFunction();
121 // FileWatchFunctionBase override.
122 virtual void PerformFileWatchOperation(
123 const base::FilePath
& local_path
,
124 const base::FilePath
& virtual_path
,
125 const std::string
& extension_id
) OVERRIDE
;
128 // Implements the chrome.fileBrowserPrivate.setLastModified method.
129 // Sets last modified date in seconds of local file
130 class SetLastModifiedFunction
: public LoggedAsyncExtensionFunction
{
132 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified",
133 FILEBROWSERPRIVATE_SETLASTMODIFIED
)
135 SetLastModifiedFunction();
138 virtual ~SetLastModifiedFunction();
140 // AsyncExtensionFunction overrides.
141 virtual bool RunImpl() OVERRIDE
;
144 // Implements the chrome.fileBrowserPrivate.getSizeStats method.
145 class GetSizeStatsFunction
: public LoggedAsyncExtensionFunction
{
147 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
148 FILEBROWSERPRIVATE_GETSIZESTATS
)
150 GetSizeStatsFunction();
153 virtual ~GetSizeStatsFunction();
155 // AsyncExtensionFunction overrides.
156 virtual bool RunImpl() OVERRIDE
;
159 void GetDriveAvailableSpaceCallback(drive::FileError error
,
163 void GetSizeStatsCallback(const uint64
* total_size
,
164 const uint64
* remaining_size
);
167 // Implements the chrome.fileBrowserPrivate.getVolumeMetadata method.
168 // Retrieves devices meta-data. Expects volume's device path as an argument.
169 class GetVolumeMetadataFunction
: public LoggedAsyncExtensionFunction
{
171 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata",
172 FILEBROWSERPRIVATE_GETVOLUMEMETADATA
)
174 GetVolumeMetadataFunction();
177 virtual ~GetVolumeMetadataFunction();
179 // AsyncExtensionFunction overrides.
180 virtual bool RunImpl() OVERRIDE
;
183 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
184 class ValidatePathNameLengthFunction
: public LoggedAsyncExtensionFunction
{
186 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
187 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH
)
189 ValidatePathNameLengthFunction();
192 virtual ~ValidatePathNameLengthFunction();
194 void OnFilePathLimitRetrieved(size_t current_length
, size_t max_length
);
196 // AsyncExtensionFunction overrides.
197 virtual bool RunImpl() OVERRIDE
;
200 // Implements the chrome.fileBrowserPrivate.formatDevice method.
201 // Formats Device given its mount path.
202 class FormatDeviceFunction
: public LoggedAsyncExtensionFunction
{
204 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice",
205 FILEBROWSERPRIVATE_FORMATDEVICE
)
207 FormatDeviceFunction();
210 virtual ~FormatDeviceFunction();
212 // AsyncExtensionFunction overrides.
213 virtual bool RunImpl() OVERRIDE
;
216 } // namespace file_manager
218 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_