Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
blob14185ecbf6f5ee6e2a342e0c983b728d4819d3ae
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 "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 GetDriveAvailableSpaceCallback(drive::FileError error,
155 int64 bytes_total,
156 int64 bytes_used);
158 void GetMtpAvailableSpaceCallback(const MtpStorageInfo& mtp_storage_info,
159 const bool error);
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 {
168 public:
169 DECLARE_EXTENSION_FUNCTION(
170 "fileManagerPrivateInternal.validatePathNameLength",
171 FILEMANAGERPRIVATEINTERNAL_VALIDATEPATHNAMELENGTH)
173 protected:
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 {
186 public:
187 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
188 FILEMANAGERPRIVATE_FORMATVOLUME)
190 protected:
191 ~FileManagerPrivateFormatVolumeFunction() override {}
193 // AsyncExtensionFunction overrides.
194 bool RunAsync() override;
197 // Implements the chrome.fileManagerPrivate.startCopy method.
198 class FileManagerPrivateInternalStartCopyFunction
199 : public LoggedAsyncExtensionFunction {
200 public:
201 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.startCopy",
202 FILEMANAGERPRIVATEINTERNAL_STARTCOPY)
204 protected:
205 ~FileManagerPrivateInternalStartCopyFunction() override {}
207 // AsyncExtensionFunction overrides.
208 bool RunAsync() override;
210 private:
211 void RunAfterGetFileMetadata(base::File::Error result,
212 const base::File::Info& file_info);
214 // Part of RunAsync(). Called after FreeDiskSpaceIfNeededFor() is completed on
215 // IO thread.
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 {
228 public:
229 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
230 FILEMANAGERPRIVATE_CANCELCOPY)
232 protected:
233 ~FileManagerPrivateCancelCopyFunction() override {}
235 // AsyncExtensionFunction overrides.
236 bool RunAsync() override;
239 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
240 // method.
241 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
242 : public ChromeAsyncExtensionFunction {
243 public:
244 DECLARE_EXTENSION_FUNCTION(
245 "fileManagerPrivateInternal.resolveIsolatedEntries",
246 FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
248 protected:
249 ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() override {}
251 // AsyncExtensionFunction overrides.
252 bool RunAsync() override;
254 private:
255 void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
256 file_manager::util::EntryDefinitionList> entry_definition_list);
259 class FileManagerPrivateInternalComputeChecksumFunction
260 : public LoggedAsyncExtensionFunction {
261 public:
262 FileManagerPrivateInternalComputeChecksumFunction();
264 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.computeChecksum",
265 FILEMANAGERPRIVATEINTERNAL_COMPUTECHECKSUM)
267 protected:
268 ~FileManagerPrivateInternalComputeChecksumFunction() override;
270 // AsyncExtensionFunction overrides.
271 bool RunAsync() override;
273 private:
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 {
282 public:
283 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchFilesByHashes",
284 FILEMANAGERPRIVATE_SEARCHFILESBYHASHES)
286 protected:
287 ~FileManagerPrivateSearchFilesByHashesFunction() override {}
289 private:
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 {
302 public:
303 FileManagerPrivateIsUMAEnabledFunction() {}
304 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.isUMAEnabled",
305 FILEMANAGERPRIVATE_ISUMAENABLED)
306 protected:
307 ~FileManagerPrivateIsUMAEnabledFunction() override {}
309 private:
310 ExtensionFunction::ResponseAction Run() override;
311 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateIsUMAEnabledFunction);
314 // Implements the chrome.fileManagerPrivate.setEntryTag method.
315 class FileManagerPrivateInternalSetEntryTagFunction
316 : public UIThreadExtensionFunction {
317 public:
318 FileManagerPrivateInternalSetEntryTagFunction();
319 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.setEntryTag",
320 FILEMANAGERPRIVATEINTERNAL_SETENTRYTAG)
321 protected:
322 ~FileManagerPrivateInternalSetEntryTagFunction() override {}
324 private:
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_