| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 case ERROR_FILE_CORRUPT: | 301 case ERROR_FILE_CORRUPT: |
| 302 case ERROR_DISK_CORRUPT: | 302 case ERROR_DISK_CORRUPT: |
| 303 return FILE_ERROR_IO; | 303 return FILE_ERROR_IO; |
| 304 default: | 304 default: |
| 305 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", | 305 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", |
| 306 last_error); | 306 last_error); |
| 307 return FILE_ERROR_FAILED; | 307 return FILE_ERROR_FAILED; |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 | 310 |
| 311 void File::DoInitialize(uint32 flags) { | 311 void File::DoInitialize(const FilePath& path, uint32 flags) { |
| 312 ThreadRestrictions::AssertIOAllowed(); | 312 ThreadRestrictions::AssertIOAllowed(); |
| 313 DCHECK(!IsValid()); | 313 DCHECK(!IsValid()); |
| 314 | 314 |
| 315 DWORD disposition = 0; | 315 DWORD disposition = 0; |
| 316 | 316 |
| 317 if (flags & FLAG_OPEN) | 317 if (flags & FLAG_OPEN) |
| 318 disposition = OPEN_EXISTING; | 318 disposition = OPEN_EXISTING; |
| 319 | 319 |
| 320 if (flags & FLAG_CREATE) { | 320 if (flags & FLAG_CREATE) { |
| 321 DCHECK(!disposition); | 321 DCHECK(!disposition); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 create_flags |= FILE_FLAG_OVERLAPPED; | 369 create_flags |= FILE_FLAG_OVERLAPPED; |
| 370 if (flags & FLAG_TEMPORARY) | 370 if (flags & FLAG_TEMPORARY) |
| 371 create_flags |= FILE_ATTRIBUTE_TEMPORARY; | 371 create_flags |= FILE_ATTRIBUTE_TEMPORARY; |
| 372 if (flags & FLAG_HIDDEN) | 372 if (flags & FLAG_HIDDEN) |
| 373 create_flags |= FILE_ATTRIBUTE_HIDDEN; | 373 create_flags |= FILE_ATTRIBUTE_HIDDEN; |
| 374 if (flags & FLAG_DELETE_ON_CLOSE) | 374 if (flags & FLAG_DELETE_ON_CLOSE) |
| 375 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; | 375 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; |
| 376 if (flags & FLAG_BACKUP_SEMANTICS) | 376 if (flags & FLAG_BACKUP_SEMANTICS) |
| 377 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; | 377 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; |
| 378 | 378 |
| 379 file_.Set(CreateFile(path_.value().c_str(), access, sharing, NULL, | 379 file_.Set(CreateFile(path.value().c_str(), access, sharing, NULL, disposition, |
| 380 disposition, create_flags, NULL)); | 380 create_flags, NULL)); |
| 381 | 381 |
| 382 if (file_.IsValid()) { | 382 if (file_.IsValid()) { |
| 383 error_details_ = FILE_OK; | 383 error_details_ = FILE_OK; |
| 384 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); | 384 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
| 385 | 385 |
| 386 if (flags & (FLAG_OPEN_ALWAYS)) | 386 if (flags & (FLAG_OPEN_ALWAYS)) |
| 387 created_ = (ERROR_ALREADY_EXISTS != GetLastError()); | 387 created_ = (ERROR_ALREADY_EXISTS != GetLastError()); |
| 388 else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) | 388 else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
| 389 created_ = true; | 389 created_ = true; |
| 390 } else { | 390 } else { |
| 391 error_details_ = OSErrorToFileError(GetLastError()); | 391 error_details_ = OSErrorToFileError(GetLastError()); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool File::DoFlush() { | 395 bool File::DoFlush() { |
| 396 ThreadRestrictions::AssertIOAllowed(); | 396 ThreadRestrictions::AssertIOAllowed(); |
| 397 DCHECK(IsValid()); | 397 DCHECK(IsValid()); |
| 398 return ::FlushFileBuffers(file_.Get()) != FALSE; | 398 return ::FlushFileBuffers(file_.Get()) != FALSE; |
| 399 } | 399 } |
| 400 | 400 |
| 401 void File::SetPlatformFile(PlatformFile file) { | 401 void File::SetPlatformFile(PlatformFile file) { |
| 402 file_.Set(file); | 402 file_.Set(file); |
| 403 } | 403 } |
| 404 | 404 |
| 405 } // namespace base | 405 } // namespace base |
| OLD | NEW |