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 #include "base/files/file.h" | 5 #include "base/files/file.h" |
6 | 6 |
7 #include <io.h> | 7 #include <io.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 DUPLICATE_SAME_ACCESS)) { | 266 DUPLICATE_SAME_ACCESS)) { |
267 return File(OSErrorToFileError(GetLastError())); | 267 return File(OSErrorToFileError(GetLastError())); |
268 } | 268 } |
269 | 269 |
270 File other(other_handle); | 270 File other(other_handle); |
271 if (async()) | 271 if (async()) |
272 other.async_ = true; | 272 other.async_ = true; |
273 return other; | 273 return other; |
274 } | 274 } |
275 | 275 |
| 276 bool File::DeleteOnClose(bool delete_on_close) { |
| 277 FILE_DISPOSITION_INFO disposition = {delete_on_close ? TRUE : FALSE}; |
| 278 return ::SetFileInformationByHandle(GetPlatformFile(), FileDispositionInfo, |
| 279 &disposition, sizeof(disposition)) != 0; |
| 280 } |
| 281 |
276 // Static. | 282 // Static. |
277 File::Error File::OSErrorToFileError(DWORD last_error) { | 283 File::Error File::OSErrorToFileError(DWORD last_error) { |
278 switch (last_error) { | 284 switch (last_error) { |
279 case ERROR_SHARING_VIOLATION: | 285 case ERROR_SHARING_VIOLATION: |
280 return FILE_ERROR_IN_USE; | 286 return FILE_ERROR_IN_USE; |
281 case ERROR_FILE_EXISTS: | 287 case ERROR_FILE_EXISTS: |
282 return FILE_ERROR_EXISTS; | 288 return FILE_ERROR_EXISTS; |
283 case ERROR_FILE_NOT_FOUND: | 289 case ERROR_FILE_NOT_FOUND: |
284 case ERROR_PATH_NOT_FOUND: | 290 case ERROR_PATH_NOT_FOUND: |
285 return FILE_ERROR_NOT_FOUND; | 291 return FILE_ERROR_NOT_FOUND; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (flags & FLAG_APPEND) { | 358 if (flags & FLAG_APPEND) { |
353 DCHECK(!access); | 359 DCHECK(!access); |
354 access = FILE_APPEND_DATA; | 360 access = FILE_APPEND_DATA; |
355 } | 361 } |
356 if (flags & FLAG_READ) | 362 if (flags & FLAG_READ) |
357 access |= GENERIC_READ; | 363 access |= GENERIC_READ; |
358 if (flags & FLAG_WRITE_ATTRIBUTES) | 364 if (flags & FLAG_WRITE_ATTRIBUTES) |
359 access |= FILE_WRITE_ATTRIBUTES; | 365 access |= FILE_WRITE_ATTRIBUTES; |
360 if (flags & FLAG_EXECUTE) | 366 if (flags & FLAG_EXECUTE) |
361 access |= GENERIC_EXECUTE; | 367 access |= GENERIC_EXECUTE; |
| 368 if (flags & FLAG_CAN_DELETE_ON_CLOSE) |
| 369 access |= DELETE; |
362 | 370 |
363 DWORD sharing = (flags & FLAG_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; | 371 DWORD sharing = (flags & FLAG_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; |
364 if (!(flags & FLAG_EXCLUSIVE_WRITE)) | 372 if (!(flags & FLAG_EXCLUSIVE_WRITE)) |
365 sharing |= FILE_SHARE_WRITE; | 373 sharing |= FILE_SHARE_WRITE; |
366 if (flags & FLAG_SHARE_DELETE) | 374 if (flags & FLAG_SHARE_DELETE) |
367 sharing |= FILE_SHARE_DELETE; | 375 sharing |= FILE_SHARE_DELETE; |
368 | 376 |
369 DWORD create_flags = 0; | 377 DWORD create_flags = 0; |
370 if (flags & FLAG_ASYNC) | 378 if (flags & FLAG_ASYNC) |
371 create_flags |= FILE_FLAG_OVERLAPPED; | 379 create_flags |= FILE_FLAG_OVERLAPPED; |
(...skipping 29 matching lines...) Expand all Loading... |
401 DCHECK(IsValid()); | 409 DCHECK(IsValid()); |
402 SCOPED_FILE_TRACE("Flush"); | 410 SCOPED_FILE_TRACE("Flush"); |
403 return ::FlushFileBuffers(file_.Get()) != FALSE; | 411 return ::FlushFileBuffers(file_.Get()) != FALSE; |
404 } | 412 } |
405 | 413 |
406 void File::SetPlatformFile(PlatformFile file) { | 414 void File::SetPlatformFile(PlatformFile file) { |
407 file_.Set(file); | 415 file_.Set(file); |
408 } | 416 } |
409 | 417 |
410 } // namespace base | 418 } // namespace base |
OLD | NEW |