OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file provides file system related API functions. | 5 // This file provides file system related API functions. |
6 | 6 |
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_
H_ | 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_ | 8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_
H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "chrome/browser/chromeos/drive/file_errors.h" | 13 #include "chrome/browser/chromeos/drive/file_errors.h" |
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" |
15 | 15 |
16 class GURL; | 16 class GURL; |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class FilePath; | 19 class FilePath; |
20 } | 20 } |
21 | 21 |
22 namespace fileapi { | 22 namespace fileapi { |
23 class FileSystemContext; | 23 class FileSystemContext; |
24 } | 24 } |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 | 27 |
28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method. | 28 // Implements the chrome.fileBrowserPrivate.requestFileSystem method. |
29 class RequestFileSystemFunction : public LoggedAsyncExtensionFunction { | 29 class FileBrowserPrivateRequestFileSystemFunction |
| 30 : public LoggedAsyncExtensionFunction { |
30 public: | 31 public: |
31 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem", | 32 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem", |
32 FILEBROWSERPRIVATE_REQUESTFILESYSTEM) | 33 FILEBROWSERPRIVATE_REQUESTFILESYSTEM) |
33 | 34 |
34 RequestFileSystemFunction(); | 35 FileBrowserPrivateRequestFileSystemFunction(); |
35 | 36 |
36 protected: | 37 protected: |
37 virtual ~RequestFileSystemFunction(); | 38 virtual ~FileBrowserPrivateRequestFileSystemFunction(); |
38 | 39 |
39 // AsyncExtensionFunction overrides. | 40 // AsyncExtensionFunction overrides. |
40 virtual bool RunImpl() OVERRIDE; | 41 virtual bool RunImpl() OVERRIDE; |
41 | 42 |
42 private: | 43 private: |
43 void RespondSuccessOnUIThread(const std::string& name, | 44 void RespondSuccessOnUIThread(const std::string& name, |
44 const GURL& root_path); | 45 const GURL& root_path); |
45 void RespondFailedOnUIThread(base::PlatformFileError error_code); | 46 void RespondFailedOnUIThread(base::PlatformFileError error_code); |
46 | 47 |
47 // Called when FileSystemContext::OpenFileSystem() is done. | 48 // Called when FileSystemContext::OpenFileSystem() is done. |
48 void DidOpenFileSystem( | 49 void DidOpenFileSystem( |
49 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 50 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
50 base::PlatformFileError result, | 51 base::PlatformFileError result, |
51 const std::string& name, | 52 const std::string& name, |
52 const GURL& root_path); | 53 const GURL& root_path); |
53 | 54 |
54 // Called when something goes wrong. Records the error to |error_| per the | 55 // Called when something goes wrong. Records the error to |error_| per the |
55 // error code and reports that the private API function failed. | 56 // error code and reports that the private API function failed. |
56 void DidFail(base::PlatformFileError error_code); | 57 void DidFail(base::PlatformFileError error_code); |
57 | 58 |
58 // Sets up file system access permissions to the extension identified by | 59 // Sets up file system access permissions to the extension identified by |
59 // |child_id|. | 60 // |child_id|. |
60 bool SetupFileSystemAccessPermissions( | 61 bool SetupFileSystemAccessPermissions( |
61 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 62 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
62 int child_id, | 63 int child_id, |
63 scoped_refptr<const extensions::Extension> extension); | 64 scoped_refptr<const extensions::Extension> extension); |
64 }; | 65 }; |
65 | 66 |
66 // Base class for AddFileWatchFunction and RemoveFileWatchFunction. Although | 67 // Base class for FileBrowserPrivateAddFileWatchFunction and |
67 // it's called "FileWatch", the class and its sub classes are used only for | 68 // FileBrowserPrivateRemoveFileWatchFunction. Although it's called "FileWatch", |
68 // watching changes in directories. | 69 // the class and its sub classes are used only for watching changes in |
| 70 // directories. |
69 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { | 71 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { |
70 public: | 72 public: |
71 FileWatchFunctionBase(); | 73 FileWatchFunctionBase(); |
72 | 74 |
73 protected: | 75 protected: |
74 virtual ~FileWatchFunctionBase(); | 76 virtual ~FileWatchFunctionBase(); |
75 | 77 |
76 // Performs a file watch operation (ex. adds or removes a file watch). | 78 // Performs a file watch operation (ex. adds or removes a file watch). |
77 virtual void PerformFileWatchOperation( | 79 virtual void PerformFileWatchOperation( |
78 const base::FilePath& local_path, | 80 const base::FilePath& local_path, |
79 const base::FilePath& virtual_path, | 81 const base::FilePath& virtual_path, |
80 const std::string& extension_id) = 0; | 82 const std::string& extension_id) = 0; |
81 | 83 |
82 // AsyncExtensionFunction overrides. | 84 // AsyncExtensionFunction overrides. |
83 virtual bool RunImpl() OVERRIDE; | 85 virtual bool RunImpl() OVERRIDE; |
84 | 86 |
85 // Calls SendResponse() with |success| converted to base::Value. | 87 // Calls SendResponse() with |success| converted to base::Value. |
86 void Respond(bool success); | 88 void Respond(bool success); |
87 }; | 89 }; |
88 | 90 |
89 // Implements the chrome.fileBrowserPrivate.addFileWatch method. | 91 // Implements the chrome.fileBrowserPrivate.addFileWatch method. |
90 // Starts watching changes in directories. | 92 // Starts watching changes in directories. |
91 class AddFileWatchFunction : public FileWatchFunctionBase { | 93 class FileBrowserPrivateAddFileWatchFunction : public FileWatchFunctionBase { |
92 public: | 94 public: |
93 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch", | 95 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch", |
94 FILEBROWSERPRIVATE_ADDFILEWATCH) | 96 FILEBROWSERPRIVATE_ADDFILEWATCH) |
95 | 97 |
96 AddFileWatchFunction(); | 98 FileBrowserPrivateAddFileWatchFunction(); |
97 | 99 |
98 protected: | 100 protected: |
99 virtual ~AddFileWatchFunction(); | 101 virtual ~FileBrowserPrivateAddFileWatchFunction(); |
100 | 102 |
101 // FileWatchFunctionBase override. | 103 // FileWatchFunctionBase override. |
102 virtual void PerformFileWatchOperation( | 104 virtual void PerformFileWatchOperation( |
103 const base::FilePath& local_path, | 105 const base::FilePath& local_path, |
104 const base::FilePath& virtual_path, | 106 const base::FilePath& virtual_path, |
105 const std::string& extension_id) OVERRIDE; | 107 const std::string& extension_id) OVERRIDE; |
106 }; | 108 }; |
107 | 109 |
108 | 110 |
109 // Implements the chrome.fileBrowserPrivate.removeFileWatch method. | 111 // Implements the chrome.fileBrowserPrivate.removeFileWatch method. |
110 // Stops watching changes in directories. | 112 // Stops watching changes in directories. |
111 class RemoveFileWatchFunction : public FileWatchFunctionBase { | 113 class FileBrowserPrivateRemoveFileWatchFunction : public FileWatchFunctionBase { |
112 public: | 114 public: |
113 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch", | 115 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch", |
114 FILEBROWSERPRIVATE_REMOVEFILEWATCH) | 116 FILEBROWSERPRIVATE_REMOVEFILEWATCH) |
115 | 117 |
116 RemoveFileWatchFunction(); | 118 FileBrowserPrivateRemoveFileWatchFunction(); |
117 | 119 |
118 protected: | 120 protected: |
119 virtual ~RemoveFileWatchFunction(); | 121 virtual ~FileBrowserPrivateRemoveFileWatchFunction(); |
120 | 122 |
121 // FileWatchFunctionBase override. | 123 // FileWatchFunctionBase override. |
122 virtual void PerformFileWatchOperation( | 124 virtual void PerformFileWatchOperation( |
123 const base::FilePath& local_path, | 125 const base::FilePath& local_path, |
124 const base::FilePath& virtual_path, | 126 const base::FilePath& virtual_path, |
125 const std::string& extension_id) OVERRIDE; | 127 const std::string& extension_id) OVERRIDE; |
126 }; | 128 }; |
127 | 129 |
128 // Implements the chrome.fileBrowserPrivate.setLastModified method. | 130 // Implements the chrome.fileBrowserPrivate.setLastModified method. |
129 // Sets last modified date in seconds of local file | 131 // Sets last modified date in seconds of local file |
130 class SetLastModifiedFunction : public LoggedAsyncExtensionFunction { | 132 class FileBrowserPrivateSetLastModifiedFunction |
| 133 : public LoggedAsyncExtensionFunction { |
131 public: | 134 public: |
132 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified", | 135 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified", |
133 FILEBROWSERPRIVATE_SETLASTMODIFIED) | 136 FILEBROWSERPRIVATE_SETLASTMODIFIED) |
134 | 137 |
135 SetLastModifiedFunction(); | 138 FileBrowserPrivateSetLastModifiedFunction(); |
136 | 139 |
137 protected: | 140 protected: |
138 virtual ~SetLastModifiedFunction(); | 141 virtual ~FileBrowserPrivateSetLastModifiedFunction(); |
139 | 142 |
140 // AsyncExtensionFunction overrides. | 143 // AsyncExtensionFunction overrides. |
141 virtual bool RunImpl() OVERRIDE; | 144 virtual bool RunImpl() OVERRIDE; |
142 }; | 145 }; |
143 | 146 |
144 // Implements the chrome.fileBrowserPrivate.getSizeStats method. | 147 // Implements the chrome.fileBrowserPrivate.getSizeStats method. |
145 class GetSizeStatsFunction : public LoggedAsyncExtensionFunction { | 148 class FileBrowserPrivateGetSizeStatsFunction |
| 149 : public LoggedAsyncExtensionFunction { |
146 public: | 150 public: |
147 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats", | 151 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats", |
148 FILEBROWSERPRIVATE_GETSIZESTATS) | 152 FILEBROWSERPRIVATE_GETSIZESTATS) |
149 | 153 |
150 GetSizeStatsFunction(); | 154 FileBrowserPrivateGetSizeStatsFunction(); |
151 | 155 |
152 protected: | 156 protected: |
153 virtual ~GetSizeStatsFunction(); | 157 virtual ~FileBrowserPrivateGetSizeStatsFunction(); |
154 | 158 |
155 // AsyncExtensionFunction overrides. | 159 // AsyncExtensionFunction overrides. |
156 virtual bool RunImpl() OVERRIDE; | 160 virtual bool RunImpl() OVERRIDE; |
157 | 161 |
158 private: | 162 private: |
159 void GetDriveAvailableSpaceCallback(drive::FileError error, | 163 void GetDriveAvailableSpaceCallback(drive::FileError error, |
160 int64 bytes_total, | 164 int64 bytes_total, |
161 int64 bytes_used); | 165 int64 bytes_used); |
162 | 166 |
163 void GetSizeStatsCallback(const uint64* total_size, | 167 void GetSizeStatsCallback(const uint64* total_size, |
164 const uint64* remaining_size); | 168 const uint64* remaining_size); |
165 }; | 169 }; |
166 | 170 |
167 // Implements the chrome.fileBrowserPrivate.getVolumeMetadata method. | 171 // Implements the chrome.fileBrowserPrivate.getVolumeMetadata method. |
168 // Retrieves devices meta-data. Expects volume's device path as an argument. | 172 // Retrieves devices meta-data. Expects volume's device path as an argument. |
169 class GetVolumeMetadataFunction : public LoggedAsyncExtensionFunction { | 173 class FileBrowserPrivateGetVolumeMetadataFunction |
| 174 : public LoggedAsyncExtensionFunction { |
170 public: | 175 public: |
171 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata", | 176 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata", |
172 FILEBROWSERPRIVATE_GETVOLUMEMETADATA) | 177 FILEBROWSERPRIVATE_GETVOLUMEMETADATA) |
173 | 178 |
174 GetVolumeMetadataFunction(); | 179 FileBrowserPrivateGetVolumeMetadataFunction(); |
175 | 180 |
176 protected: | 181 protected: |
177 virtual ~GetVolumeMetadataFunction(); | 182 virtual ~FileBrowserPrivateGetVolumeMetadataFunction(); |
178 | 183 |
179 // AsyncExtensionFunction overrides. | 184 // AsyncExtensionFunction overrides. |
180 virtual bool RunImpl() OVERRIDE; | 185 virtual bool RunImpl() OVERRIDE; |
181 }; | 186 }; |
182 | 187 |
183 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method. | 188 // Implements the chrome.fileBrowserPrivate.validatePathNameLength method. |
184 class ValidatePathNameLengthFunction : public LoggedAsyncExtensionFunction { | 189 class FileBrowserPrivateValidatePathNameLengthFunction |
| 190 : public LoggedAsyncExtensionFunction { |
185 public: | 191 public: |
186 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength", | 192 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength", |
187 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH) | 193 FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH) |
188 | 194 |
189 ValidatePathNameLengthFunction(); | 195 FileBrowserPrivateValidatePathNameLengthFunction(); |
190 | 196 |
191 protected: | 197 protected: |
192 virtual ~ValidatePathNameLengthFunction(); | 198 virtual ~FileBrowserPrivateValidatePathNameLengthFunction(); |
193 | 199 |
194 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); | 200 void OnFilePathLimitRetrieved(size_t current_length, size_t max_length); |
195 | 201 |
196 // AsyncExtensionFunction overrides. | 202 // AsyncExtensionFunction overrides. |
197 virtual bool RunImpl() OVERRIDE; | 203 virtual bool RunImpl() OVERRIDE; |
198 }; | 204 }; |
199 | 205 |
200 // Implements the chrome.fileBrowserPrivate.formatDevice method. | 206 // Implements the chrome.fileBrowserPrivate.formatDevice method. |
201 // Formats Device given its mount path. | 207 // Formats Device given its mount path. |
202 class FormatDeviceFunction : public LoggedAsyncExtensionFunction { | 208 class FileBrowserPrivateFormatDeviceFunction |
| 209 : public LoggedAsyncExtensionFunction { |
203 public: | 210 public: |
204 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice", | 211 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice", |
205 FILEBROWSERPRIVATE_FORMATDEVICE) | 212 FILEBROWSERPRIVATE_FORMATDEVICE) |
206 | 213 |
207 FormatDeviceFunction(); | 214 FileBrowserPrivateFormatDeviceFunction(); |
208 | 215 |
209 protected: | 216 protected: |
210 virtual ~FormatDeviceFunction(); | 217 virtual ~FileBrowserPrivateFormatDeviceFunction(); |
211 | 218 |
212 // AsyncExtensionFunction overrides. | 219 // AsyncExtensionFunction overrides. |
213 virtual bool RunImpl() OVERRIDE; | 220 virtual bool RunImpl() OVERRIDE; |
214 }; | 221 }; |
215 | 222 |
216 } // namespace extensions | 223 } // namespace extensions |
217 | 224 |
218 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYST
EM_H_ | 225 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYST
EM_H_ |
OLD | NEW |