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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // Returns the current size of this file, or a negative number on failure. | 245 // Returns the current size of this file, or a negative number on failure. |
246 int64_t GetLength(); | 246 int64_t GetLength(); |
247 | 247 |
248 // Truncates the file to the given length. If |length| is greater than the | 248 // Truncates the file to the given length. If |length| is greater than the |
249 // current size of the file, the file is extended with zeros. If the file | 249 // current size of the file, the file is extended with zeros. If the file |
250 // doesn't exist, |false| is returned. | 250 // doesn't exist, |false| is returned. |
251 bool SetLength(int64_t length); | 251 bool SetLength(int64_t length); |
252 | 252 |
253 // Instructs the filesystem to flush the file to disk. (POSIX: fsync, Windows: | 253 // Instructs the filesystem to flush the file to disk. (POSIX: fsync, Windows: |
254 // FlushFileBuffers). | 254 // FlushFileBuffers). |
| 255 // Calling Flush() does not guarantee file integrity and thus is not a valid |
| 256 // substitute for file integrity checks and recovery codepaths for malformed |
| 257 // files. It can also be *really* slow, so avoid blocking on Flush(), |
| 258 // especially please don't block shutdown on Flush(). |
| 259 // Latency percentiles of Flush() across all platforms as of July 2016: |
| 260 // 50 % > 5 ms |
| 261 // 10 % > 58 ms |
| 262 // 1 % > 357 ms |
| 263 // 0.1 % > 1.8 seconds |
| 264 // 0.01 % > 7.6 seconds |
255 bool Flush(); | 265 bool Flush(); |
256 | 266 |
257 // Updates the file times. | 267 // Updates the file times. |
258 bool SetTimes(Time last_access_time, Time last_modified_time); | 268 bool SetTimes(Time last_access_time, Time last_modified_time); |
259 | 269 |
260 // Returns some basic information for the given file. | 270 // Returns some basic information for the given file. |
261 bool GetInfo(Info* info); | 271 bool GetInfo(Info* info); |
262 | 272 |
263 // Attempts to take an exclusive write lock on the file. Returns immediately | 273 // Attempts to take an exclusive write lock on the file. Returns immediately |
264 // (i.e. does not wait for another process to unlock the file). If the lock | 274 // (i.e. does not wait for another process to unlock the file). If the lock |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // Converts an error value to a human-readable form. Used for logging. | 313 // Converts an error value to a human-readable form. Used for logging. |
304 static std::string ErrorToString(Error error); | 314 static std::string ErrorToString(Error error); |
305 | 315 |
306 private: | 316 private: |
307 friend class FileTracing::ScopedTrace; | 317 friend class FileTracing::ScopedTrace; |
308 | 318 |
309 // Creates or opens the given file. Only called if |path| has no | 319 // Creates or opens the given file. Only called if |path| has no |
310 // traversal ('..') components. | 320 // traversal ('..') components. |
311 void DoInitialize(const FilePath& path, uint32_t flags); | 321 void DoInitialize(const FilePath& path, uint32_t flags); |
312 | 322 |
313 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore, | |
314 // cf. issue 473337. | |
315 bool DoFlush(); | |
316 | |
317 void SetPlatformFile(PlatformFile file); | 323 void SetPlatformFile(PlatformFile file); |
318 | 324 |
319 #if defined(OS_WIN) | 325 #if defined(OS_WIN) |
320 win::ScopedHandle file_; | 326 win::ScopedHandle file_; |
321 #elif defined(OS_POSIX) | 327 #elif defined(OS_POSIX) |
322 ScopedFD file_; | 328 ScopedFD file_; |
323 #endif | 329 #endif |
324 | 330 |
325 // A path to use for tracing purposes. Set if file tracing is enabled during | 331 // A path to use for tracing purposes. Set if file tracing is enabled during |
326 // |Initialize()|. | 332 // |Initialize()|. |
327 FilePath tracing_path_; | 333 FilePath tracing_path_; |
328 | 334 |
329 // Object tied to the lifetime of |this| that enables/disables tracing. | 335 // Object tied to the lifetime of |this| that enables/disables tracing. |
330 FileTracing::ScopedEnabler trace_enabler_; | 336 FileTracing::ScopedEnabler trace_enabler_; |
331 | 337 |
332 Error error_details_; | 338 Error error_details_; |
333 bool created_; | 339 bool created_; |
334 bool async_; | 340 bool async_; |
335 | 341 |
336 DISALLOW_COPY_AND_ASSIGN(File); | 342 DISALLOW_COPY_AND_ASSIGN(File); |
337 }; | 343 }; |
338 | 344 |
339 } // namespace base | 345 } // namespace base |
340 | 346 |
341 #endif // BASE_FILES_FILE_H_ | 347 #endif // BASE_FILES_FILE_H_ |
342 | 348 |
OLD | NEW |