Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
blob835b7f7974aae651fda5bd0d7fe4503ca1211458
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/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"
20 class GURL;
22 namespace base {
23 class FilePath;
24 } // namespace base
26 namespace storage {
27 class FileSystemContext;
28 class FileSystemURL;
29 } // namespace storage
31 namespace file_manager {
32 namespace util {
33 struct EntryDefinition;
34 typedef std::vector<EntryDefinition> EntryDefinitionList;
35 } // namespace util
36 } // namespace file_manager
38 namespace drive {
39 namespace util {
40 class FileStreamMd5Digester;
41 } // namespace util
42 struct HashAndFilePath;
43 } // namespace drive
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 {
51 public:
52 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.enableExternalFileScheme",
53 FILEMANAGERPRIVATE_ENABLEEXTERNALFILESCHEME);
55 protected:
56 ~FileManagerPrivateEnableExternalFileSchemeFunction() override {}
58 private:
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 {
65 public:
66 FileManagerPrivateGrantAccessFunction();
68 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.grantAccess",
69 FILEMANAGERPRIVATE_GRANTACCESS)
71 protected:
72 ~FileManagerPrivateGrantAccessFunction() override {}
74 private:
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
82 // "FileWatch",
83 // the class and its sub classes are used only for watching changes in
84 // directories.
85 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
86 public:
87 // Calls SendResponse() with |success| converted to base::Value.
88 void Respond(bool success);
90 protected:
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 {
107 public:
108 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.addFileWatch",
109 FILEMANAGERPRIVATEINTERNAL_ADDFILEWATCH)
111 protected:
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 {
126 public:
127 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.removeFileWatch",
128 FILEMANAGERPRIVATEINTERNAL_REMOVEFILEWATCH)
130 protected:
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 {
143 public:
144 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
145 FILEMANAGERPRIVATE_GETSIZESTATS)
147 protected:
148 ~FileManagerPrivateGetSizeStatsFunction() override {}
150 // AsyncExtensionFunction overrides.
151 bool RunAsync() override;
153 private:
154 void OnGetLocalSpace(uint64_t* total_size,
155 uint64_t* remaining_size,
156 bool is_download);
158 void OnGetDriveAvailableSpace(drive::FileError error,
159 int64 bytes_total,
160 int64 bytes_used);
162 void OnGetMtpAvailableSpace(const MtpStorageInfo& mtp_storage_info,
163 const bool error);
165 void OnGetSizeStats(const uint64* total_size, const uint64* remaining_size);
168 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
169 class FileManagerPrivateInternalValidatePathNameLengthFunction
170 : public LoggedAsyncExtensionFunction {
171 public:
172 DECLARE_EXTENSION_FUNCTION(
173 "fileManagerPrivateInternal.validatePathNameLength",
174 FILEMANAGERPRIVATEINTERNAL_VALIDATEPATHNAMELENGTH)
176 protected:
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 {
189 public:
190 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
191 FILEMANAGERPRIVATE_FORMATVOLUME)
193 protected:
194 ~FileManagerPrivateFormatVolumeFunction() override {}
196 // AsyncExtensionFunction overrides.
197 bool RunAsync() override;
200 // Implements the chrome.fileManagerPrivate.startCopy method.
201 class FileManagerPrivateInternalStartCopyFunction
202 : public LoggedAsyncExtensionFunction {
203 public:
204 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy",
205 FILEMANAGERPRIVATEINTERNAL_STARTCOPY)
207 protected:
208 ~FileManagerPrivateInternalStartCopyFunction() override {}
210 // AsyncExtensionFunction overrides.
211 bool RunAsync() override;
213 private:
214 void RunAfterGetFileMetadata(base::File::Error result,
215 const base::File::Info& file_info);
217 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
218 // IO thread.
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 {
231 public:
232 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
233 FILEMANAGERPRIVATE_CANCELCOPY)
235 protected:
236 ~FileManagerPrivateCancelCopyFunction() override {}
238 // AsyncExtensionFunction overrides.
239 bool RunAsync() override;
242 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
243 // method.
244 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
245 : public ChromeAsyncExtensionFunction {
246 public:
247 DECLARE_EXTENSION_FUNCTION(
248 "fileManagerPrivateInternal.resolveIsolatedEntries",
249 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
251 protected:
252 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override {}
254 // AsyncExtensionFunction overrides.
255 bool RunAsync() override;
257 private:
258 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
259 file_manager::util::EntryDefinitionList> entry_definition_list);
262 class FileManagerPrivateInternalComputeChecksumFunction
263 : public LoggedAsyncExtensionFunction {
264 public:
265 FileManagerPrivateInternalComputeChecksumFunction();
267 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.computeChecksum",
268 FILEMANAGERPRIVATEINTERNAL_COMPUTECHECKSUM)
270 protected:
271 ~FileManagerPrivateInternalComputeChecksumFunction() override;
273 // AsyncExtensionFunction overrides.
274 bool RunAsync() override;
276 private:
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 {
285 public:
286 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
287 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
289 protected:
290 ~FileManagerPrivateSearchFilesByHashesFunction() override {}
292 private:
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 {
305 public:
306 FileManagerPrivateIsUMAEnabledFunction() {}
307 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
308 FILEMANAGERPRIVATE_ISUMAENABLED)
309 protected:
310 ~FileManagerPrivateIsUMAEnabledFunction() override {}
312 private:
313 ExtensionFunction::ResponseAction Run() override;
314 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction);
317 // Implements the chrome.fileManagerPrivate.setEntryTag method.
318 class FileManagerPrivateInternalSetEntryTagFunction
319 : public UIThreadExtensionFunction {
320 public:
321 FileManagerPrivateInternalSetEntryTagFunction();
322 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.setEntryTag",
323 FILEMANAGERPRIVATEINTERNAL_SETENTRYTAG)
324 protected:
325 ~FileManagerPrivateInternalSetEntryTagFunction() override {}
327 private:
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_