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_LOCAL_FILE_SYSTEM_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_LOCAL_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 #include "webkit/fileapi/file_system_file_util.h" |
| 17 #include "webkit/fileapi/file_system_types.h" |
| 18 |
| 19 namespace base { |
| 20 struct PlatformFileInfo; |
| 21 class MessageLoopProxy; |
| 22 class Time; |
| 23 } |
| 24 |
| 25 class GURL; |
| 26 |
| 27 namespace fileapi { |
| 28 |
| 29 using base::PlatformFile; |
| 30 using base::PlatformFileError; |
| 31 |
| 32 class FileSystemOperationContext; |
| 33 |
| 34 // A large part of this implementation is taken from base::FileUtilProxy. |
| 35 // TODO(dmikurube, kinuko): Clean up base::FileUtilProxy to factor out common |
| 36 // routines. It includes dropping FileAPI-specific routines from FileUtilProxy. |
| 37 class LocalFileSystemFileUtil : public FileSystemFileUtil { |
| 38 public: |
| 39 static LocalFileSystemFileUtil* GetInstance(); |
| 40 |
| 41 // Creates or opens a file with the given flags. It is invalid to pass NULL |
| 42 // for the callback. |
| 43 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 44 // a new file at the given |file_path| and calls back with |
| 45 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
| 46 virtual PlatformFileError CreateOrOpen( |
| 47 FileSystemOperationContext* context, |
| 48 const FilePath& file_path, |
| 49 int file_flags, |
| 50 PlatformFile* file_handle, |
| 51 bool* created); |
| 52 |
| 53 // Ensures that the given |file_path| exist. This creates a empty new file |
| 54 // at |file_path| if the |file_path| does not exist. |
| 55 // If a new file han not existed and is created at the |file_path|, |
| 56 // |created| of the callback argument is set true and |error code| |
| 57 // is set PLATFORM_FILE_OK. |
| 58 // If the file already exists, |created| is set false and |error code| |
| 59 // is set PLATFORM_FILE_OK. |
| 60 // If the file hasn't existed but it couldn't be created for some other |
| 61 // reasons, |created| is set false and |error code| indicates the error. |
| 62 virtual PlatformFileError EnsureFileExists( |
| 63 FileSystemOperationContext* context, |
| 64 const FilePath& file_path, bool* created); |
| 65 |
| 66 // Retrieves the information about a file. It is invalid to pass NULL for the |
| 67 // callback. |
| 68 virtual PlatformFileError GetFileInfo( |
| 69 FileSystemOperationContext* context, |
| 70 const FilePath& file_, base::PlatformFileInfo* file_info); |
| 71 |
| 72 virtual PlatformFileError ReadDirectory( |
| 73 FileSystemOperationContext* context, |
| 74 const FilePath& file_path, |
| 75 std::vector<base::FileUtilProxy::Entry>* entries); |
| 76 |
| 77 // Creates directory at given path. It's an error to create |
| 78 // if |exclusive| is true and dir already exists. |
| 79 virtual PlatformFileError CreateDirectory( |
| 80 FileSystemOperationContext* context, |
| 81 const FilePath& file_path, |
| 82 bool exclusive, |
| 83 bool recursive); |
| 84 |
| 85 // Copies a file or a directory from |src_file_path| to |dest_file_path| |
| 86 // Error cases: |
| 87 // If destination file doesn't exist or destination's parent |
| 88 // doesn't exists. |
| 89 // If source dir exists but destination path is an existing file. |
| 90 // If source file exists but destination path is an existing directory. |
| 91 // If source is a parent of destination. |
| 92 // If source doesn't exists. |
| 93 virtual PlatformFileError Copy( |
| 94 FileSystemOperationContext* context, |
| 95 const FilePath& src_file_path, |
| 96 const FilePath& dest_file_path); |
| 97 |
| 98 // Moves a file or a directory from src_file_path to dest_file_path. |
| 99 // Error cases are similar to Copy method's error cases. |
| 100 virtual PlatformFileError Move( |
| 101 FileSystemOperationContext* context, |
| 102 const FilePath& src_file_path, |
| 103 const FilePath& dest_file_path); |
| 104 |
| 105 // Deletes a file or a directory. |
| 106 // It is an error to delete a non-empty directory with recursive=false. |
| 107 virtual PlatformFileError Delete( |
| 108 FileSystemOperationContext* context, |
| 109 const FilePath& file_path, |
| 110 bool recursive); |
| 111 |
| 112 // Touches a file. The callback can be NULL. |
| 113 virtual PlatformFileError Touch( |
| 114 FileSystemOperationContext* context, |
| 115 const FilePath& file_path, |
| 116 const base::Time& last_access_time, |
| 117 const base::Time& last_modified_time); |
| 118 |
| 119 // Truncates a file to the given length. If |length| is greater than the |
| 120 // current length of the file, the file will be extended with zeroes. |
| 121 // The callback can be NULL. |
| 122 virtual PlatformFileError Truncate( |
| 123 FileSystemOperationContext* context, |
| 124 const FilePath& path, |
| 125 int64 length); |
| 126 |
| 127 protected: |
| 128 LocalFileSystemFileUtil() { } |
| 129 |
| 130 friend struct DefaultSingletonTraits<LocalFileSystemFileUtil>; |
| 131 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemFileUtil); |
| 132 |
| 133 private: |
| 134 // Given the filesystem's root URL and a virtual path, produces a real, full |
| 135 // local path. |
| 136 FilePath GetLocalPath( |
| 137 FileSystemOperationContext* context, |
| 138 const GURL& origin_url, |
| 139 FileSystemType type, |
| 140 const FilePath& virtual_path); |
| 141 |
| 142 }; |
| 143 |
| 144 } // namespace fileapi |
| 145 |
| 146 #endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_FILE_UTIL_H_ |
OLD | NEW |