1 // Copyright (c) 2012 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 #ifndef WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 6 #define WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/files/file_util_proxy.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/platform_file.h" 12 #include "webkit/browser/fileapi/file_system_file_util.h" 13 #include "webkit/browser/webkit_storage_browser_export.h" 14 15 namespace base { 16 class Time; 17 } 18 19 namespace fileapi { 20 21 // A thin wrapper class for accessing the OS native filesystem. 22 // This performs common error checks necessary to implement FileUtil family 23 // in addition to perform native filesystem operations. 24 // 25 // For the error checks it performs please see the comment for 26 // FileSystemFileUtil interface 27 // (webkit/browser/fileapi/file_system_file_util.h). 28 // 29 // Note that all the methods of this class are static and this does NOT 30 // inherit from FileSystemFileUtil. 31 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE NativeFileUtil { 32 public: 33 enum CopyOrMoveMode { 34 COPY_NOSYNC, 35 COPY_SYNC, 36 MOVE 37 }; 38 static CopyOrMoveMode CopyOrMoveModeForDestination( 39 const FileSystemURL& dest_url, bool copy); 40 41 static base::PlatformFileError CreateOrOpen( 42 const base::FilePath& path, 43 int file_flags, 44 base::PlatformFile* file_handle, 45 bool* created); 46 static base::PlatformFileError Close(base::PlatformFile file); 47 static base::PlatformFileError EnsureFileExists(const base::FilePath& path, 48 bool* created); 49 static base::PlatformFileError CreateDirectory(const base::FilePath& path, 50 bool exclusive, 51 bool recursive); 52 static base::PlatformFileError GetFileInfo(const base::FilePath& path, 53 base::PlatformFileInfo* file_info); 54 static scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 55 CreateFileEnumerator(const base::FilePath& root_path, 56 bool recursive); 57 static base::PlatformFileError Touch(const base::FilePath& path, 58 const base::Time& last_access_time, 59 const base::Time& last_modified_time); 60 static base::PlatformFileError Truncate(const base::FilePath& path, 61 int64 length); 62 static bool PathExists(const base::FilePath& path); 63 static bool DirectoryExists(const base::FilePath& path); 64 static base::PlatformFileError CopyOrMoveFile( 65 const base::FilePath& src_path, 66 const base::FilePath& dest_path, 67 FileSystemOperation::CopyOrMoveOption option, 68 CopyOrMoveMode mode); 69 static base::PlatformFileError DeleteFile(const base::FilePath& path); 70 static base::PlatformFileError DeleteDirectory(const base::FilePath& path); 71 72 private: 73 DISALLOW_IMPLICIT_CONSTRUCTORS(NativeFileUtil); 74 }; 75 76 } // namespace fileapi 77 78 #endif // WEBKIT_BROWSER_FILEAPI_NATIVE_FILE_UTIL_H_ 79