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_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util_proxy.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
12 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
13 #include "webkit/fileapi/file_system_url.h" | 11 #include "webkit/fileapi/file_system_url.h" |
14 #include "webkit/storage/webkit_storage_export.h" | 12 #include "webkit/storage/webkit_storage_export.h" |
15 | 13 |
16 namespace base { | 14 namespace base { |
17 class Time; | 15 class Time; |
18 } | 16 } |
19 | 17 |
20 namespace webkit_blob { | 18 namespace webkit_blob { |
21 class ShareableFileReference; | 19 class ShareableFileReference; |
22 } | 20 } |
23 | 21 |
24 namespace fileapi { | 22 namespace fileapi { |
25 | 23 |
26 using base::PlatformFile; | |
27 using base::PlatformFileError; | |
28 class FileSystemOperationContext; | 24 class FileSystemOperationContext; |
29 | 25 |
30 // A file utility interface that provides basic file utility methods for | 26 // A file utility interface that provides basic file utility methods for |
31 // FileSystem API. | 27 // FileSystem API. |
32 // | 28 // |
33 // Layering structure of the FileSystemFileUtil was split out. | 29 // Layering structure of the FileSystemFileUtil was split out. |
34 // See http://crbug.com/128136 if you need it. | 30 // See http://crbug.com/128136 if you need it. |
35 class WEBKIT_STORAGE_EXPORT FileSystemFileUtil { | 31 class WEBKIT_STORAGE_EXPORT FileSystemFileUtil { |
36 public: | 32 public: |
37 // It will be implemented by each subclass such as FileSystemFileEnumerator. | 33 // It will be implemented by each subclass such as FileSystemFileEnumerator. |
(...skipping 29 matching lines...) Expand all Loading... |
67 virtual base::Time LastModifiedTime() OVERRIDE; | 63 virtual base::Time LastModifiedTime() OVERRIDE; |
68 virtual bool IsDirectory() OVERRIDE; | 64 virtual bool IsDirectory() OVERRIDE; |
69 }; | 65 }; |
70 | 66 |
71 virtual ~FileSystemFileUtil() {} | 67 virtual ~FileSystemFileUtil() {} |
72 | 68 |
73 // Creates or opens a file with the given flags. | 69 // Creates or opens a file with the given flags. |
74 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 70 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
75 // a new file at the given |url| and calls back with | 71 // a new file at the given |url| and calls back with |
76 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. | 72 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. |
77 virtual PlatformFileError CreateOrOpen( | 73 virtual base::PlatformFileError CreateOrOpen( |
78 FileSystemOperationContext* context, | 74 FileSystemOperationContext* context, |
79 const FileSystemURL& url, | 75 const FileSystemURL& url, |
80 int file_flags, | 76 int file_flags, |
81 PlatformFile* file_handle, | 77 base::PlatformFile* file_handle, |
82 bool* created) = 0; | 78 bool* created) = 0; |
83 | 79 |
84 // Closes the given file handle. | 80 // Closes the given file handle. |
85 virtual PlatformFileError Close( | 81 virtual base::PlatformFileError Close( |
86 FileSystemOperationContext* context, | 82 FileSystemOperationContext* context, |
87 PlatformFile file) = 0; | 83 base::PlatformFile file) = 0; |
88 | 84 |
89 // Ensures that the given |url| exist. This creates a empty new file | 85 // Ensures that the given |url| exist. This creates a empty new file |
90 // at |url| if the |url| does not exist. | 86 // at |url| if the |url| does not exist. |
91 // If a new file han not existed and is created at the |url|, | 87 // If a new file han not existed and is created at the |url|, |
92 // |created| is set true and |error code| | 88 // |created| is set true and |error code| |
93 // is set PLATFORM_FILE_OK. | 89 // is set PLATFORM_FILE_OK. |
94 // If the file already exists, |created| is set false and |error code| | 90 // If the file already exists, |created| is set false and |error code| |
95 // is set PLATFORM_FILE_OK. | 91 // is set PLATFORM_FILE_OK. |
96 // If the file hasn't existed but it couldn't be created for some other | 92 // If the file hasn't existed but it couldn't be created for some other |
97 // reasons, |created| is set false and |error code| indicates the error. | 93 // reasons, |created| is set false and |error code| indicates the error. |
98 virtual PlatformFileError EnsureFileExists( | 94 virtual base::PlatformFileError EnsureFileExists( |
99 FileSystemOperationContext* context, | 95 FileSystemOperationContext* context, |
100 const FileSystemURL& url, bool* created) = 0; | 96 const FileSystemURL& url, bool* created) = 0; |
101 | 97 |
102 // Creates directory at given url. It's an error to create | 98 // Creates directory at given url. It's an error to create |
103 // if |exclusive| is true and dir already exists. | 99 // if |exclusive| is true and dir already exists. |
104 virtual PlatformFileError CreateDirectory( | 100 virtual base::PlatformFileError CreateDirectory( |
105 FileSystemOperationContext* context, | 101 FileSystemOperationContext* context, |
106 const FileSystemURL& url, | 102 const FileSystemURL& url, |
107 bool exclusive, | 103 bool exclusive, |
108 bool recursive) = 0; | 104 bool recursive) = 0; |
109 | 105 |
110 // Retrieves the information about a file. | 106 // Retrieves the information about a file. |
111 virtual PlatformFileError GetFileInfo( | 107 virtual base::PlatformFileError GetFileInfo( |
112 FileSystemOperationContext* context, | 108 FileSystemOperationContext* context, |
113 const FileSystemURL& url, | 109 const FileSystemURL& url, |
114 base::PlatformFileInfo* file_info, | 110 base::PlatformFileInfo* file_info, |
115 FilePath* platform_path) = 0; | 111 FilePath* platform_path) = 0; |
116 | 112 |
117 // Returns a pointer to a new instance of AbstractFileEnumerator which is | 113 // Returns a pointer to a new instance of AbstractFileEnumerator which is |
118 // implemented for each FileSystemFileUtil subclass. The instance needs to be | 114 // implemented for each FileSystemFileUtil subclass. The instance needs to be |
119 // freed by the caller, and its lifetime should not extend past when the | 115 // freed by the caller, and its lifetime should not extend past when the |
120 // current call returns to the main FILE message loop. | 116 // current call returns to the main FILE message loop. |
121 // | 117 // |
122 // The supplied context must remain valid at least lifetime of the enumerator | 118 // The supplied context must remain valid at least lifetime of the enumerator |
123 // instance. | 119 // instance. |
124 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 120 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
125 FileSystemOperationContext* context, | 121 FileSystemOperationContext* context, |
126 const FileSystemURL& root_url, | 122 const FileSystemURL& root_url, |
127 bool recursive) = 0; | 123 bool recursive) = 0; |
128 | 124 |
129 // Maps |file_system_url| given |context| into |local_file_path| | 125 // Maps |file_system_url| given |context| into |local_file_path| |
130 // which represents physical file location on the host OS. | 126 // which represents physical file location on the host OS. |
131 // This may not always make sense for all subclasses. | 127 // This may not always make sense for all subclasses. |
132 virtual PlatformFileError GetLocalFilePath( | 128 virtual base::PlatformFileError GetLocalFilePath( |
133 FileSystemOperationContext* context, | 129 FileSystemOperationContext* context, |
134 const FileSystemURL& file_system_url, | 130 const FileSystemURL& file_system_url, |
135 FilePath* local_file_path) = 0; | 131 FilePath* local_file_path) = 0; |
136 | 132 |
137 // Updates the file metadata information. Unlike posix's touch, it does | 133 // Updates the file metadata information. Unlike posix's touch, it does |
138 // not create a file even if |url| does not exist, but instead fails | 134 // not create a file even if |url| does not exist, but instead fails |
139 // with PLATFORM_FILE_ERROR_NOT_FOUND. | 135 // with PLATFORM_FILE_ERROR_NOT_FOUND. |
140 virtual PlatformFileError Touch( | 136 virtual base::PlatformFileError Touch( |
141 FileSystemOperationContext* context, | 137 FileSystemOperationContext* context, |
142 const FileSystemURL& url, | 138 const FileSystemURL& url, |
143 const base::Time& last_access_time, | 139 const base::Time& last_access_time, |
144 const base::Time& last_modified_time) = 0; | 140 const base::Time& last_modified_time) = 0; |
145 | 141 |
146 // Truncates a file to the given length. If |length| is greater than the | 142 // Truncates a file to the given length. If |length| is greater than the |
147 // current length of the file, the file will be extended with zeroes. | 143 // current length of the file, the file will be extended with zeroes. |
148 virtual PlatformFileError Truncate( | 144 virtual base::PlatformFileError Truncate( |
149 FileSystemOperationContext* context, | 145 FileSystemOperationContext* context, |
150 const FileSystemURL& url, | 146 const FileSystemURL& url, |
151 int64 length) = 0; | 147 int64 length) = 0; |
152 | 148 |
153 // Returns true if a given |url| is an empty directory. | 149 // Returns true if a given |url| is an empty directory. |
154 virtual bool IsDirectoryEmpty( | 150 virtual bool IsDirectoryEmpty( |
155 FileSystemOperationContext* context, | 151 FileSystemOperationContext* context, |
156 const FileSystemURL& url) = 0; | 152 const FileSystemURL& url) = 0; |
157 | 153 |
158 // Copies or moves a single file from |src_url| to |dest_url|. | 154 // Copies or moves a single file from |src_url| to |dest_url|. |
159 virtual PlatformFileError CopyOrMoveFile( | 155 virtual base::PlatformFileError CopyOrMoveFile( |
160 FileSystemOperationContext* context, | 156 FileSystemOperationContext* context, |
161 const FileSystemURL& src_url, | 157 const FileSystemURL& src_url, |
162 const FileSystemURL& dest_url, | 158 const FileSystemURL& dest_url, |
163 bool copy) = 0; | 159 bool copy) = 0; |
164 | 160 |
165 // Copies in a single file from a different filesystem. | 161 // Copies in a single file from a different filesystem. |
166 virtual PlatformFileError CopyInForeignFile( | 162 virtual base::PlatformFileError CopyInForeignFile( |
167 FileSystemOperationContext* context, | 163 FileSystemOperationContext* context, |
168 const FilePath& src_file_path, | 164 const FilePath& src_file_path, |
169 const FileSystemURL& dest_url) = 0; | 165 const FileSystemURL& dest_url) = 0; |
170 | 166 |
171 // Deletes a single file. | 167 // Deletes a single file. |
172 // It assumes the given url points a file. | 168 // It assumes the given url points a file. |
173 virtual PlatformFileError DeleteFile( | 169 virtual base::PlatformFileError DeleteFile( |
174 FileSystemOperationContext* context, | 170 FileSystemOperationContext* context, |
175 const FileSystemURL& url) = 0; | 171 const FileSystemURL& url) = 0; |
176 | 172 |
177 // Deletes a single empty directory. | 173 // Deletes a single empty directory. |
178 // It assumes the given url points an empty directory. | 174 // It assumes the given url points an empty directory. |
179 virtual PlatformFileError DeleteSingleDirectory( | 175 virtual base::PlatformFileError DeleteSingleDirectory( |
180 FileSystemOperationContext* context, | 176 FileSystemOperationContext* context, |
181 const FileSystemURL& url) = 0; | 177 const FileSystemURL& url) = 0; |
182 | 178 |
183 // Creates a local snapshot file for a given |url| and returns the | 179 // Creates a local snapshot file for a given |url| and returns the |
184 // metadata and platform path of the snapshot file via |callback|. | 180 // metadata and platform path of the snapshot file via |callback|. |
185 // In regular filesystem cases the implementation may simply return | 181 // In regular filesystem cases the implementation may simply return |
186 // the metadata of the file itself (as well as GetMetadata does), | 182 // the metadata of the file itself (as well as GetMetadata does), |
187 // while in non-regular filesystem case the backend may create a | 183 // while in non-regular filesystem case the backend may create a |
188 // temporary snapshot file which holds the file data and return | 184 // temporary snapshot file which holds the file data and return |
189 // the metadata of the temporary file. | 185 // the metadata of the temporary file. |
(...skipping 12 matching lines...) Expand all Loading... |
202 protected: | 198 protected: |
203 FileSystemFileUtil() {} | 199 FileSystemFileUtil() {} |
204 | 200 |
205 private: | 201 private: |
206 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); | 202 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
207 }; | 203 }; |
208 | 204 |
209 } // namespace fileapi | 205 } // namespace fileapi |
210 | 206 |
211 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ | 207 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
OLD | NEW |