OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/file_stream.h" | 5 #include "net/base/file_stream.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/win_util.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 // Ensure that we can just use our Whence values directly. | 18 // Ensure that we can just use our Whence values directly. |
18 COMPILE_ASSERT(FROM_BEGIN == FILE_BEGIN, bad_whence_begin); | 19 COMPILE_ASSERT(FROM_BEGIN == FILE_BEGIN, bad_whence_begin); |
19 COMPILE_ASSERT(FROM_CURRENT == FILE_CURRENT, bad_whence_current); | 20 COMPILE_ASSERT(FROM_CURRENT == FILE_CURRENT, bad_whence_current); |
20 COMPILE_ASSERT(FROM_END == FILE_END, bad_whence_end); | 21 COMPILE_ASSERT(FROM_END == FILE_END, bad_whence_end); |
21 | 22 |
22 static void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) { | 23 static void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (auto_closed_) | 141 if (auto_closed_) |
141 Close(); | 142 Close(); |
142 } | 143 } |
143 | 144 |
144 void FileStream::Close() { | 145 void FileStream::Close() { |
145 if (file_ != INVALID_HANDLE_VALUE) | 146 if (file_ != INVALID_HANDLE_VALUE) |
146 CancelIo(file_); | 147 CancelIo(file_); |
147 | 148 |
148 async_context_.reset(); | 149 async_context_.reset(); |
149 if (file_ != INVALID_HANDLE_VALUE) { | 150 if (file_ != INVALID_HANDLE_VALUE) { |
150 CloseHandle(file_); | 151 if (!CloseHandle(file_)) { |
| 152 DLOG(WARNING) << " Unable to close file with handle = " |
| 153 << file_ << ", due to error " |
| 154 << GetLastError() << " (" |
| 155 << win_util::FormatMessage(GetLastError()) |
| 156 << ")"; |
| 157 } |
151 file_ = INVALID_HANDLE_VALUE; | 158 file_ = INVALID_HANDLE_VALUE; |
152 } | 159 } |
153 } | 160 } |
154 | 161 |
155 int FileStream::Open(const FilePath& path, int open_flags) { | 162 int FileStream::Open(const FilePath& path, int open_flags) { |
156 if (IsOpen()) { | 163 if (IsOpen()) { |
157 DLOG(FATAL) << "File is already open!"; | 164 DLOG(FATAL) << "File is already open!"; |
158 return ERR_UNEXPECTED; | 165 return ERR_UNEXPECTED; |
159 } | 166 } |
160 | 167 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 DWORD error = GetLastError(); | 343 DWORD error = GetLastError(); |
337 LOG(WARNING) << "SetEndOfFile failed: " << error; | 344 LOG(WARNING) << "SetEndOfFile failed: " << error; |
338 return MapErrorCode(error); | 345 return MapErrorCode(error); |
339 } | 346 } |
340 | 347 |
341 // Success. | 348 // Success. |
342 return seek_position; | 349 return seek_position; |
343 } | 350 } |
344 | 351 |
345 } // namespace net | 352 } // namespace net |
OLD | NEW |