Upstream version 5.34.104.0
[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 "base/platform_file.h"
13 #include "chrome/browser/chromeos/drive/file_errors.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
15
16 class GURL;
17
18 namespace base {
19 class FilePath;
20 }
21
22 namespace fileapi {
23 class FileSystemContext;
24 }
25
26 namespace extensions {
27
28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method.
29 class FileBrowserPrivateRequestFileSystemFunction
30     : public LoggedAsyncExtensionFunction {
31  public:
32   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem",
33                              FILEBROWSERPRIVATE_REQUESTFILESYSTEM)
34
35  protected:
36   virtual ~FileBrowserPrivateRequestFileSystemFunction() {}
37
38   // AsyncExtensionFunction overrides.
39   virtual bool RunImpl() OVERRIDE;
40
41  private:
42   void RespondSuccessOnUIThread(const std::string& name,
43                                 const GURL& root_url);
44   void RespondFailedOnUIThread(base::File::Error error_code);
45
46   // Called when something goes wrong. Records the error to |error_| per the
47   // error code and reports that the private API function failed.
48   void DidFail(base::File::Error error_code);
49
50   // Sets up file system access permissions to the extension identified by
51   // |child_id|.
52   bool SetupFileSystemAccessPermissions(
53       scoped_refptr<fileapi::FileSystemContext> file_system_context,
54       int child_id,
55       Profile* profile,
56       scoped_refptr<const extensions::Extension> extension);
57 };
58
59 // Base class for FileBrowserPrivateAddFileWatchFunction and
60 // FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch",
61 // the class and its sub classes are used only for watching changes in
62 // directories.
63 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
64  protected:
65   virtual ~FileWatchFunctionBase() {}
66
67   // Performs a file watch operation (ex. adds or removes a file watch).
68   virtual void PerformFileWatchOperation(
69       const base::FilePath& local_path,
70       const base::FilePath& virtual_path,
71       const std::string& extension_id) = 0;
72
73   // AsyncExtensionFunction overrides.
74   virtual bool RunImpl() OVERRIDE;
75
76   // Calls SendResponse() with |success| converted to base::Value.
77   void Respond(bool success);
78 };
79
80 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
81 // Starts watching changes in directories.
82 class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase {
83  public:
84   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
85                              FILEBROWSERPRIVATE_ADDFILEWATCH)
86
87  protected:
88   virtual ~FileBrowserPrivateAddFileWatchFunction() {}
89
90   // FileWatchFunctionBase override.
91   virtual void PerformFileWatchOperation(
92       const base::FilePath& local_path,
93       const base::FilePath& virtual_path,
94       const std::string& extension_id) OVERRIDE;
95 };
96
97
98 // Implements the chrome.fileBrowserPrivate.removeFileWatch method.
99 // Stops watching changes in directories.
100 class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase {
101  public:
102   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
103                              FILEBROWSERPRIVATE_REMOVEFILEWATCH)
104
105  protected:
106   virtual ~FileBrowserPrivateRemoveFileWatchFunction() {}
107
108   // FileWatchFunctionBase override.
109   virtual void PerformFileWatchOperation(
110       const base::FilePath& local_path,
111       const base::FilePath& virtual_path,
112       const std::string& extension_id) OVERRIDE;
113 };
114
115 // Implements the chrome.fileBrowserPrivate.getSizeStats method.
116 class FileBrowserPrivateGetSizeStatsFunction
117     : public LoggedAsyncExtensionFunction {
118  public:
119   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
120                              FILEBROWSERPRIVATE_GETSIZESTATS)
121
122  protected:
123   virtual ~FileBrowserPrivateGetSizeStatsFunction() {}
124
125   // AsyncExtensionFunction overrides.
126   virtual bool RunImpl() OVERRIDE;
127
128  private:
129   void GetDriveAvailableSpaceCallback(drive::FileError error,
130                                       int64 bytes_total,
131                                       int64 bytes_used);
132
133   void GetSizeStatsCallback(const uint64* total_size,
134                             const uint64* remaining_size);
135 };
136
137 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
138 class FileBrowserPrivateValidatePathNameLengthFunction
139     : public LoggedAsyncExtensionFunction {
140  public:
141   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
142                              FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH)
143
144  protected:
145   virtual ~FileBrowserPrivateValidatePathNameLengthFunction() {}
146
147   void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
148
149   // AsyncExtensionFunction overrides.
150   virtual bool RunImpl() OVERRIDE;
151 };
152
153 // Implements the chrome.fileBrowserPrivate.formatVolume method.
154 // Formats Volume given its mount path.
155 class FileBrowserPrivateFormatVolumeFunction
156     : public LoggedAsyncExtensionFunction {
157  public:
158   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatVolume",
159                              FILEBROWSERPRIVATE_FORMATVOLUME)
160
161  protected:
162   virtual ~FileBrowserPrivateFormatVolumeFunction() {}
163
164   // AsyncExtensionFunction overrides.
165   virtual bool RunImpl() OVERRIDE;
166 };
167
168 // Implements the chrome.fileBrowserPrivate.startCopy method.
169 class FileBrowserPrivateStartCopyFunction
170     : public LoggedAsyncExtensionFunction {
171  public:
172   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.startCopy",
173                              FILEBROWSERPRIVATE_STARTCOPY)
174
175  protected:
176   virtual ~FileBrowserPrivateStartCopyFunction() {}
177
178   // AsyncExtensionFunction overrides.
179   virtual bool RunImpl() OVERRIDE;
180
181  private:
182   // Part of RunImpl(). Called after Copy() is started on IO thread.
183   void RunAfterStartCopy(int operation_id);
184 };
185
186 // Implements the chrome.fileBrowserPrivate.cancelCopy method.
187 class FileBrowserPrivateCancelCopyFunction
188     : public LoggedAsyncExtensionFunction {
189  public:
190   DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelCopy",
191                              FILEBROWSERPRIVATE_CANCELCOPY)
192
193  protected:
194   virtual ~FileBrowserPrivateCancelCopyFunction() {}
195
196   // AsyncExtensionFunction overrides.
197   virtual bool RunImpl() OVERRIDE;
198 };
199
200 }  // namespace extensions
201
202 #endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_