| 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/files/file_path.h" | 9 #include "base/files/file_tracing.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 // Make sure our Whence mappings match the system headers. | 16 // Make sure our Whence mappings match the system headers. |
| 17 COMPILE_ASSERT(File::FROM_BEGIN == FILE_BEGIN && | 17 COMPILE_ASSERT(File::FROM_BEGIN == FILE_BEGIN && |
| 18 File::FROM_CURRENT == FILE_CURRENT && | 18 File::FROM_CURRENT == FILE_CURRENT && |
| 19 File::FROM_END == FILE_END, whence_matches_system); | 19 File::FROM_END == FILE_END, whence_matches_system); |
| 20 | 20 |
| 21 bool File::IsValid() const { | 21 bool File::IsValid() const { |
| 22 return file_.IsValid(); | 22 return file_.IsValid(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 PlatformFile File::GetPlatformFile() const { | 25 PlatformFile File::GetPlatformFile() const { |
| 26 return file_.Get(); | 26 return file_.Get(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 PlatformFile File::TakePlatformFile() { | 29 PlatformFile File::TakePlatformFile() { |
| 30 return file_.Take(); | 30 return file_.Take(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void File::Close() { | 33 void File::Close() { |
| 34 if (file_.IsValid()) { | 34 if (!file_.IsValid()) |
| 35 ThreadRestrictions::AssertIOAllowed(); | 35 return; |
| 36 file_.Close(); | 36 |
| 37 } | 37 ThreadRestrictions::AssertIOAllowed(); |
| 38 SCOPED_FILE_TRACE("Close"); |
| 39 file_.Close(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 int64 File::Seek(Whence whence, int64 offset) { | 42 int64 File::Seek(Whence whence, int64 offset) { |
| 41 ThreadRestrictions::AssertIOAllowed(); | 43 ThreadRestrictions::AssertIOAllowed(); |
| 42 DCHECK(IsValid()); | 44 DCHECK(IsValid()); |
| 43 | 45 |
| 46 SCOPED_FILE_TRACE_WITH_SIZE("Seek", offset); |
| 47 |
| 44 LARGE_INTEGER distance, res; | 48 LARGE_INTEGER distance, res; |
| 45 distance.QuadPart = offset; | 49 distance.QuadPart = offset; |
| 46 DWORD move_method = static_cast<DWORD>(whence); | 50 DWORD move_method = static_cast<DWORD>(whence); |
| 47 if (!SetFilePointerEx(file_.Get(), distance, &res, move_method)) | 51 if (!SetFilePointerEx(file_.Get(), distance, &res, move_method)) |
| 48 return -1; | 52 return -1; |
| 49 return res.QuadPart; | 53 return res.QuadPart; |
| 50 } | 54 } |
| 51 | 55 |
| 52 int File::Read(int64 offset, char* data, int size) { | 56 int File::Read(int64 offset, char* data, int size) { |
| 53 ThreadRestrictions::AssertIOAllowed(); | 57 ThreadRestrictions::AssertIOAllowed(); |
| 54 DCHECK(IsValid()); | 58 DCHECK(IsValid()); |
| 55 DCHECK(!async_); | 59 DCHECK(!async_); |
| 56 if (size < 0) | 60 if (size < 0) |
| 57 return -1; | 61 return -1; |
| 58 | 62 |
| 63 SCOPED_FILE_TRACE_WITH_SIZE("Read", size); |
| 64 |
| 59 LARGE_INTEGER offset_li; | 65 LARGE_INTEGER offset_li; |
| 60 offset_li.QuadPart = offset; | 66 offset_li.QuadPart = offset; |
| 61 | 67 |
| 62 OVERLAPPED overlapped = {0}; | 68 OVERLAPPED overlapped = {0}; |
| 63 overlapped.Offset = offset_li.LowPart; | 69 overlapped.Offset = offset_li.LowPart; |
| 64 overlapped.OffsetHigh = offset_li.HighPart; | 70 overlapped.OffsetHigh = offset_li.HighPart; |
| 65 | 71 |
| 66 DWORD bytes_read; | 72 DWORD bytes_read; |
| 67 if (::ReadFile(file_.Get(), data, size, &bytes_read, &overlapped)) | 73 if (::ReadFile(file_.Get(), data, size, &bytes_read, &overlapped)) |
| 68 return bytes_read; | 74 return bytes_read; |
| 69 if (ERROR_HANDLE_EOF == GetLastError()) | 75 if (ERROR_HANDLE_EOF == GetLastError()) |
| 70 return 0; | 76 return 0; |
| 71 | 77 |
| 72 return -1; | 78 return -1; |
| 73 } | 79 } |
| 74 | 80 |
| 75 int File::ReadAtCurrentPos(char* data, int size) { | 81 int File::ReadAtCurrentPos(char* data, int size) { |
| 76 ThreadRestrictions::AssertIOAllowed(); | 82 ThreadRestrictions::AssertIOAllowed(); |
| 77 DCHECK(IsValid()); | 83 DCHECK(IsValid()); |
| 78 DCHECK(!async_); | 84 DCHECK(!async_); |
| 79 if (size < 0) | 85 if (size < 0) |
| 80 return -1; | 86 return -1; |
| 81 | 87 |
| 88 SCOPED_FILE_TRACE_WITH_SIZE("ReadAtCurrentPos", size); |
| 89 |
| 82 DWORD bytes_read; | 90 DWORD bytes_read; |
| 83 if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL)) | 91 if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL)) |
| 84 return bytes_read; | 92 return bytes_read; |
| 85 if (ERROR_HANDLE_EOF == GetLastError()) | 93 if (ERROR_HANDLE_EOF == GetLastError()) |
| 86 return 0; | 94 return 0; |
| 87 | 95 |
| 88 return -1; | 96 return -1; |
| 89 } | 97 } |
| 90 | 98 |
| 91 int File::ReadNoBestEffort(int64 offset, char* data, int size) { | 99 int File::ReadNoBestEffort(int64 offset, char* data, int size) { |
| 100 // TODO(dbeam): trace this separately? |
| 92 return Read(offset, data, size); | 101 return Read(offset, data, size); |
| 93 } | 102 } |
| 94 | 103 |
| 95 int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { | 104 int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { |
| 105 // TODO(dbeam): trace this separately? |
| 96 return ReadAtCurrentPos(data, size); | 106 return ReadAtCurrentPos(data, size); |
| 97 } | 107 } |
| 98 | 108 |
| 99 int File::Write(int64 offset, const char* data, int size) { | 109 int File::Write(int64 offset, const char* data, int size) { |
| 100 ThreadRestrictions::AssertIOAllowed(); | 110 ThreadRestrictions::AssertIOAllowed(); |
| 101 DCHECK(IsValid()); | 111 DCHECK(IsValid()); |
| 102 DCHECK(!async_); | 112 DCHECK(!async_); |
| 103 | 113 |
| 114 SCOPED_FILE_TRACE_WITH_SIZE("Write", size); |
| 115 |
| 104 LARGE_INTEGER offset_li; | 116 LARGE_INTEGER offset_li; |
| 105 offset_li.QuadPart = offset; | 117 offset_li.QuadPart = offset; |
| 106 | 118 |
| 107 OVERLAPPED overlapped = {0}; | 119 OVERLAPPED overlapped = {0}; |
| 108 overlapped.Offset = offset_li.LowPart; | 120 overlapped.Offset = offset_li.LowPart; |
| 109 overlapped.OffsetHigh = offset_li.HighPart; | 121 overlapped.OffsetHigh = offset_li.HighPart; |
| 110 | 122 |
| 111 DWORD bytes_written; | 123 DWORD bytes_written; |
| 112 if (::WriteFile(file_.Get(), data, size, &bytes_written, &overlapped)) | 124 if (::WriteFile(file_.Get(), data, size, &bytes_written, &overlapped)) |
| 113 return bytes_written; | 125 return bytes_written; |
| 114 | 126 |
| 115 return -1; | 127 return -1; |
| 116 } | 128 } |
| 117 | 129 |
| 118 int File::WriteAtCurrentPos(const char* data, int size) { | 130 int File::WriteAtCurrentPos(const char* data, int size) { |
| 119 ThreadRestrictions::AssertIOAllowed(); | 131 ThreadRestrictions::AssertIOAllowed(); |
| 120 DCHECK(IsValid()); | 132 DCHECK(IsValid()); |
| 121 DCHECK(!async_); | 133 DCHECK(!async_); |
| 122 if (size < 0) | 134 if (size < 0) |
| 123 return -1; | 135 return -1; |
| 124 | 136 |
| 137 SCOPED_FILE_TRACE_WITH_SIZE("WriteAtCurrentPos", size); |
| 138 |
| 125 DWORD bytes_written; | 139 DWORD bytes_written; |
| 126 if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL)) | 140 if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL)) |
| 127 return bytes_written; | 141 return bytes_written; |
| 128 | 142 |
| 129 return -1; | 143 return -1; |
| 130 } | 144 } |
| 131 | 145 |
| 132 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { | 146 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
| 133 return WriteAtCurrentPos(data, size); | 147 return WriteAtCurrentPos(data, size); |
| 134 } | 148 } |
| 135 | 149 |
| 136 int64 File::GetLength() { | 150 int64 File::GetLength() { |
| 137 ThreadRestrictions::AssertIOAllowed(); | 151 ThreadRestrictions::AssertIOAllowed(); |
| 138 DCHECK(IsValid()); | 152 DCHECK(IsValid()); |
| 153 |
| 154 SCOPED_FILE_TRACE("GetLength"); |
| 155 |
| 139 LARGE_INTEGER size; | 156 LARGE_INTEGER size; |
| 140 if (!::GetFileSizeEx(file_.Get(), &size)) | 157 if (!::GetFileSizeEx(file_.Get(), &size)) |
| 141 return -1; | 158 return -1; |
| 142 | 159 |
| 143 return static_cast<int64>(size.QuadPart); | 160 return static_cast<int64>(size.QuadPart); |
| 144 } | 161 } |
| 145 | 162 |
| 146 bool File::SetLength(int64 length) { | 163 bool File::SetLength(int64 length) { |
| 147 ThreadRestrictions::AssertIOAllowed(); | 164 ThreadRestrictions::AssertIOAllowed(); |
| 148 DCHECK(IsValid()); | 165 DCHECK(IsValid()); |
| 149 | 166 |
| 167 SCOPED_FILE_TRACE_WITH_SIZE("SetLength", length); |
| 168 |
| 150 // Get the current file pointer. | 169 // Get the current file pointer. |
| 151 LARGE_INTEGER file_pointer; | 170 LARGE_INTEGER file_pointer; |
| 152 LARGE_INTEGER zero; | 171 LARGE_INTEGER zero; |
| 153 zero.QuadPart = 0; | 172 zero.QuadPart = 0; |
| 154 if (!::SetFilePointerEx(file_.Get(), zero, &file_pointer, FILE_CURRENT)) | 173 if (!::SetFilePointerEx(file_.Get(), zero, &file_pointer, FILE_CURRENT)) |
| 155 return false; | 174 return false; |
| 156 | 175 |
| 157 LARGE_INTEGER length_li; | 176 LARGE_INTEGER length_li; |
| 158 length_li.QuadPart = length; | 177 length_li.QuadPart = length; |
| 159 // If length > file size, SetFilePointerEx() should extend the file | 178 // If length > file size, SetFilePointerEx() should extend the file |
| 160 // with zeroes on all Windows standard file systems (NTFS, FATxx). | 179 // with zeroes on all Windows standard file systems (NTFS, FATxx). |
| 161 if (!::SetFilePointerEx(file_.Get(), length_li, NULL, FILE_BEGIN)) | 180 if (!::SetFilePointerEx(file_.Get(), length_li, NULL, FILE_BEGIN)) |
| 162 return false; | 181 return false; |
| 163 | 182 |
| 164 // Set the new file length and move the file pointer to its old position. | 183 // Set the new file length and move the file pointer to its old position. |
| 165 // This is consistent with ftruncate()'s behavior, even when the file | 184 // This is consistent with ftruncate()'s behavior, even when the file |
| 166 // pointer points to a location beyond the end of the file. | 185 // pointer points to a location beyond the end of the file. |
| 167 // TODO(rvargas): Emulating ftruncate details seem suspicious and it is not | 186 // TODO(rvargas): Emulating ftruncate details seem suspicious and it is not |
| 168 // promised by the interface (nor was promised by PlatformFile). See if this | 187 // promised by the interface (nor was promised by PlatformFile). See if this |
| 169 // implementation detail can be removed. | 188 // implementation detail can be removed. |
| 170 return ((::SetEndOfFile(file_.Get()) != FALSE) && | 189 return ((::SetEndOfFile(file_.Get()) != FALSE) && |
| 171 (::SetFilePointerEx(file_.Get(), file_pointer, NULL, FILE_BEGIN) != | 190 (::SetFilePointerEx(file_.Get(), file_pointer, NULL, FILE_BEGIN) != |
| 172 FALSE)); | 191 FALSE)); |
| 173 } | 192 } |
| 174 | 193 |
| 175 bool File::SetTimes(Time last_access_time, Time last_modified_time) { | 194 bool File::SetTimes(Time last_access_time, Time last_modified_time) { |
| 176 ThreadRestrictions::AssertIOAllowed(); | 195 ThreadRestrictions::AssertIOAllowed(); |
| 177 DCHECK(IsValid()); | 196 DCHECK(IsValid()); |
| 178 | 197 |
| 198 SCOPED_FILE_TRACE("SetTimes"); |
| 199 |
| 179 FILETIME last_access_filetime = last_access_time.ToFileTime(); | 200 FILETIME last_access_filetime = last_access_time.ToFileTime(); |
| 180 FILETIME last_modified_filetime = last_modified_time.ToFileTime(); | 201 FILETIME last_modified_filetime = last_modified_time.ToFileTime(); |
| 181 return (::SetFileTime(file_.Get(), NULL, &last_access_filetime, | 202 return (::SetFileTime(file_.Get(), NULL, &last_access_filetime, |
| 182 &last_modified_filetime) != FALSE); | 203 &last_modified_filetime) != FALSE); |
| 183 } | 204 } |
| 184 | 205 |
| 185 bool File::GetInfo(Info* info) { | 206 bool File::GetInfo(Info* info) { |
| 186 ThreadRestrictions::AssertIOAllowed(); | 207 ThreadRestrictions::AssertIOAllowed(); |
| 187 DCHECK(IsValid()); | 208 DCHECK(IsValid()); |
| 188 | 209 |
| 210 SCOPED_FILE_TRACE("GetInfo"); |
| 211 |
| 189 BY_HANDLE_FILE_INFORMATION file_info; | 212 BY_HANDLE_FILE_INFORMATION file_info; |
| 190 if (!GetFileInformationByHandle(file_.Get(), &file_info)) | 213 if (!GetFileInformationByHandle(file_.Get(), &file_info)) |
| 191 return false; | 214 return false; |
| 192 | 215 |
| 193 LARGE_INTEGER size; | 216 LARGE_INTEGER size; |
| 194 size.HighPart = file_info.nFileSizeHigh; | 217 size.HighPart = file_info.nFileSizeHigh; |
| 195 size.LowPart = file_info.nFileSizeLow; | 218 size.LowPart = file_info.nFileSizeLow; |
| 196 info->size = size.QuadPart; | 219 info->size = size.QuadPart; |
| 197 info->is_directory = | 220 info->is_directory = |
| 198 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 221 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 199 info->is_symbolic_link = false; // Windows doesn't have symbolic links. | 222 info->is_symbolic_link = false; // Windows doesn't have symbolic links. |
| 200 info->last_modified = Time::FromFileTime(file_info.ftLastWriteTime); | 223 info->last_modified = Time::FromFileTime(file_info.ftLastWriteTime); |
| 201 info->last_accessed = Time::FromFileTime(file_info.ftLastAccessTime); | 224 info->last_accessed = Time::FromFileTime(file_info.ftLastAccessTime); |
| 202 info->creation_time = Time::FromFileTime(file_info.ftCreationTime); | 225 info->creation_time = Time::FromFileTime(file_info.ftCreationTime); |
| 203 return true; | 226 return true; |
| 204 } | 227 } |
| 205 | 228 |
| 206 File::Error File::Lock() { | 229 File::Error File::Lock() { |
| 207 DCHECK(IsValid()); | 230 DCHECK(IsValid()); |
| 231 |
| 232 SCOPED_FILE_TRACE("Lock"); |
| 233 |
| 208 BOOL result = LockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); | 234 BOOL result = LockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); |
| 209 if (!result) | 235 if (!result) |
| 210 return OSErrorToFileError(GetLastError()); | 236 return OSErrorToFileError(GetLastError()); |
| 211 return FILE_OK; | 237 return FILE_OK; |
| 212 } | 238 } |
| 213 | 239 |
| 214 File::Error File::Unlock() { | 240 File::Error File::Unlock() { |
| 215 DCHECK(IsValid()); | 241 DCHECK(IsValid()); |
| 242 |
| 243 SCOPED_FILE_TRACE("Unlock"); |
| 244 |
| 216 BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); | 245 BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); |
| 217 if (!result) | 246 if (!result) |
| 218 return OSErrorToFileError(GetLastError()); | 247 return OSErrorToFileError(GetLastError()); |
| 219 return FILE_OK; | 248 return FILE_OK; |
| 220 } | 249 } |
| 221 | 250 |
| 222 File File::Duplicate() { | 251 File File::Duplicate() { |
| 223 if (!IsValid()) | 252 if (!IsValid()) |
| 224 return File(); | 253 return File(); |
| 225 | 254 |
| 255 SCOPED_FILE_TRACE("Duplicate"); |
| 256 |
| 226 HANDLE other_handle = nullptr; | 257 HANDLE other_handle = nullptr; |
| 227 | 258 |
| 228 if (!::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle | 259 if (!::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle |
| 229 GetPlatformFile(), | 260 GetPlatformFile(), |
| 230 GetCurrentProcess(), // hTargetProcessHandle | 261 GetCurrentProcess(), // hTargetProcessHandle |
| 231 &other_handle, | 262 &other_handle, |
| 232 0, // dwDesiredAccess ignored due to SAME_ACCESS | 263 0, // dwDesiredAccess ignored due to SAME_ACCESS |
| 233 FALSE, // !bInheritHandle | 264 FALSE, // !bInheritHandle |
| 234 DUPLICATE_SAME_ACCESS)) { | 265 DUPLICATE_SAME_ACCESS)) { |
| 235 return File(OSErrorToFileError(GetLastError())); | 266 return File(OSErrorToFileError(GetLastError())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 case ERROR_FILE_CORRUPT: | 302 case ERROR_FILE_CORRUPT: |
| 272 case ERROR_DISK_CORRUPT: | 303 case ERROR_DISK_CORRUPT: |
| 273 return FILE_ERROR_IO; | 304 return FILE_ERROR_IO; |
| 274 default: | 305 default: |
| 275 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", | 306 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", |
| 276 last_error); | 307 last_error); |
| 277 return FILE_ERROR_FAILED; | 308 return FILE_ERROR_FAILED; |
| 278 } | 309 } |
| 279 } | 310 } |
| 280 | 311 |
| 281 void File::DoInitialize(const FilePath& name, uint32 flags) { | 312 void File::DoInitialize(uint32 flags) { |
| 282 ThreadRestrictions::AssertIOAllowed(); | 313 ThreadRestrictions::AssertIOAllowed(); |
| 283 DCHECK(!IsValid()); | 314 DCHECK(!IsValid()); |
| 284 | 315 |
| 285 DWORD disposition = 0; | 316 DWORD disposition = 0; |
| 286 | 317 |
| 287 if (flags & FLAG_OPEN) | 318 if (flags & FLAG_OPEN) |
| 288 disposition = OPEN_EXISTING; | 319 disposition = OPEN_EXISTING; |
| 289 | 320 |
| 290 if (flags & FLAG_CREATE) { | 321 if (flags & FLAG_CREATE) { |
| 291 DCHECK(!disposition); | 322 DCHECK(!disposition); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 create_flags |= FILE_FLAG_OVERLAPPED; | 370 create_flags |= FILE_FLAG_OVERLAPPED; |
| 340 if (flags & FLAG_TEMPORARY) | 371 if (flags & FLAG_TEMPORARY) |
| 341 create_flags |= FILE_ATTRIBUTE_TEMPORARY; | 372 create_flags |= FILE_ATTRIBUTE_TEMPORARY; |
| 342 if (flags & FLAG_HIDDEN) | 373 if (flags & FLAG_HIDDEN) |
| 343 create_flags |= FILE_ATTRIBUTE_HIDDEN; | 374 create_flags |= FILE_ATTRIBUTE_HIDDEN; |
| 344 if (flags & FLAG_DELETE_ON_CLOSE) | 375 if (flags & FLAG_DELETE_ON_CLOSE) |
| 345 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; | 376 create_flags |= FILE_FLAG_DELETE_ON_CLOSE; |
| 346 if (flags & FLAG_BACKUP_SEMANTICS) | 377 if (flags & FLAG_BACKUP_SEMANTICS) |
| 347 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; | 378 create_flags |= FILE_FLAG_BACKUP_SEMANTICS; |
| 348 | 379 |
| 349 file_.Set(CreateFile(name.value().c_str(), access, sharing, NULL, | 380 file_.Set(CreateFile(path_.value().c_str(), access, sharing, NULL, |
| 350 disposition, create_flags, NULL)); | 381 disposition, create_flags, NULL)); |
| 351 | 382 |
| 352 if (file_.IsValid()) { | 383 if (file_.IsValid()) { |
| 353 error_details_ = FILE_OK; | 384 error_details_ = FILE_OK; |
| 354 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); | 385 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
| 355 | 386 |
| 356 if (flags & (FLAG_OPEN_ALWAYS)) | 387 if (flags & (FLAG_OPEN_ALWAYS)) |
| 357 created_ = (ERROR_ALREADY_EXISTS != GetLastError()); | 388 created_ = (ERROR_ALREADY_EXISTS != GetLastError()); |
| 358 else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) | 389 else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
| 359 created_ = true; | 390 created_ = true; |
| 360 } else { | 391 } else { |
| 361 error_details_ = OSErrorToFileError(GetLastError()); | 392 error_details_ = OSErrorToFileError(GetLastError()); |
| 362 } | 393 } |
| 363 } | 394 } |
| 364 | 395 |
| 365 bool File::DoFlush() { | 396 bool File::DoFlush() { |
| 366 ThreadRestrictions::AssertIOAllowed(); | 397 ThreadRestrictions::AssertIOAllowed(); |
| 367 DCHECK(IsValid()); | 398 DCHECK(IsValid()); |
| 368 return ::FlushFileBuffers(file_.Get()) != FALSE; | 399 return ::FlushFileBuffers(file_.Get()) != FALSE; |
| 369 } | 400 } |
| 370 | 401 |
| 371 void File::SetPlatformFile(PlatformFile file) { | 402 void File::SetPlatformFile(PlatformFile file) { |
| 372 file_.Set(file); | 403 file_.Set(file); |
| 373 } | 404 } |
| 374 | 405 |
| 375 } // namespace base | 406 } // namespace base |
| OLD | NEW |