| 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) | |
| 10 #include <windows.h> | |
| 11 #endif | |
| 12 | 9 |
| 13 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
| 14 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 15 #endif | 12 #endif |
| 16 | 13 |
| 17 #include <string> | 14 #include <string> |
| 18 | 15 |
| 19 #include "base/base_export.h" | 16 #include "base/base_export.h" |
| 20 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 21 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 22 #include "base/files/file_tracing.h" | 19 #include "base/files/file_tracing.h" |
| 23 #include "base/files/scoped_file.h" | 20 #include "base/files/scoped_file.h" |
| 24 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| 25 #include "base/move.h" | 22 #include "base/move.h" |
| 26 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 27 | 24 |
| 28 #if defined(OS_WIN) | |
| 29 #include "base/win/scoped_handle.h" | |
| 30 #endif | |
| 31 | |
| 32 FORWARD_DECLARE_TEST(FileTest, MemoryCorruption); | 25 FORWARD_DECLARE_TEST(FileTest, MemoryCorruption); |
| 33 | 26 |
| 34 namespace base { | 27 namespace base { |
| 35 | 28 |
| 36 #if defined(OS_WIN) | 29 #if defined(OS_POSIX) |
| 37 typedef HANDLE PlatformFile; | |
| 38 #elif defined(OS_POSIX) | |
| 39 typedef int PlatformFile; | 30 typedef int PlatformFile; |
| 40 | 31 |
| 41 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) | 32 #if defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL) |
| 42 typedef struct stat stat_wrapper_t; | 33 typedef struct stat stat_wrapper_t; |
| 43 #else | 34 #else |
| 44 typedef struct stat64 stat_wrapper_t; | 35 typedef struct stat64 stat_wrapper_t; |
| 45 #endif | 36 #endif |
| 46 #endif // defined(OS_POSIX) | 37 #endif // defined(OS_POSIX) |
| 47 | 38 |
| 48 // Thin wrapper around an OS-level file. | 39 // Thin wrapper around an OS-level file. |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 277 |
| 287 // Returns a new object referencing this file for use within the current | 278 // Returns a new object referencing this file for use within the current |
| 288 // process. Handling of FLAG_DELETE_ON_CLOSE varies by OS. On POSIX, the File | 279 // process. Handling of FLAG_DELETE_ON_CLOSE varies by OS. On POSIX, the File |
| 289 // object that was created or initialized with this flag will have unlinked | 280 // object that was created or initialized with this flag will have unlinked |
| 290 // the underlying file when it was created or opened. On Windows, the | 281 // the underlying file when it was created or opened. On Windows, the |
| 291 // underlying file is deleted when the last handle to it is closed. | 282 // underlying file is deleted when the last handle to it is closed. |
| 292 File Duplicate(); | 283 File Duplicate(); |
| 293 | 284 |
| 294 bool async() const { return async_; } | 285 bool async() const { return async_; } |
| 295 | 286 |
| 296 #if defined(OS_WIN) | |
| 297 static Error OSErrorToFileError(DWORD last_error); | |
| 298 #elif defined(OS_POSIX) | |
| 299 static Error OSErrorToFileError(int saved_errno); | 287 static Error OSErrorToFileError(int saved_errno); |
| 300 #endif | |
| 301 | 288 |
| 302 // Converts an error value to a human-readable form. Used for logging. | 289 // Converts an error value to a human-readable form. Used for logging. |
| 303 static std::string ErrorToString(Error error); | 290 static std::string ErrorToString(Error error); |
| 304 | 291 |
| 305 private: | 292 private: |
| 306 FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption); | 293 FRIEND_TEST_ALL_PREFIXES(::FileTest, MemoryCorruption); |
| 307 | 294 |
| 308 friend class FileTracing::ScopedTrace; | 295 friend class FileTracing::ScopedTrace; |
| 309 | 296 |
| 310 #if defined(OS_POSIX) | 297 #if defined(OS_POSIX) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // Creates or opens the given file. Only called if |path_| has no | 342 // Creates or opens the given file. Only called if |path_| has no |
| 356 // traversal ('..') components. | 343 // traversal ('..') components. |
| 357 void DoInitialize(uint32 flags); | 344 void DoInitialize(uint32 flags); |
| 358 | 345 |
| 359 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore, | 346 // TODO(tnagel): Reintegrate into Flush() once histogram isn't needed anymore, |
| 360 // cf. issue 473337. | 347 // cf. issue 473337. |
| 361 bool DoFlush(); | 348 bool DoFlush(); |
| 362 | 349 |
| 363 void SetPlatformFile(PlatformFile file); | 350 void SetPlatformFile(PlatformFile file); |
| 364 | 351 |
| 365 #if defined(OS_WIN) | |
| 366 win::ScopedHandle file_; | |
| 367 #elif defined(OS_POSIX) | |
| 368 MemoryCheckingScopedFD file_; | 352 MemoryCheckingScopedFD file_; |
| 369 #endif | |
| 370 | 353 |
| 371 // Path that |Initialize()| was called with. Only set if safe (i.e. no '..'). | 354 // Path that |Initialize()| was called with. Only set if safe (i.e. no '..'). |
| 372 FilePath path_; | 355 FilePath path_; |
| 373 | 356 |
| 374 // Object tied to the lifetime of |this| that enables/disables tracing. | 357 // Object tied to the lifetime of |this| that enables/disables tracing. |
| 375 FileTracing::ScopedEnabler trace_enabler_; | 358 FileTracing::ScopedEnabler trace_enabler_; |
| 376 | 359 |
| 377 Error error_details_; | 360 Error error_details_; |
| 378 bool created_; | 361 bool created_; |
| 379 bool async_; | 362 bool async_; |
| 380 }; | 363 }; |
| 381 | 364 |
| 382 } // namespace base | 365 } // namespace base |
| 383 | 366 |
| 384 #endif // BASE_FILES_FILE_H_ | 367 #endif // BASE_FILES_FILE_H_ |
| OLD | NEW |