file_manager: Move FindPreferredIcon() to drive_app_registry.h
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.h
blobd4e4f13e4e75e6158dfae79c0b4c64d72969b716
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 "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"
16 class GURL;
18 namespace base {
19 class FilePath;
22 namespace fileapi {
23 class FileSystemContext;
26 namespace file_manager {
28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method.
29 class RequestFileSystemFunction : public LoggedAsyncExtensionFunction {
30 public:
31 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem",
32 FILEBROWSERPRIVATE_REQUESTFILESYSTEM)
34 RequestFileSystemFunction();
36 protected:
37 virtual ~RequestFileSystemFunction();
39 // AsyncExtensionFunction overrides.
40 virtual bool RunImpl() OVERRIDE;
42 private:
43 void RespondSuccessOnUIThread(const std::string& name,
44 const GURL& root_path);
45 void RespondFailedOnUIThread(base::PlatformFileError error_code);
47 // Called when FileSystemContext::OpenFileSystem() is done.
48 void DidOpenFileSystem(
49 scoped_refptr<fileapi::FileSystemContext> file_system_context,
50 base::PlatformFileError result,
51 const std::string& name,
52 const GURL& root_path);
54 // Called when something goes wrong. Records the error to |error_| per the
55 // error code and reports that the private API function failed.
56 void DidFail(base::PlatformFileError error_code);
58 // Sets up file system access permissions to the extension identified by
59 // |child_id|.
60 bool SetupFileSystemAccessPermissions(
61 scoped_refptr<fileapi::FileSystemContext> file_system_context,
62 int child_id,
63 scoped_refptr<const extensions::Extension> extension);
66 // Base class for AddFileWatchFunction and RemoveFileWatchFunction. Although
67 // it's called "FileWatch", the class and its sub classes are used only for
68 // watching changes in directories.
69 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
70 public:
71 FileWatchFunctionBase();
73 protected:
74 virtual ~FileWatchFunctionBase();
76 // Performs a file watch operation (ex. adds or removes a file watch).
77 virtual void PerformFileWatchOperation(
78 const base::FilePath& local_path,
79 const base::FilePath& virtual_path,
80 const std::string& extension_id) = 0;
82 // AsyncExtensionFunction overrides.
83 virtual bool RunImpl() OVERRIDE;
85 // Calls SendResponse() with |success| converted to base::Value.
86 void Respond(bool success);
89 // Implements the chrome.fileBrowserPrivate.addFileWatch method.
90 // Starts watching changes in directories.
91 class AddFileWatchFunction : public FileWatchFunctionBase {
92 public:
93 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
94 FILEBROWSERPRIVATE_ADDFILEWATCH)
96 AddFileWatchFunction();
98 protected:
99 virtual ~AddFileWatchFunction();
101 // FileWatchFunctionBase override.
102 virtual void PerformFileWatchOperation(
103 const base::FilePath& local_path,
104 const base::FilePath& virtual_path,
105 const std::string& extension_id) OVERRIDE;
109 // Implements the chrome.fileBrowserPrivate.removeFileWatch method.
110 // Stops watching changes in directories.
111 class RemoveFileWatchFunction : public FileWatchFunctionBase {
112 public:
113 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
114 FILEBROWSERPRIVATE_REMOVEFILEWATCH)
116 RemoveFileWatchFunction();
118 protected:
119 virtual ~RemoveFileWatchFunction();
121 // FileWatchFunctionBase override.
122 virtual void PerformFileWatchOperation(
123 const base::FilePath& local_path,
124 const base::FilePath& virtual_path,
125 const std::string& extension_id) OVERRIDE;
128 // Implements the chrome.fileBrowserPrivate.setLastModified method.
129 // Sets last modified date in seconds of local file
130 class SetLastModifiedFunction : public LoggedAsyncExtensionFunction {
131 public:
132 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified",
133 FILEBROWSERPRIVATE_SETLASTMODIFIED)
135 SetLastModifiedFunction();
137 protected:
138 virtual ~SetLastModifiedFunction();
140 // AsyncExtensionFunction overrides.
141 virtual bool RunImpl() OVERRIDE;
144 // Implements the chrome.fileBrowserPrivate.getSizeStats method.
145 class GetSizeStatsFunction : public LoggedAsyncExtensionFunction {
146 public:
147 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
148 FILEBROWSERPRIVATE_GETSIZESTATS)
150 GetSizeStatsFunction();
152 protected:
153 virtual ~GetSizeStatsFunction();
155 // AsyncExtensionFunction overrides.
156 virtual bool RunImpl() OVERRIDE;
158 private:
159 void GetDriveAvailableSpaceCallback(drive::FileError error,
160 int64 bytes_total,
161 int64 bytes_used);
163 void GetSizeStatsCallback(const uint64* total_size,
164 const uint64* remaining_size);
167 // Implements the chrome.fileBrowserPrivate.getVolumeMetadata method.
168 // Retrieves devices meta-data. Expects volume's device path as an argument.
169 class GetVolumeMetadataFunction : public LoggedAsyncExtensionFunction {
170 public:
171 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata",
172 FILEBROWSERPRIVATE_GETVOLUMEMETADATA)
174 GetVolumeMetadataFunction();
176 protected:
177 virtual ~GetVolumeMetadataFunction();
179 // AsyncExtensionFunction overrides.
180 virtual bool RunImpl() OVERRIDE;
183 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
184 class ValidatePathNameLengthFunction : public LoggedAsyncExtensionFunction {
185 public:
186 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
187 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH)
189 ValidatePathNameLengthFunction();
191 protected:
192 virtual ~ValidatePathNameLengthFunction();
194 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
196 // AsyncExtensionFunction overrides.
197 virtual bool RunImpl() OVERRIDE;
200 // Implements the chrome.fileBrowserPrivate.formatDevice method.
201 // Formats Device given its mount path.
202 class FormatDeviceFunction : public LoggedAsyncExtensionFunction {
203 public:
204 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice",
205 FILEBROWSERPRIVATE_FORMATDEVICE)
207 FormatDeviceFunction();
209 protected:
210 virtual ~FormatDeviceFunction();
212 // AsyncExtensionFunction overrides.
213 virtual bool RunImpl() OVERRIDE;
216 } // namespace file_manager
218 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_