718769df8f54337b5ee6a647cf0fc5394fc7803b
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
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.
6
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_
9
10 #include <string>
11
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
14
15 class GURL;
16
17 namespace base {
18 class FilePath;
19 }  // namespace base
20
21 namespace storage {
22 class FileSystemContext;
23 class FileSystemURL;
24 }  // namespace storage
25
26 namespace file_manager {
27 namespace util {
28 struct EntryDefinition;
29 typedef std::vector<EntryDefinition> EntryDefinitionList;
30 }  // namespace util
31 }  // namespace file_manager
32
33 namespace extensions {
34
35 // Implements the chrome.fileManagerPrivate.requestFileSystem method.
36 class FileManagerPrivateRequestFileSystemFunction
37     : public LoggedAsyncExtensionFunction {
38  public:
39   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestFileSystem",
40                              FILEMANAGERPRIVATE_REQUESTFILESYSTEM)
41
42  protected:
43   virtual ~FileManagerPrivateRequestFileSystemFunction() {}
44
45   // AsyncExtensionFunction overrides.
46   virtual bool RunAsync() override;
47
48  private:
49   void RespondSuccessOnUIThread(const std::string& name,
50                                 const GURL& root_url);
51   void RespondFailedOnUIThread(base::File::Error error_code);
52
53   // Called when something goes wrong. Records the error to |error_| per the
54   // error code and reports that the private API function failed.
55   void DidFail(base::File::Error error_code);
56
57   // Sets up file system access permissions to the extension identified by
58   // |child_id|.
59   bool SetupFileSystemAccessPermissions(
60       scoped_refptr<storage::FileSystemContext> file_system_context,
61       int child_id,
62       Profile* profile,
63       scoped_refptr<const extensions::Extension> extension);
64
65   // Called when the entry definition is computed.
66   void OnEntryDefinition(
67       const file_manager::util::EntryDefinition& entry_definition);
68 };
69
70 // Base class for FileManagerPrivateAddFileWatchFunction and
71 // FileManagerPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
72 // the class and its sub classes are used only for watching changes in
73 // directories.
74 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
75  public:
76   // Calls SendResponse() with |success| converted to base::Value.
77   void Respond(bool success);
78
79  protected:
80   virtual ~FileWatchFunctionBase() {}
81
82   // Performs a file watch operation (ex. adds or removes a file watch).
83   virtual void PerformFileWatchOperation(
84       scoped_refptr<storage::FileSystemContext> file_system_context,
85       const storage::FileSystemURL& file_system_url,
86       const std::string& extension_id) = 0;
87
88   // AsyncExtensionFunction overrides.
89   virtual bool RunAsync() override;
90 };
91
92 // Implements the chrome.fileManagerPrivate.addFileWatch method.
93 // Starts watching changes in directories.
94 class FileManagerPrivateAddFileWatchFunction : public FileWatchFunctionBase {
95  public:
96   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.addFileWatch",
97                              FILEMANAGERPRIVATE_ADDFILEWATCH)
98
99  protected:
100   virtual ~FileManagerPrivateAddFileWatchFunction() {}
101
102   // FileWatchFunctionBase override.
103   virtual void PerformFileWatchOperation(
104       scoped_refptr<storage::FileSystemContext> file_system_context,
105       const storage::FileSystemURL& file_system_url,
106       const std::string& extension_id) override;
107 };
108
109
110 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
111 // Stops watching changes in directories.
112 class FileManagerPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
113  public:
114   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.removeFileWatch",
115                              FILEMANAGERPRIVATE_REMOVEFILEWATCH)
116
117  protected:
118   virtual ~FileManagerPrivateRemoveFileWatchFunction() {}
119
120   // FileWatchFunctionBase override.
121   virtual void PerformFileWatchOperation(
122       scoped_refptr<storage::FileSystemContext> file_system_context,
123       const storage::FileSystemURL& file_system_url,
124       const std::string& extension_id) override;
125 };
126
127 // Implements the chrome.fileManagerPrivate.getSizeStats method.
128 class FileManagerPrivateGetSizeStatsFunction
129     : public LoggedAsyncExtensionFunction {
130  public:
131   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
132                              FILEMANAGERPRIVATE_GETSIZESTATS)
133
134  protected:
135   virtual ~FileManagerPrivateGetSizeStatsFunction() {}
136
137   // AsyncExtensionFunction overrides.
138   virtual bool RunAsync() override;
139
140  private:
141   void GetDriveAvailableSpaceCallback(drive::FileError error,
142                                       int64 bytes_total,
143                                       int64 bytes_used);
144
145   void GetSizeStatsCallback(const uint64* total_size,
146                             const uint64* remaining_size);
147 };
148
149 // Implements the chrome.fileManagerPrivate.validatePathNameLength method.
150 class FileManagerPrivateValidatePathNameLengthFunction
151     : public LoggedAsyncExtensionFunction {
152  public:
153   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.validatePathNameLength",
154                              FILEMANAGERPRIVATE_VALIDATEPATHNAMELENGTH)
155
156  protected:
157   virtual ~FileManagerPrivateValidatePathNameLengthFunction() {}
158
159   void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
160
161   // AsyncExtensionFunction overrides.
162   virtual bool RunAsync() override;
163 };
164
165 // Implements the chrome.fileManagerPrivate.formatVolume method.
166 // Formats Volume given its mount path.
167 class FileManagerPrivateFormatVolumeFunction
168     : public LoggedAsyncExtensionFunction {
169  public:
170   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.formatVolume",
171                              FILEMANAGERPRIVATE_FORMATVOLUME)
172
173  protected:
174   virtual ~FileManagerPrivateFormatVolumeFunction() {}
175
176   // AsyncExtensionFunction overrides.
177   virtual bool RunAsync() override;
178 };
179
180 // Implements the chrome.fileManagerPrivate.startCopy method.
181 class FileManagerPrivateStartCopyFunction
182     : public LoggedAsyncExtensionFunction {
183  public:
184   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.startCopy",
185                              FILEMANAGERPRIVATE_STARTCOPY)
186
187  protected:
188   virtual ~FileManagerPrivateStartCopyFunction() {}
189
190   // AsyncExtensionFunction overrides.
191   virtual bool RunAsync() override;
192
193  private:
194   // Part of RunAsync(). Called after Copy() is started on IO thread.
195   void RunAfterStartCopy(int operation_id);
196 };
197
198 // Implements the chrome.fileManagerPrivate.cancelCopy method.
199 class FileManagerPrivateCancelCopyFunction
200     : public LoggedAsyncExtensionFunction {
201  public:
202   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelCopy",
203                              FILEMANAGERPRIVATE_CANCELCOPY)
204
205  protected:
206   virtual ~FileManagerPrivateCancelCopyFunction() {}
207
208   // AsyncExtensionFunction overrides.
209   virtual bool RunAsync() override;
210 };
211
212 // Implements the chrome.fileManagerPrivateInternal.resolveIsolatedEntries
213 // method.
214 class FileManagerPrivateInternalResolveIsolatedEntriesFunction
215     : public ChromeAsyncExtensionFunction {
216  public:
217   DECLARE_EXTENSION_FUNCTION(
218       "fileManagerPrivateInternal.resolveIsolatedEntries",
219       FILEMANAGERPRIVATE_RESOLVEISOLATEDENTRIES)
220
221  protected:
222   virtual ~FileManagerPrivateInternalResolveIsolatedEntriesFunction() {}
223
224   // AsyncExtensionFunction overrides.
225   virtual bool RunAsync() override;
226
227  private:
228   void RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr<
229       file_manager::util::EntryDefinitionList> entry_definition_list);
230 };
231
232 }  // namespace extensions
233
234 #endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_