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 BASE_FILES_FILE_H_ | 5 #ifndef BASE_FILES_FILE_H_ |
6 #define BASE_FILES_FILE_H_ | 6 #define BASE_FILES_FILE_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 int64 size; | 143 int64 size; |
144 | 144 |
145 // True if the file corresponds to a directory. | 145 // True if the file corresponds to a directory. |
146 bool is_directory; | 146 bool is_directory; |
147 | 147 |
148 // True if the file corresponds to a symbolic link. For Windows currently | 148 // True if the file corresponds to a symbolic link. For Windows currently |
149 // not supported and thus always false. | 149 // not supported and thus always false. |
150 bool is_symbolic_link; | 150 bool is_symbolic_link; |
151 | 151 |
152 // The last modified time of a file. | 152 // The last modified time of a file. |
153 base::Time last_modified; | 153 Time last_modified; |
154 | 154 |
155 // The last accessed time of a file. | 155 // The last accessed time of a file. |
156 base::Time last_accessed; | 156 Time last_accessed; |
157 | 157 |
158 // The creation time of a file. | 158 // The creation time of a file. |
159 base::Time creation_time; | 159 Time creation_time; |
160 }; | 160 }; |
161 | 161 |
162 File(); | 162 File(); |
163 | 163 |
164 // Creates or opens the given file. This will fail with 'access denied' if the | 164 // Creates or opens the given file. This will fail with 'access denied' if the |
165 // |name| contains path traversal ('..') components. | 165 // |name| contains path traversal ('..') components. |
166 File(const FilePath& name, uint32 flags); | 166 File(const FilePath& name, uint32 flags); |
167 | 167 |
168 // Takes ownership of |platform_file|. | 168 // Takes ownership of |platform_file|. |
169 explicit File(PlatformFile platform_file); | 169 explicit File(PlatformFile platform_file); |
170 | 170 |
171 // Creates an object with a specific error_details code. | 171 // Creates an object with a specific error_details code. |
172 explicit File(Error error_details); | 172 explicit File(Error error_details); |
173 | 173 |
174 // Move constructor for C++03 move emulation of this type. | 174 // Move constructor for C++03 move emulation of this type. |
175 File(RValue other); | 175 File(RValue other); |
176 | 176 |
177 ~File(); | 177 ~File(); |
178 | 178 |
179 // Move operator= for C++03 move emulation of this type. | 179 // Move operator= for C++03 move emulation of this type. |
180 File& operator=(RValue other); | 180 File& operator=(RValue other); |
181 | 181 |
182 // Creates or opens the given file. | 182 // Creates or opens the given file. |
183 void Initialize(const FilePath& name, uint32 flags); | 183 void Initialize(const FilePath& name, uint32 flags); |
184 | 184 |
185 // Creates or opens the given file, allowing paths with traversal ('..') | |
186 // components. Use only with extreme care. | |
187 void InitializeUnsafe(const FilePath& name, uint32 flags); | |
188 | |
189 bool IsValid() const; | 185 bool IsValid() const; |
190 | 186 |
191 // Returns true if a new file was created (or an old one truncated to zero | 187 // Returns true if a new file was created (or an old one truncated to zero |
192 // length to simulate a new file, which can happen with | 188 // length to simulate a new file, which can happen with |
193 // FLAG_CREATE_ALWAYS), and false otherwise. | 189 // FLAG_CREATE_ALWAYS), and false otherwise. |
194 bool created() const { return created_; } | 190 bool created() const { return created_; } |
195 | 191 |
196 // Returns the OS result of opening this file. Note that the way to verify | 192 // Returns the OS result of opening this file. Note that the way to verify |
197 // the success of the operation is to use IsValid(), not this method: | 193 // the success of the operation is to use IsValid(), not this method: |
198 // File file(name, flags); | 194 // File file(name, flags); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // failing a CHECK if they do not. | 343 // failing a CHECK if they do not. |
348 void Check() const; | 344 void Check() const; |
349 | 345 |
350 void UpdateChecksum(); | 346 void UpdateChecksum(); |
351 | 347 |
352 ScopedFD file_; | 348 ScopedFD file_; |
353 unsigned int file_memory_checksum_; | 349 unsigned int file_memory_checksum_; |
354 }; | 350 }; |
355 #endif | 351 #endif |
356 | 352 |
| 353 // Creates or opens the given file. Only called if |name| has no traversal |
| 354 // ('..') components. |
| 355 void DoInitialize(const FilePath& name, uint32 flags); |
| 356 |
| 357 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore, |
| 358 // cf. issue 473337. |
| 359 bool DoFlush(); |
| 360 |
357 void SetPlatformFile(PlatformFile file); | 361 void SetPlatformFile(PlatformFile file); |
358 | 362 |
359 #if defined(OS_WIN) | 363 #if defined(OS_WIN) |
360 win::ScopedHandle file_; | 364 win::ScopedHandle file_; |
361 #elif defined(OS_POSIX) | 365 #elif defined(OS_POSIX) |
362 MemoryCheckingScopedFD file_; | 366 MemoryCheckingScopedFD file_; |
363 #endif | 367 #endif |
364 | 368 |
365 Error error_details_; | 369 Error error_details_; |
366 bool created_; | 370 bool created_; |
367 bool async_; | 371 bool async_; |
368 }; | 372 }; |
369 | 373 |
370 } // namespace base | 374 } // namespace base |
371 | 375 |
372 #endif // BASE_FILES_FILE_H_ | 376 #endif // BASE_FILES_FILE_H_ |
OLD | NEW |