| 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_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | |
| 9 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | |
| 11 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 14 #include "base/tracked_objects.h" | |
| 15 #include "webkit/fileapi/file_system_types.h" | |
| 16 | 11 |
| 17 namespace base { | 12 namespace base { |
| 18 struct PlatformFileInfo; | |
| 19 class MessageLoopProxy; | |
| 20 class Time; | 13 class Time; |
| 21 } | 14 } |
| 22 | 15 |
| 23 namespace fileapi { | 16 namespace fileapi { |
| 24 | 17 |
| 25 using base::PlatformFile; | 18 using base::PlatformFile; |
| 26 using base::PlatformFileError; | 19 using base::PlatformFileError; |
| 27 class FileSystemOperationContext; | 20 class FileSystemOperationContext; |
| 28 | 21 |
| 29 // A large part of this implementation is taken from base::FileUtilProxy. | 22 // A large part of this implementation is taken from base::FileUtilProxy. |
| 30 // TODO(dmikurube, kinuko): Clean up base::FileUtilProxy to factor out common | 23 // TODO(dmikurube, kinuko): Clean up base::FileUtilProxy to factor out common |
| 31 // routines. It includes dropping FileAPI-specific routines from FileUtilProxy. | 24 // routines. It includes dropping FileAPI-specific routines from FileUtilProxy. |
| 32 // | 25 // |
| 33 // The default implementations of the virtual methods below (*1) assume the | 26 // The default implementations of the virtual methods below (*1) assume the |
| 34 // given paths are native ones for the host platform. The subclasses that | 27 // given paths are native ones for the host platform. The subclasses that |
| 35 // perform local path translation/obfuscation must override them. | 28 // perform local path translation/obfuscation must override them. |
| 36 // (*1) All virtual methods which receive FilePath as their arguments: | 29 // (*1) All virtual methods which receive FilePath as their arguments: |
| 37 // CreateOrOpen, EnsureFileExists, GetLocalFilePath, GetFileInfo, | 30 // CreateOrOpen, EnsureFileExists, GetLocalFilePath, GetFileInfo, |
| 38 // ReadDirectory, CreateDirectory, CopyOrMoveFile, DeleteFile, | 31 // ReadDirectory, CreateDirectory, CopyOrMoveFile, DeleteFile, |
| 39 // DeleteSingleDirectory, Touch, Truncate, PathExists, DirectoryExists, | 32 // DeleteSingleDirectory, Touch, Truncate, PathExists, DirectoryExists, |
| 40 // IsDirectoryEmpty and CreateFileEnumerator. | 33 // IsDirectoryEmpty and CreateFileEnumerator. |
| 41 // | 34 // |
| 42 // The methods below (*2) assume the given paths may not be native ones for the | 35 // The methods below (*2) assume the given paths may not be native ones for the |
| 43 // host platform. The subclasses should not override them. They provide basic | 36 // host platform. The subclasses should not override them. They provide basic |
| 44 // meta logic by using other virtual methods. | 37 // meta logic by using other virtual methods. |
| 45 // (*2) All non-virtual methods: Copy, Move, Delete, DeleteDirectoryRecursive, | 38 // (*2) All non-virtual methods: Copy, Move, Delete, DeleteDirectoryRecursive, |
| 46 // PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory. | 39 // PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory. |
| 47 class FileSystemFileUtil { | 40 class FileApiFileUtil { |
| 48 public: | 41 public: |
| 49 FileSystemFileUtil() {} | 42 FileApiFileUtil(); |
| 50 virtual ~FileSystemFileUtil() {} | 43 explicit FileApiFileUtil(FileApiFileUtil* underlying_file_util); |
| 44 virtual ~FileApiFileUtil(); |
| 51 | 45 |
| 52 // Creates or opens a file with the given flags. It is invalid to pass NULL | 46 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 53 // for the callback. | 47 // for the callback. |
| 54 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 48 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 55 // a new file at the given |file_path| and calls back with | 49 // a new file at the given |file_path| and calls back with |
| 56 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. | 50 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 57 virtual PlatformFileError CreateOrOpen( | 51 virtual PlatformFileError CreateOrOpen( |
| 58 FileSystemOperationContext* context, | 52 FileSystemOperationContext* context, |
| 59 const FilePath& file_path, | 53 const FilePath& file_path, |
| 60 int file_flags, | 54 int file_flags, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 105 |
| 112 // Copies or moves a single file. | 106 // Copies or moves a single file. |
| 113 virtual PlatformFileError CopyOrMoveFile( | 107 virtual PlatformFileError CopyOrMoveFile( |
| 114 FileSystemOperationContext* context, | 108 FileSystemOperationContext* context, |
| 115 const FilePath& src_file_path, | 109 const FilePath& src_file_path, |
| 116 const FilePath& dest_file_path, | 110 const FilePath& dest_file_path, |
| 117 bool copy); | 111 bool copy); |
| 118 | 112 |
| 119 // Copies in a single file from a different filesystem. The src_file_path is | 113 // Copies in a single file from a different filesystem. The src_file_path is |
| 120 // a true local platform path, regardless of which subclass of | 114 // a true local platform path, regardless of which subclass of |
| 121 // FileSystemFileUtil is being invoked. | 115 // FileApiFileUtil is being invoked. |
| 122 virtual PlatformFileError CopyInForeignFile( | 116 virtual PlatformFileError CopyInForeignFile( |
| 123 FileSystemOperationContext* context, | 117 FileSystemOperationContext* context, |
| 124 const FilePath& src_file_path, | 118 const FilePath& src_file_path, |
| 125 const FilePath& dest_file_path); | 119 const FilePath& dest_file_path); |
| 126 | 120 |
| 127 // Copies a file or a directory from |src_file_path| to |dest_file_path|. | 121 // Copies a file or a directory from |src_file_path| to |dest_file_path|. |
| 128 // | 122 // |
| 129 // Error cases: | 123 // Error cases: |
| 130 // If destination's parent doesn't exist. | 124 // If destination's parent doesn't exist. |
| 131 // If source dir exists but destination path is an existing file. | 125 // If source dir exists but destination path is an existing file. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 218 |
| 225 virtual bool IsDirectory() = 0; | 219 virtual bool IsDirectory() = 0; |
| 226 }; | 220 }; |
| 227 | 221 |
| 228 class EmptyFileEnumerator : public AbstractFileEnumerator { | 222 class EmptyFileEnumerator : public AbstractFileEnumerator { |
| 229 virtual FilePath Next() { return FilePath(); } | 223 virtual FilePath Next() { return FilePath(); } |
| 230 virtual bool IsDirectory() { return false; } | 224 virtual bool IsDirectory() { return false; } |
| 231 }; | 225 }; |
| 232 | 226 |
| 233 // Returns a pointer to a new instance of AbstractFileEnumerator which is | 227 // Returns a pointer to a new instance of AbstractFileEnumerator which is |
| 234 // implemented for each FileUtil subclass. The instance needs to be freed | 228 // implemented for each FileApiFileUtil subclass. The instance needs to be |
| 235 // by the caller, and its lifetime should not extend past when the current | 229 // freed by the caller, and its lifetime should not extend past when the |
| 236 // call returns to the main FILE message loop. | 230 // current call returns to the main FILE message loop. |
| 237 virtual AbstractFileEnumerator* CreateFileEnumerator( | 231 virtual AbstractFileEnumerator* CreateFileEnumerator( |
| 238 FileSystemOperationContext* unused, | 232 FileSystemOperationContext* unused, |
| 239 const FilePath& root_path); | 233 const FilePath& root_path); |
| 240 | 234 |
| 241 protected: | 235 protected: |
| 242 // Deletes a directory and all entries under the directory. | 236 // Deletes a directory and all entries under the directory. |
| 243 // | 237 // |
| 244 // This method is called from Delete. It internally calls two following | 238 // This method is called from Delete. It internally calls two following |
| 245 // virtual methods, | 239 // virtual methods, |
| 246 // - (virtual) DeleteFile to delete files, and | 240 // - (virtual) DeleteFile to delete files, and |
| (...skipping 24 matching lines...) Expand all Loading... |
| 271 // Determines whether a simple same-filesystem move or copy can be done. If | 265 // Determines whether a simple same-filesystem move or copy can be done. If |
| 272 // so, it delegates to CopyOrMoveFile. Otherwise it looks up the true | 266 // so, it delegates to CopyOrMoveFile. Otherwise it looks up the true |
| 273 // platform path of the source file, delegates to CopyInForeignFile, and [for | 267 // platform path of the source file, delegates to CopyInForeignFile, and [for |
| 274 // move] calls DeleteFile on the source file. | 268 // move] calls DeleteFile on the source file. |
| 275 PlatformFileError CopyOrMoveFileHelper( | 269 PlatformFileError CopyOrMoveFileHelper( |
| 276 FileSystemOperationContext* context, | 270 FileSystemOperationContext* context, |
| 277 const FilePath& src_file_path, | 271 const FilePath& src_file_path, |
| 278 const FilePath& dest_file_path, | 272 const FilePath& dest_file_path, |
| 279 bool copy); | 273 bool copy); |
| 280 | 274 |
| 281 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); | 275 FileApiFileUtil* underlying_file_util() const { |
| 276 return underlying_file_util_.get(); |
| 277 } |
| 278 |
| 279 private: |
| 280 scoped_ptr<FileApiFileUtil> underlying_file_util_; |
| 281 |
| 282 DISALLOW_COPY_AND_ASSIGN(FileApiFileUtil); |
| 282 }; | 283 }; |
| 283 | 284 |
| 284 } // namespace fileapi | 285 } // namespace fileapi |
| 285 | 286 |
| 286 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 287 #endif // WEBKIT_FILEAPI_FILE_UTIL_H_ |
| OLD | NEW |