OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
7 | 7 |
| 8 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
11 #include "webkit/browser/fileapi/file_system_operation.h" | 12 #include "webkit/browser/fileapi/file_system_operation.h" |
12 #include "webkit/browser/webkit_storage_browser_export.h" | 13 #include "webkit/browser/webkit_storage_browser_export.h" |
13 #include "webkit/common/blob/scoped_file.h" | 14 #include "webkit/common/blob/scoped_file.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class Time; | 17 class Time; |
17 } | 18 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 virtual int64 Size() OVERRIDE; | 54 virtual int64 Size() OVERRIDE; |
54 virtual base::Time LastModifiedTime() OVERRIDE; | 55 virtual base::Time LastModifiedTime() OVERRIDE; |
55 virtual bool IsDirectory() OVERRIDE; | 56 virtual bool IsDirectory() OVERRIDE; |
56 }; | 57 }; |
57 | 58 |
58 virtual ~FileSystemFileUtil() {} | 59 virtual ~FileSystemFileUtil() {} |
59 | 60 |
60 // Creates or opens a file with the given flags. | 61 // Creates or opens a file with the given flags. |
61 // See header comments for AsyncFileUtil::CreateOrOpen() for more details. | 62 // See header comments for AsyncFileUtil::CreateOrOpen() for more details. |
62 // This is used only by Pepper/NaCl File API. | 63 // This is used only by Pepper/NaCl File API. |
63 virtual base::PlatformFileError CreateOrOpen( | 64 virtual base::File::Error CreateOrOpen( |
64 FileSystemOperationContext* context, | 65 FileSystemOperationContext* context, |
65 const FileSystemURL& url, | 66 const FileSystemURL& url, |
66 int file_flags, | 67 int file_flags, |
67 base::PlatformFile* file_handle, | 68 base::PlatformFile* file_handle, |
68 bool* created) = 0; | 69 bool* created) = 0; |
69 | 70 |
70 // Closes the given file handle. | 71 // Closes the given file handle. |
71 // This is used only for Pepper/NaCl File API. | 72 // This is used only for Pepper/NaCl File API. |
72 virtual base::PlatformFileError Close( | 73 virtual base::File::Error Close( |
73 FileSystemOperationContext* context, | 74 FileSystemOperationContext* context, |
74 base::PlatformFile file) = 0; | 75 base::PlatformFile file) = 0; |
75 | 76 |
76 // Ensures that the given |url| exist. This creates a empty new file | 77 // Ensures that the given |url| exist. This creates a empty new file |
77 // at |url| if the |url| does not exist. | 78 // at |url| if the |url| does not exist. |
78 // See header comments for AsyncFileUtil::EnsureFileExists() for more details. | 79 // See header comments for AsyncFileUtil::EnsureFileExists() for more details. |
79 virtual base::PlatformFileError EnsureFileExists( | 80 virtual base::File::Error EnsureFileExists( |
80 FileSystemOperationContext* context, | 81 FileSystemOperationContext* context, |
81 const FileSystemURL& url, bool* created) = 0; | 82 const FileSystemURL& url, bool* created) = 0; |
82 | 83 |
83 // Creates directory at given url. | 84 // Creates directory at given url. |
84 // See header comments for AsyncFileUtil::CreateDirectory() for more details. | 85 // See header comments for AsyncFileUtil::CreateDirectory() for more details. |
85 virtual base::PlatformFileError CreateDirectory( | 86 virtual base::File::Error CreateDirectory( |
86 FileSystemOperationContext* context, | 87 FileSystemOperationContext* context, |
87 const FileSystemURL& url, | 88 const FileSystemURL& url, |
88 bool exclusive, | 89 bool exclusive, |
89 bool recursive) = 0; | 90 bool recursive) = 0; |
90 | 91 |
91 // Retrieves the information about a file. | 92 // Retrieves the information about a file. |
92 // See header comments for AsyncFileUtil::GetFileInfo() for more details. | 93 // See header comments for AsyncFileUtil::GetFileInfo() for more details. |
93 virtual base::PlatformFileError GetFileInfo( | 94 virtual base::File::Error GetFileInfo( |
94 FileSystemOperationContext* context, | 95 FileSystemOperationContext* context, |
95 const FileSystemURL& url, | 96 const FileSystemURL& url, |
96 base::PlatformFileInfo* file_info, | 97 base::File::Info* file_info, |
97 base::FilePath* platform_path) = 0; | 98 base::FilePath* platform_path) = 0; |
98 | 99 |
99 // Returns a pointer to a new instance of AbstractFileEnumerator which is | 100 // Returns a pointer to a new instance of AbstractFileEnumerator which is |
100 // implemented for each FileSystemFileUtil subclass. The instance needs to be | 101 // implemented for each FileSystemFileUtil subclass. The instance needs to be |
101 // freed by the caller, and its lifetime should not extend past when the | 102 // freed by the caller, and its lifetime should not extend past when the |
102 // current call returns to the main FILE message loop. | 103 // current call returns to the main FILE message loop. |
103 // | 104 // |
104 // The supplied context must remain valid at least lifetime of the enumerator | 105 // The supplied context must remain valid at least lifetime of the enumerator |
105 // instance. | 106 // instance. |
106 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 107 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
107 FileSystemOperationContext* context, | 108 FileSystemOperationContext* context, |
108 const FileSystemURL& root_url) = 0; | 109 const FileSystemURL& root_url) = 0; |
109 | 110 |
110 // Maps |file_system_url| given |context| into |local_file_path| | 111 // Maps |file_system_url| given |context| into |local_file_path| |
111 // which represents physical file location on the host OS. | 112 // which represents physical file location on the host OS. |
112 // This may not always make sense for all subclasses. | 113 // This may not always make sense for all subclasses. |
113 virtual base::PlatformFileError GetLocalFilePath( | 114 virtual base::File::Error GetLocalFilePath( |
114 FileSystemOperationContext* context, | 115 FileSystemOperationContext* context, |
115 const FileSystemURL& file_system_url, | 116 const FileSystemURL& file_system_url, |
116 base::FilePath* local_file_path) = 0; | 117 base::FilePath* local_file_path) = 0; |
117 | 118 |
118 // Updates the file metadata information. | 119 // Updates the file metadata information. |
119 // See header comments for AsyncFileUtil::Touch() for more details. | 120 // See header comments for AsyncFileUtil::Touch() for more details. |
120 virtual base::PlatformFileError Touch( | 121 virtual base::File::Error Touch( |
121 FileSystemOperationContext* context, | 122 FileSystemOperationContext* context, |
122 const FileSystemURL& url, | 123 const FileSystemURL& url, |
123 const base::Time& last_access_time, | 124 const base::Time& last_access_time, |
124 const base::Time& last_modified_time) = 0; | 125 const base::Time& last_modified_time) = 0; |
125 | 126 |
126 // Truncates a file to the given length. | 127 // Truncates a file to the given length. |
127 // See header comments for AsyncFileUtil::Truncate() for more details. | 128 // See header comments for AsyncFileUtil::Truncate() for more details. |
128 virtual base::PlatformFileError Truncate( | 129 virtual base::File::Error Truncate( |
129 FileSystemOperationContext* context, | 130 FileSystemOperationContext* context, |
130 const FileSystemURL& url, | 131 const FileSystemURL& url, |
131 int64 length) = 0; | 132 int64 length) = 0; |
132 | 133 |
133 // Copies or moves a single file from |src_url| to |dest_url|. | 134 // Copies or moves a single file from |src_url| to |dest_url|. |
134 // The filesystem type of |src_url| and |dest_url| MUST be same. | 135 // The filesystem type of |src_url| and |dest_url| MUST be same. |
135 // For |option|, please see file_system_operation.h | 136 // For |option|, please see file_system_operation.h |
136 // | 137 // |
137 // This returns: | 138 // This returns: |
138 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 139 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
139 // or the parent directory of |dest_url| does not exist. | 140 // or the parent directory of |dest_url| does not exist. |
140 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 141 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
141 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 142 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
142 // is not a file. | 143 // is not a file. |
143 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 144 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
144 // its parent path is a file. | 145 // its parent path is a file. |
145 // | 146 // |
146 virtual base::PlatformFileError CopyOrMoveFile( | 147 virtual base::File::Error CopyOrMoveFile( |
147 FileSystemOperationContext* context, | 148 FileSystemOperationContext* context, |
148 const FileSystemURL& src_url, | 149 const FileSystemURL& src_url, |
149 const FileSystemURL& dest_url, | 150 const FileSystemURL& dest_url, |
150 CopyOrMoveOption option, | 151 CopyOrMoveOption option, |
151 bool copy) = 0; | 152 bool copy) = 0; |
152 | 153 |
153 // Copies in a single file from a different filesystem. | 154 // Copies in a single file from a different filesystem. |
154 // See header comments for AsyncFileUtil::CopyInForeignFile() for | 155 // See header comments for AsyncFileUtil::CopyInForeignFile() for |
155 // more details. | 156 // more details. |
156 virtual base::PlatformFileError CopyInForeignFile( | 157 virtual base::File::Error CopyInForeignFile( |
157 FileSystemOperationContext* context, | 158 FileSystemOperationContext* context, |
158 const base::FilePath& src_file_path, | 159 const base::FilePath& src_file_path, |
159 const FileSystemURL& dest_url) = 0; | 160 const FileSystemURL& dest_url) = 0; |
160 | 161 |
161 // Deletes a single file. | 162 // Deletes a single file. |
162 // See header comments for AsyncFileUtil::DeleteFile() for more details. | 163 // See header comments for AsyncFileUtil::DeleteFile() for more details. |
163 virtual base::PlatformFileError DeleteFile( | 164 virtual base::File::Error DeleteFile( |
164 FileSystemOperationContext* context, | 165 FileSystemOperationContext* context, |
165 const FileSystemURL& url) = 0; | 166 const FileSystemURL& url) = 0; |
166 | 167 |
167 // Deletes a single empty directory. | 168 // Deletes a single empty directory. |
168 // See header comments for AsyncFileUtil::DeleteDirectory() for more details. | 169 // See header comments for AsyncFileUtil::DeleteDirectory() for more details. |
169 virtual base::PlatformFileError DeleteDirectory( | 170 virtual base::File::Error DeleteDirectory( |
170 FileSystemOperationContext* context, | 171 FileSystemOperationContext* context, |
171 const FileSystemURL& url) = 0; | 172 const FileSystemURL& url) = 0; |
172 | 173 |
173 // Creates a local snapshot file for a given |url| and returns the | 174 // Creates a local snapshot file for a given |url| and returns the |
174 // metadata and platform path of the snapshot file via |callback|. | 175 // metadata and platform path of the snapshot file via |callback|. |
175 // | 176 // |
176 // See header comments for AsyncFileUtil::CreateSnapshotFile() for | 177 // See header comments for AsyncFileUtil::CreateSnapshotFile() for |
177 // more details. | 178 // more details. |
178 virtual webkit_blob::ScopedFile CreateSnapshotFile( | 179 virtual webkit_blob::ScopedFile CreateSnapshotFile( |
179 FileSystemOperationContext* context, | 180 FileSystemOperationContext* context, |
180 const FileSystemURL& url, | 181 const FileSystemURL& url, |
181 base::PlatformFileError* error, | 182 base::File::Error* error, |
182 base::PlatformFileInfo* file_info, | 183 base::File::Info* file_info, |
183 base::FilePath* platform_path) = 0; | 184 base::FilePath* platform_path) = 0; |
184 | 185 |
185 protected: | 186 protected: |
186 FileSystemFileUtil() {} | 187 FileSystemFileUtil() {} |
187 | 188 |
188 private: | 189 private: |
189 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); | 190 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
190 }; | 191 }; |
191 | 192 |
192 } // namespace fileapi | 193 } // namespace fileapi |
193 | 194 |
194 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 195 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
OLD | NEW |