Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1159)

Side by Side Diff: base/files/file.h

Issue 2567383002: Add FLAG_CAN_DELETE_ON_CLOSE and DeleteOnClose for use on Windows. (Closed)
Patch Set: thakis comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/files/file_unittest.cc » ('j') | base/files/file_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, // Requests permission to delete a file
89 // via DeleteOnClose() (Windows only).
Nico 2017/01/11 15:47:18 It now describe what this does, but not when to us
grt (UTC plus 2) 2017/01/12 13:58:20 Better comments added to DeleteOnClose.
88 }; 90 };
89 91
90 // This enum has been recorded in multiple histograms. If the order of the 92 // 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 93 // fields needs to change, please ensure that those histograms are obsolete or
92 // have been moved to a different enum. 94 // have been moved to a different enum.
93 // 95 //
94 // FILE_ERROR_ACCESS_DENIED is returned when a call fails because of a 96 // FILE_ERROR_ACCESS_DENIED is returned when a call fails because of a
95 // filesystem restriction. FILE_ERROR_SECURITY is returned when a browser 97 // filesystem restriction. FILE_ERROR_SECURITY is returned when a browser
96 // policy doesn't allow the operation to be executed. 98 // policy doesn't allow the operation to be executed.
97 enum Error { 99 enum Error {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // Returns a new object referencing this file for use within the current 300 // 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 301 // 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 302 // 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 303 // 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. 304 // underlying file is deleted when the last handle to it is closed.
303 File Duplicate() const; 305 File Duplicate() const;
304 306
305 bool async() const { return async_; } 307 bool async() const { return async_; }
306 308
307 #if defined(OS_WIN) 309 #if defined(OS_WIN)
310 // Sets or clears the DeleteFile disposition on the handle. The handle must
311 // have been opened with FLAG_DELETE and must not have been opened with
312 // FLAG_DELETE_ON_CLOSE. Returns true if the disposition was set or cleared,
313 // as indicated by |delete_on_close|.
314 bool DeleteOnClose(bool delete_on_close);
315 #endif
316
317 #if defined(OS_WIN)
308 static Error OSErrorToFileError(DWORD last_error); 318 static Error OSErrorToFileError(DWORD last_error);
309 #elif defined(OS_POSIX) 319 #elif defined(OS_POSIX)
310 static Error OSErrorToFileError(int saved_errno); 320 static Error OSErrorToFileError(int saved_errno);
311 #endif 321 #endif
312 322
313 // Converts an error value to a human-readable form. Used for logging. 323 // Converts an error value to a human-readable form. Used for logging.
314 static std::string ErrorToString(Error error); 324 static std::string ErrorToString(Error error);
315 325
316 private: 326 private:
317 friend class FileTracing::ScopedTrace; 327 friend class FileTracing::ScopedTrace;
(...skipping 21 matching lines...) Expand all
339 bool created_; 349 bool created_;
340 bool async_; 350 bool async_;
341 351
342 DISALLOW_COPY_AND_ASSIGN(File); 352 DISALLOW_COPY_AND_ASSIGN(File);
343 }; 353 };
344 354
345 } // namespace base 355 } // namespace base
346 356
347 #endif // BASE_FILES_FILE_H_ 357 #endif // BASE_FILES_FILE_H_
348 358
OLDNEW
« no previous file with comments | « no previous file | base/files/file_unittest.cc » ('j') | base/files/file_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698