| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" |
| 11 #include "base/file_util_proxy.h" |
| 12 #include "base/platform_file.h" |
| 13 #include "base/ref_counted.h" |
| 14 #include "base/singleton.h" |
| 15 #include "base/tracked_objects.h" |
| 16 |
| 17 namespace base { |
| 18 struct PlatformFileInfo; |
| 19 class MessageLoopProxy; |
| 20 class Time; |
| 21 } |
| 22 |
| 23 namespace fileapi { |
| 24 |
| 25 using base::PlatformFile; |
| 26 using base::PlatformFileError; |
| 27 |
| 28 class FileSystemOperationContext; |
| 29 |
| 30 class FileSystemFileUtil { |
| 31 public: |
| 32 static FileSystemFileUtil* GetInstance(); |
| 33 |
| 34 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 35 // for the callback. |
| 36 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 37 // a new file at the given |file_path| and calls back with |
| 38 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 39 virtual PlatformFileError CreateOrOpen( |
| 40 FileSystemOperationContext* context, |
| 41 const FilePath& file_path, |
| 42 int file_flags, |
| 43 PlatformFile* file_handle, |
| 44 bool* created); |
| 45 |
| 46 // Close the given file handle. |
| 47 virtual PlatformFileError Close( |
| 48 FileSystemOperationContext* context, |
| 49 PlatformFile); |
| 50 |
| 51 // Ensures that the given |file_path| exist. This creates a empty new file |
| 52 // at |file_path| if the |file_path| does not exist. |
| 53 // If a new file han not existed and is created at the |file_path|, |
| 54 // |created| of the callback argument is set true and |error code| |
| 55 // is set PLATFORM_FILE_OK. |
| 56 // If the file already exists, |created| is set false and |error code| |
| 57 // is set PLATFORM_FILE_OK. |
| 58 // If the file hasn't existed but it couldn't be created for some other |
| 59 // reasons, |created| is set false and |error code| indicates the error. |
| 60 virtual PlatformFileError EnsureFileExists( |
| 61 FileSystemOperationContext* context, |
| 62 const FilePath& file_path, bool* created); |
| 63 |
| 64 // Retrieves the information about a file. It is invalid to pass NULL for the |
| 65 // callback. |
| 66 virtual PlatformFileError GetFileInfo( |
| 67 FileSystemOperationContext* context, |
| 68 const FilePath& file_, base::PlatformFileInfo* file_info); |
| 69 |
| 70 virtual PlatformFileError ReadDirectory( |
| 71 FileSystemOperationContext* context, |
| 72 const FilePath& file_path, |
| 73 std::vector<base::FileUtilProxy::Entry>* entries); |
| 74 |
| 75 // Creates directory at given path. It's an error to create |
| 76 // if |exclusive| is true and dir already exists. |
| 77 virtual PlatformFileError CreateDirectory( |
| 78 FileSystemOperationContext* context, |
| 79 const FilePath& file_path, |
| 80 bool exclusive); |
| 81 |
| 82 // Copies a file or a directory from |src_file_path| to |dest_file_path| |
| 83 // Error cases: |
| 84 // If destination file doesn't exist or destination's parent |
| 85 // doesn't exists. |
| 86 // If source dir exists but destination path is an existing file. |
| 87 // If source file exists but destination path is an existing directory. |
| 88 // If source is a parent of destination. |
| 89 // If source doesn't exists. |
| 90 virtual PlatformFileError Copy( |
| 91 FileSystemOperationContext* context, |
| 92 const FilePath& src_file_path, |
| 93 const FilePath& dest_file_path); |
| 94 |
| 95 // Moves a file or a directory from src_file_path to dest_file_path. |
| 96 // Error cases are similar to Copy method's error cases. |
| 97 virtual PlatformFileError Move( |
| 98 FileSystemOperationContext* context, |
| 99 const FilePath& src_file_path, |
| 100 const FilePath& dest_file_path); |
| 101 |
| 102 // Deletes a file or a directory. |
| 103 // It is an error to delete a non-empty directory with recursive=false. |
| 104 virtual PlatformFileError Delete( |
| 105 FileSystemOperationContext* context, |
| 106 const FilePath& file_path, |
| 107 bool recursive); |
| 108 |
| 109 // Touches a file. The callback can be NULL. |
| 110 virtual PlatformFileError Touch( |
| 111 FileSystemOperationContext* context, |
| 112 const FilePath& file_path, |
| 113 const base::Time& last_access_time, |
| 114 const base::Time& last_modified_time); |
| 115 |
| 116 // Truncates a file to the given length. If |length| is greater than the |
| 117 // current length of the file, the file will be extended with zeroes. |
| 118 // The callback can be NULL. |
| 119 virtual PlatformFileError Truncate( |
| 120 FileSystemOperationContext* context, |
| 121 const FilePath& path, |
| 122 int64 length); |
| 123 |
| 124 protected: |
| 125 FileSystemFileUtil() { } |
| 126 friend struct DefaultSingletonTraits<FileSystemFileUtil>; |
| 127 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
| 128 }; |
| 129 |
| 130 } // namespace fileapi |
| 131 |
| 132 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| OLD | NEW |