Grant permissions to other profile files on demand.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
blob1d28cde84e45c5a0e7933bd410b624da16733463
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 "extensions/browser/extension_function.h"
17 #include "storage/browser/fileapi/file_system_url.h"
19 class GURL;
21 namespace base {
22 class FilePath;
23 } // namespace base
25 namespace storage {
26 class FileSystemContext;
27 class FileSystemURL;
28 } // namespace storage
30 namespace file_manager {
31 namespace util {
32 struct EntryDefinition;
33 typedef std::vector<EntryDefinition> EntryDefinitionList;
34 } // namespace util
35 } // namespace file_manager
37 namespace drive {
38 namespace util {
39 class FileStreamMd5Digester;
40 } // namespace util
41 struct HashAndFilePath;
42 } // namespace drive
44 namespace extensions {
46 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
47 class FileManagerPrivateRequestFileSystemFunction
48 : public LoggedAsyncExtensionFunction {
49 public:
50 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
51 FILEMANAGERPRIVATE_REQUESTFILESYSTEM)
53 protected:
54 ~FileManagerPrivateRequestFileSystemFunction() override {}
56 // AsyncExtensionFunction overrides.
57 bool RunAsync() override;
59 private:
60 void RespondSuccessOnUIThread(const std::string& name,
61 const GURL& root_url);
62 void RespondFailedOnUIThread(base::File::Error error_code);
64 // Called when something goes wrong. Records the error to |error_| per the
65 // error code and reports that the private API function failed.
66 void DidFail(base::File::Error error_code);
68 // Sets up file system access permissions to the extension identified by
69 // |child_id|.
70 bool SetupFileSystemAccessPermissions(
71 scoped_refptr<storage::FileSystemContext> file_system_context,
72 int child_id,
73 Profile* profile,
74 scoped_refptr<const extensions::Extension> extension);
76 // Called when the entry definition is computed.
77 void OnEntryDefinition(
78 const file_manager::util::EntryDefinition& entry_definition);
81 // Grants R/W permissions to profile-specific directories (Drive, Downloads)
82 // from other profiles.
83 class FileManagerPrivateGrantAccessFunction : public UIThreadExtensionFunction {
84 public:
85 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.grantAccess",
86 FILEMANAGERPRIVATE_GRANTACCESS)
88 protected:
89 ~FileManagerPrivateGrantAccessFunction() override {}
91 private:
92 ExtensionFunction::ResponseAction Run() override;
95 // Base class for FileManagerPrivateAddFileWatchFunction and
96 // FileManagerPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
97 // the class and its sub classes are used only for watching changes in
98 // directories.
99 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
100 public:
101 // Calls SendResponse() with |success| converted to base::Value.
102 void Respond(bool success);
104 protected:
105 ~FileWatchFunctionBase() override {}
107 // Performs a file watch operation (ex. adds or removes a file watch).
108 virtual void PerformFileWatchOperation(
109 scoped_refptr<storage::FileSystemContext> file_system_context,
110 const storage::FileSystemURL& file_system_url,
111 const std::string& extension_id) = 0;
113 // AsyncExtensionFunction overrides.
114 bool RunAsync() override;
117 // Implements the chrome.fileManagerPrivate.addFileWatch method.
118 // Starts watching changes in directories.
119 class FileManagerPrivateAddFileWatchFunction : public FileWatchFunctionBase {
120 public:
121 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
122 FILEMANAGERPRIVATE_ADDFILEWATCH)
124 protected:
125 ~FileManagerPrivateAddFileWatchFunction() override {}
127 // FileWatchFunctionBase override.
128 void PerformFileWatchOperation(
129 scoped_refptr<storage::FileSystemContext> file_system_context,
130 const storage::FileSystemURL& file_system_url,
131 const std::string& extension_id) override;
135 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
136 // Stops watching changes in directories.
137 class FileManagerPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
138 public:
139 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
140 FILEMANAGERPRIVATE_REMOVEFILEWATCH)
142 protected:
143 ~FileManagerPrivateRemoveFileWatchFunction() override {}
145 // FileWatchFunctionBase override.
146 void PerformFileWatchOperation(
147 scoped_refptr<storage::FileSystemContext> file_system_context,
148 const storage::FileSystemURL& file_system_url,
149 const std::string& extension_id) override;
152 // Implements the chrome.fileManagerPrivate.getSizeStats method.
153 class FileManagerPrivateGetSizeStatsFunction
154 : public LoggedAsyncExtensionFunction {
155 public:
156 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
157 FILEMANAGERPRIVATE_GETSIZESTATS)
159 protected:
160 ~FileManagerPrivateGetSizeStatsFunction() override {}
162 // AsyncExtensionFunction overrides.
163 bool RunAsync() override;
165 private:
166 void GetDriveAvailableSpaceCallback(drive::FileError error,
167 int64 bytes_total,
168 int64 bytes_used);
170 void GetSizeStatsCallback(const uint64* total_size,
171 const uint64* remaining_size);
174 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
175 class FileManagerPrivateValidatePathNameLengthFunction
176 : public LoggedAsyncExtensionFunction {
177 public:
178 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
179 FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH)
181 protected:
182 ~FileManagerPrivateValidatePathNameLengthFunction() override {}
184 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
186 // AsyncExtensionFunction overrides.
187 bool RunAsync() override;
190 // Implements the chrome.fileManagerPrivate.formatVolume method.
191 // Formats Volume given its mount path.
192 class FileManagerPrivateFormatVolumeFunction
193 : public LoggedAsyncExtensionFunction {
194 public:
195 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
196 FILEMANAGERPRIVATE_FORMATVOLUME)
198 protected:
199 ~FileManagerPrivateFormatVolumeFunction() override {}
201 // AsyncExtensionFunction overrides.
202 bool RunAsync() override;
205 // Implements the chrome.fileManagerPrivate.startCopy method.
206 class FileManagerPrivateStartCopyFunction
207 : public LoggedAsyncExtensionFunction {
208 public:
209 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
210 FILEMANAGERPRIVATE_STARTCOPY)
212 protected:
213 ~FileManagerPrivateStartCopyFunction() override {}
215 // AsyncExtensionFunction overrides.
216 bool RunAsync() override;
218 private:
219 void RunAfterGetFileMetadata(base::File::Error result,
220 const base::File::Info& file_info);
222 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
223 // IO thread.
224 void RunAfterFreeDiskSpace(bool available);
226 // Part of RunAsync(). Called after Copy() is started on IO thread.
227 void RunAfterStartCopy(int operation_id);
229 storage::FileSystemURL source_url_;
230 storage::FileSystemURL destination_url_;
233 // Implements the chrome.fileManagerPrivate.cancelCopy method.
234 class FileManagerPrivateCancelCopyFunction
235 : public LoggedAsyncExtensionFunction {
236 public:
237 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
238 FILEMANAGERPRIVATE_CANCELCOPY)
240 protected:
241 ~FileManagerPrivateCancelCopyFunction() override {}
243 // AsyncExtensionFunction overrides.
244 bool RunAsync() override;
247 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
248 // method.
249 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
250 : public ChromeAsyncExtensionFunction {
251 public:
252 DECLARE_EXTENSION_FUNCTION(
253 "fileManagerPrivateInternal.resolveIsolatedEntries",
254 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
256 protected:
257 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override {}
259 // AsyncExtensionFunction overrides.
260 bool RunAsync() override;
262 private:
263 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
264 file_manager::util::EntryDefinitionList> entry_definition_list);
267 class FileManagerPrivateComputeChecksumFunction
268 : public LoggedAsyncExtensionFunction {
269 public:
270 FileManagerPrivateComputeChecksumFunction();
272 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.computeChecksum",
273 FILEMANAGERPRIVATE_COMPUTECHECKSUM)
275 protected:
276 ~FileManagerPrivateComputeChecksumFunction() override;
278 // AsyncExtensionFunction overrides.
279 bool RunAsync() override;
281 private:
282 scoped_ptr<drive::util::FileStreamMd5Digester> digester_;
284 void Respond(const std::string& hash);
287 // Implements the chrome.fileManagerPrivate.searchFilesByHashes method.
288 class FileManagerPrivateSearchFilesByHashesFunction
289 : public LoggedAsyncExtensionFunction {
290 public:
291 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
292 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
294 protected:
295 ~FileManagerPrivateSearchFilesByHashesFunction() override {}
297 private:
298 // AsyncExtensionFunction overrides.
299 bool RunAsync() override;
301 // Sends a response with |results| to the extension.
302 void OnSearchByHashes(const std::set<std::string>& hashes,
303 drive::FileError error,
304 const std::vector<drive::HashAndFilePath>& results);
307 // Implements the chrome.fileManagerPrivate.isUMAEnabled method.
308 class FileManagerPrivateIsUMAEnabledFunction
309 : public UIThreadExtensionFunction {
310 public:
311 FileManagerPrivateIsUMAEnabledFunction() {}
312 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
313 FILEMANAGERPRIVATE_ISUMAENABLED)
314 protected:
315 ~FileManagerPrivateIsUMAEnabledFunction() override {}
317 private:
318 ExtensionFunction::ResponseAction Run() override;
319 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction);
322 // Implements the chrome.fileManagerPrivate.setEntryTag method.
323 class FileManagerPrivateSetEntryTagFunction : public UIThreadExtensionFunction {
324 public:
325 FileManagerPrivateSetEntryTagFunction();
326 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.setEntryTag",
327 FILEMANAGERPRIVATE_SETENTRYTAG)
328 protected:
329 ~FileManagerPrivateSetEntryTagFunction() override {}
331 private:
332 const ChromeExtensionFunctionDetails chrome_details_;
334 // Called when setting a tag is completed with either a success or an error.
335 void OnSetEntryPropertyCompleted(drive::FileError result);
337 ExtensionFunction::ResponseAction Run() override;
338 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateSetEntryTagFunction);
341 } // namespace extensions
343 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_