OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 // This class is designed to serve one-time file system operation per instance. | 42 // This class is designed to serve one-time file system operation per instance. |
43 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 43 // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
44 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of | 44 // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of |
45 // this object and it should be called no more than once. | 45 // this object and it should be called no more than once. |
46 // This class is self-destructed and an instance automatically gets deleted | 46 // This class is self-destructed and an instance automatically gets deleted |
47 // when its operation is finished. | 47 // when its operation is finished. |
48 class FileSystemOperation { | 48 class FileSystemOperation { |
49 public: | 49 public: |
50 // |dispatcher| will be owned by this class. | 50 // |dispatcher| will be owned by this class. |
51 // |file_system_file_util| is optional; if supplied, it will not be deleted by | 51 // |file_util| is optional; if supplied, it will not be deleted by |
52 // the class. It's expecting a pointer to a singleton. | 52 // the class. It's expecting a pointer to a singleton. |
53 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, | 53 FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, |
54 scoped_refptr<base::MessageLoopProxy> proxy, | 54 scoped_refptr<base::MessageLoopProxy> proxy, |
55 FileSystemContext* file_system_context, | 55 FileSystemContext* file_system_context, |
56 FileSystemFileUtil* file_system_file_util); | 56 FileUtil* file_util); |
57 virtual ~FileSystemOperation(); | 57 virtual ~FileSystemOperation(); |
58 | 58 |
59 void OpenFileSystem(const GURL& origin_url, | 59 void OpenFileSystem(const GURL& origin_url, |
60 fileapi::FileSystemType type, | 60 fileapi::FileSystemType type, |
61 bool create); | 61 bool create); |
62 void CreateFile(const GURL& path, | 62 void CreateFile(const GURL& path, |
63 bool exclusive); | 63 bool exclusive); |
64 void CreateDirectory(const GURL& path, | 64 void CreateDirectory(const GURL& path, |
65 bool exclusive, | 65 bool exclusive, |
66 bool recursive); | 66 bool recursive); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 bool created); | 164 bool created); |
165 | 165 |
166 // Helper for Write(). | 166 // Helper for Write(). |
167 void OnFileOpenedForWrite( | 167 void OnFileOpenedForWrite( |
168 base::PlatformFileError rv, | 168 base::PlatformFileError rv, |
169 base::PassPlatformFile file, | 169 base::PassPlatformFile file, |
170 bool created); | 170 bool created); |
171 | 171 |
172 // Checks the validity of a given |path| for reading, cracks the path into | 172 // Checks the validity of a given |path| for reading, cracks the path into |
173 // root URL and virtual path components, and returns the correct | 173 // root URL and virtual path components, and returns the correct |
174 // FileSystemFileUtil subclass for this type. | 174 // FileUtil subclass for this type. |
175 // Returns true if the given |path| is a valid FileSystem path. | 175 // Returns true if the given |path| is a valid FileSystem path. |
176 // Otherwise it calls dispatcher's DidFail method with | 176 // Otherwise it calls dispatcher's DidFail method with |
177 // PLATFORM_FILE_ERROR_SECURITY and returns false. | 177 // PLATFORM_FILE_ERROR_SECURITY and returns false. |
178 // (Note: this doesn't delete this when it calls DidFail and returns false; | 178 // (Note: this doesn't delete this when it calls DidFail and returns false; |
179 // it's the caller's responsibility.) | 179 // it's the caller's responsibility.) |
180 bool VerifyFileSystemPathForRead(const GURL& path, | 180 bool VerifyFileSystemPathForRead(const GURL& path, |
181 GURL* root_url, | 181 GURL* root_url, |
182 FileSystemType* type, | 182 FileSystemType* type, |
183 FilePath* virtual_path, | 183 FilePath* virtual_path, |
184 FileSystemFileUtil** file_system_file_util); | 184 FileUtil** file_util); |
185 | 185 |
186 // Checks the validity of a given |path| for writing, cracks the path into | 186 // Checks the validity of a given |path| for writing, cracks the path into |
187 // root URL and virtual path components, and returns the correct | 187 // root URL and virtual path components, and returns the correct |
188 // FileSystemFileUtil subclass for this type. | 188 // FileUtil subclass for this type. |
189 // Returns true if the given |path| is a valid FileSystem path, and | 189 // Returns true if the given |path| is a valid FileSystem path, and |
190 // its origin embedded in the path has the right to write. | 190 // its origin embedded in the path has the right to write. |
191 // Otherwise it fires dispatcher's DidFail method with | 191 // Otherwise it fires dispatcher's DidFail method with |
192 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, | 192 // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, |
193 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to | 193 // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to |
194 // write to the storage. | 194 // write to the storage. |
195 // In either case it returns false after firing DidFail. | 195 // In either case it returns false after firing DidFail. |
196 // If |create| flag is true this also checks if the |path| contains | 196 // If |create| flag is true this also checks if the |path| contains |
197 // any restricted names and chars. If it does, the call fires dispatcher's | 197 // any restricted names and chars. If it does, the call fires dispatcher's |
198 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. | 198 // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. |
199 // (Note: this doesn't delete this when it calls DidFail and returns false; | 199 // (Note: this doesn't delete this when it calls DidFail and returns false; |
200 // it's the caller's responsibility.) | 200 // it's the caller's responsibility.) |
201 bool VerifyFileSystemPathForWrite(const GURL& path, | 201 bool VerifyFileSystemPathForWrite(const GURL& path, |
202 bool create, | 202 bool create, |
203 GURL* root_url, | 203 GURL* root_url, |
204 FileSystemType* type, | 204 FileSystemType* type, |
205 FilePath* virtual_path, | 205 FilePath* virtual_path, |
206 FileSystemFileUtil** file_system_file_util); | 206 FileUtil** file_util); |
207 | 207 |
208 #ifndef NDEBUG | 208 #ifndef NDEBUG |
209 enum OperationType { | 209 enum OperationType { |
210 kOperationNone, | 210 kOperationNone, |
211 kOperationOpenFileSystem, | 211 kOperationOpenFileSystem, |
212 kOperationCreateFile, | 212 kOperationCreateFile, |
213 kOperationCreateDirectory, | 213 kOperationCreateDirectory, |
214 kOperationCopy, | 214 kOperationCopy, |
215 kOperationMove, | 215 kOperationMove, |
216 kOperationDirectoryExists, | 216 kOperationDirectoryExists, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 // Length to be truncated. | 259 // Length to be truncated. |
260 int64 length_; | 260 int64 length_; |
261 | 261 |
262 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); | 262 DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); |
263 }; | 263 }; |
264 | 264 |
265 } // namespace fileapi | 265 } // namespace fileapi |
266 | 266 |
267 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 267 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |