ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
blob6d845f213acdf40a5229739127a99ef3be73cd85
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.
4 //
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_
10 #include <string>
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"
18 class GURL;
20 namespace base {
21 class FilePath;
22 } // namespace base
24 namespace storage {
25 class FileSystemContext;
26 class FileSystemURL;
27 } // namespace storage
29 namespace file_manager {
30 namespace util {
31 struct EntryDefinition;
32 typedef std::vector<EntryDefinition> EntryDefinitionList;
33 } // namespace util
34 } // namespace file_manager
36 namespace drive {
37 namespace util {
38 class FileStreamMd5Digester;
39 } // namespace util
40 struct HashAndFilePath;
41 } // namespace drive
43 namespace extensions {
45 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
46 class FileManagerPrivateRequestFileSystemFunction
47 : public LoggedAsyncExtensionFunction {
48 public:
49 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
50 FILEMANAGERPRIVATE_REQUESTFILESYSTEM)
52 protected:
53 ~FileManagerPrivateRequestFileSystemFunction() override {}
55 // AsyncExtensionFunction overrides.
56 bool RunAsync() override;
58 private:
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
68 // |child_id|.
69 bool SetupFileSystemAccessPermissions(
70 scoped_refptr<storage::FileSystemContext> file_system_context,
71 int child_id,
72 Profile* profile,
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
83 // directories.
84 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
85 public:
86 // Calls SendResponse() with |success| converted to base::Value.
87 void Respond(bool success);
89 protected:
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 {
105 public:
106 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
107 FILEMANAGERPRIVATE_ADDFILEWATCH)
109 protected:
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 {
123 public:
124 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
125 FILEMANAGERPRIVATE_REMOVEFILEWATCH)
127 protected:
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 {
140 public:
141 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
142 FILEMANAGERPRIVATE_GETSIZESTATS)
144 protected:
145 ~FileManagerPrivateGetSizeStatsFunction() override {}
147 // AsyncExtensionFunction overrides.
148 bool RunAsync() override;
150 private:
151 void GetDriveAvailableSpaceCallback(drive::FileError error,
152 int64 bytes_total,
153 int64 bytes_used);
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 {
162 public:
163 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
164 FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH)
166 protected:
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 {
179 public:
180 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
181 FILEMANAGERPRIVATE_FORMATVOLUME)
183 protected:
184 ~FileManagerPrivateFormatVolumeFunction() override {}
186 // AsyncExtensionFunction overrides.
187 bool RunAsync() override;
190 // Implements the chrome.fileManagerPrivate.startCopy method.
191 class FileManagerPrivateStartCopyFunction
192 : public LoggedAsyncExtensionFunction {
193 public:
194 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
195 FILEMANAGERPRIVATE_STARTCOPY)
197 protected:
198 ~FileManagerPrivateStartCopyFunction() override {}
200 // AsyncExtensionFunction overrides.
201 bool RunAsync() override;
203 private:
204 void RunAfterGetFileMetadata(base::File::Error result,
205 const base::File::Info& file_info);
207 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
208 // IO thread.
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 {
221 public:
222 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
223 FILEMANAGERPRIVATE_CANCELCOPY)
225 protected:
226 ~FileManagerPrivateCancelCopyFunction() override {}
228 // AsyncExtensionFunction overrides.
229 bool RunAsync() override;
232 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
233 // method.
234 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
235 : public ChromeAsyncExtensionFunction {
236 public:
237 DECLARE_EXTENSION_FUNCTION(
238 "fileManagerPrivateInternal.resolveIsolatedEntries",
239 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
241 protected:
242 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override {}
244 // AsyncExtensionFunction overrides.
245 bool RunAsync() override;
247 private:
248 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
249 file_manager::util::EntryDefinitionList> entry_definition_list);
252 class FileManagerPrivateComputeChecksumFunction
253 : public LoggedAsyncExtensionFunction {
254 public:
255 FileManagerPrivateComputeChecksumFunction();
257 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.computeChecksum",
258 FILEMANAGERPRIVATE_COMPUTECHECKSUM)
260 protected:
261 ~FileManagerPrivateComputeChecksumFunction() override;
263 // AsyncExtensionFunction overrides.
264 bool RunAsync() override;
266 private:
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 {
275 public:
276 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
277 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
279 protected:
280 ~FileManagerPrivateSearchFilesByHashesFunction() override {}
282 private:
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 {
295 public:
296 FileManagerPrivateIsUMAEnabledFunction() {}
297 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
298 FILEMANAGERPRIVATE_ISUMAENABLED)
299 protected:
300 ~FileManagerPrivateIsUMAEnabledFunction() override {}
302 private:
303 ExtensionFunction::ResponseAction Run() override;
304 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction);
307 // Implements the chrome.fileManagerPrivate.setEntryTag method.
308 class FileManagerPrivateSetEntryTagFunction : public UIThreadExtensionFunction {
309 public:
310 FileManagerPrivateSetEntryTagFunction();
311 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.setEntryTag",
312 FILEMANAGERPRIVATE_SETENTRYTAG)
313 protected:
314 ~FileManagerPrivateSetEntryTagFunction() override {}
316 private:
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_