Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 class BASE_EXPORT File { | 56 class BASE_EXPORT File { |
| 57 public: | 57 public: |
| 58 // FLAG_(OPEN|CREATE).* are mutually exclusive. You should specify exactly one | 58 // FLAG_(OPEN|CREATE).* are mutually exclusive. You should specify exactly one |
| 59 // of the five (possibly combining with other flags) when opening or creating | 59 // of the five (possibly combining with other flags) when opening or creating |
| 60 // a file. | 60 // a file. |
| 61 // FLAG_(WRITE|APPEND) are mutually exclusive. This is so that APPEND behavior | 61 // FLAG_(WRITE|APPEND) are mutually exclusive. This is so that APPEND behavior |
| 62 // will be consistent with O_APPEND on POSIX. | 62 // will be consistent with O_APPEND on POSIX. |
| 63 // FLAG_EXCLUSIVE_(READ|WRITE) only grant exclusive access to the file on | 63 // FLAG_EXCLUSIVE_(READ|WRITE) only grant exclusive access to the file on |
| 64 // creation on POSIX; for existing files, consider using Lock(). | 64 // creation on POSIX; for existing files, consider using Lock(). |
| 65 enum Flags { | 65 enum Flags { |
| 66 FLAG_OPEN = 1 << 0, // Opens a file, only if it exists. | 66 FLAG_OPEN = 1 << 0, // Opens a file, only if it exists. |
| 67 FLAG_CREATE = 1 << 1, // Creates a new file, only if it does not | 67 FLAG_CREATE = 1 << 1, // Creates a new file, only if it does not |
| 68 // already exist. | 68 // already exist. |
| 69 FLAG_OPEN_ALWAYS = 1 << 2, // May create a new file. | 69 FLAG_OPEN_ALWAYS = 1 << 2, // May create a new file. |
| 70 FLAG_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. | 70 FLAG_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. |
| 71 FLAG_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, only if it | 71 FLAG_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, only if it |
| 72 // exists. | 72 // exists. |
| 73 FLAG_READ = 1 << 5, | 73 FLAG_READ = 1 << 5, |
| 74 FLAG_WRITE = 1 << 6, | 74 FLAG_WRITE = 1 << 6, |
| 75 FLAG_APPEND = 1 << 7, | 75 FLAG_APPEND = 1 << 7, |
| 76 FLAG_EXCLUSIVE_READ = 1 << 8, // EXCLUSIVE is opposite of Windows SHARE. | 76 FLAG_EXCLUSIVE_READ = 1 << 8, // EXCLUSIVE is opposite of Windows SHARE. |
| 77 FLAG_EXCLUSIVE_WRITE = 1 << 9, | 77 FLAG_EXCLUSIVE_WRITE = 1 << 9, |
| 78 FLAG_ASYNC = 1 << 10, | 78 FLAG_ASYNC = 1 << 10, |
| 79 FLAG_TEMPORARY = 1 << 11, // Used on Windows only. | 79 FLAG_TEMPORARY = 1 << 11, // Used on Windows only. |
| 80 FLAG_HIDDEN = 1 << 12, // Used on Windows only. | 80 FLAG_HIDDEN = 1 << 12, // Used on Windows only. |
| 81 FLAG_DELETE_ON_CLOSE = 1 << 13, | 81 FLAG_DELETE_ON_CLOSE = 1 << 13, |
| 82 FLAG_WRITE_ATTRIBUTES = 1 << 14, // Used on Windows only. | 82 FLAG_WRITE_ATTRIBUTES = 1 << 14, // Used on Windows only. |
| 83 FLAG_SHARE_DELETE = 1 << 15, // Used on Windows only. | 83 FLAG_SHARE_DELETE = 1 << 15, // Used on Windows only. |
| 84 FLAG_TERMINAL_DEVICE = 1 << 16, // Serial port flags. | 84 FLAG_TERMINAL_DEVICE = 1 << 16, // Serial port flags. |
| 85 FLAG_BACKUP_SEMANTICS = 1 << 17, // Used on Windows only. | 85 FLAG_BACKUP_SEMANTICS = 1 << 17, // Used on Windows only. |
| 86 FLAG_EXECUTE = 1 << 18, // Used on Windows only. | 86 FLAG_EXECUTE = 1 << 18, // Used on Windows only. |
| 87 FLAG_SEQUENTIAL_SCAN = 1 << 19, // Used on Windows only. | 87 FLAG_SEQUENTIAL_SCAN = 1 << 19, // Used on Windows only. |
| 88 FLAG_DELETE = 1 << 20, // Used on Windows only. | |
|
Nico
2017/01/10 18:04:15
Maybe this could describe what this does, and when
grt (UTC plus 2)
2017/01/11 13:52:17
Done.
| |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 // This enum has been recorded in multiple histograms. If the order of the | 91 // This enum has been recorded in multiple histograms. If the order of the |
| 91 // fields needs to change, please ensure that those histograms are obsolete or | 92 // fields needs to change, please ensure that those histograms are obsolete or |
| 92 // have been moved to a different enum. | 93 // have been moved to a different enum. |
| 93 // | 94 // |
| 94 // FILE_ERROR_ACCESS_DENIED is returned when a call fails because of a | 95 // FILE_ERROR_ACCESS_DENIED is returned when a call fails because of a |
| 95 // filesystem restriction. FILE_ERROR_SECURITY is returned when a browser | 96 // filesystem restriction. FILE_ERROR_SECURITY is returned when a browser |
| 96 // policy doesn't allow the operation to be executed. | 97 // policy doesn't allow the operation to be executed. |
| 97 enum Error { | 98 enum Error { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // Returns a new object referencing this file for use within the current | 299 // Returns a new object referencing this file for use within the current |
| 299 // process. Handling of FLAG_DELETE_ON_CLOSE varies by OS. On POSIX, the File | 300 // process. Handling of FLAG_DELETE_ON_CLOSE varies by OS. On POSIX, the File |
| 300 // object that was created or initialized with this flag will have unlinked | 301 // object that was created or initialized with this flag will have unlinked |
| 301 // the underlying file when it was created or opened. On Windows, the | 302 // the underlying file when it was created or opened. On Windows, the |
| 302 // underlying file is deleted when the last handle to it is closed. | 303 // underlying file is deleted when the last handle to it is closed. |
| 303 File Duplicate() const; | 304 File Duplicate() const; |
| 304 | 305 |
| 305 bool async() const { return async_; } | 306 bool async() const { return async_; } |
| 306 | 307 |
| 307 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
| 309 // Sets or clears the DeleteFile disposition on the handle. The handle must | |
| 310 // have been opened with FLAG_DELETE and must not have been opened with | |
| 311 // FLAG_DELETE_ON_CLOSE. Returns true if the disposition was set or cleared, | |
| 312 // as indicated by |delete_on_close|. | |
| 313 bool DeleteOnClose(bool delete_on_close); | |
| 314 #endif | |
| 315 | |
| 316 #if defined(OS_WIN) | |
| 308 static Error OSErrorToFileError(DWORD last_error); | 317 static Error OSErrorToFileError(DWORD last_error); |
| 309 #elif defined(OS_POSIX) | 318 #elif defined(OS_POSIX) |
| 310 static Error OSErrorToFileError(int saved_errno); | 319 static Error OSErrorToFileError(int saved_errno); |
| 311 #endif | 320 #endif |
| 312 | 321 |
| 313 // Converts an error value to a human-readable form. Used for logging. | 322 // Converts an error value to a human-readable form. Used for logging. |
| 314 static std::string ErrorToString(Error error); | 323 static std::string ErrorToString(Error error); |
| 315 | 324 |
| 316 private: | 325 private: |
| 317 friend class FileTracing::ScopedTrace; | 326 friend class FileTracing::ScopedTrace; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 339 bool created_; | 348 bool created_; |
| 340 bool async_; | 349 bool async_; |
| 341 | 350 |
| 342 DISALLOW_COPY_AND_ASSIGN(File); | 351 DISALLOW_COPY_AND_ASSIGN(File); |
| 343 }; | 352 }; |
| 344 | 353 |
| 345 } // namespace base | 354 } // namespace base |
| 346 | 355 |
| 347 #endif // BASE_FILES_FILE_H_ | 356 #endif // BASE_FILES_FILE_H_ |
| 348 | 357 |
| OLD | NEW |