| 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 "net/base/file_stream_context.h" | 5 #include "net/base/file_stream_context.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 int FileStream::Context::Read(IOBuffer* buf, | 62 int FileStream::Context::Read(IOBuffer* buf, |
| 63 int buf_len, | 63 int buf_len, |
| 64 const CompletionCallback& callback) { | 64 const CompletionCallback& callback) { |
| 65 DCHECK(!async_in_progress_); | 65 DCHECK(!async_in_progress_); |
| 66 | 66 |
| 67 DWORD bytes_read; | 67 DWORD bytes_read; |
| 68 if (!ReadFile(file_.GetPlatformFile(), buf->data(), buf_len, | 68 if (!ReadFile(file_.GetPlatformFile(), buf->data(), buf_len, |
| 69 &bytes_read, &io_context_.overlapped)) { | 69 &bytes_read, &io_context_.overlapped)) { |
| 70 IOResult error = IOResult::FromOSError(GetLastError()); | 70 IOResult error = IOResult::FromOSError(GetLastError()); |
| 71 if (error.os_error == ERROR_IO_PENDING) { | 71 if (error.os_error == ERROR_HANDLE_EOF) |
| 72 return 0; // Report EOF by returning 0 bytes read. |
| 73 if (error.os_error == ERROR_IO_PENDING) |
| 72 IOCompletionIsPending(callback, buf); | 74 IOCompletionIsPending(callback, buf); |
| 73 } else if (error.os_error == ERROR_HANDLE_EOF) { | 75 else |
| 74 return 0; // Report EOF by returning 0 bytes read. | |
| 75 } else { | |
| 76 LOG(WARNING) << "ReadFile failed: " << error.os_error; | 76 LOG(WARNING) << "ReadFile failed: " << error.os_error; |
| 77 } | 77 return static_cast<int>(error.result); |
| 78 return error.result; | |
| 79 } | 78 } |
| 80 | 79 |
| 81 IOCompletionIsPending(callback, buf); | 80 IOCompletionIsPending(callback, buf); |
| 82 return ERR_IO_PENDING; | 81 return ERR_IO_PENDING; |
| 83 } | 82 } |
| 84 | 83 |
| 85 int FileStream::Context::Write(IOBuffer* buf, | 84 int FileStream::Context::Write(IOBuffer* buf, |
| 86 int buf_len, | 85 int buf_len, |
| 87 const CompletionCallback& callback) { | 86 const CompletionCallback& callback) { |
| 88 DWORD bytes_written = 0; | 87 DWORD bytes_written = 0; |
| 89 if (!WriteFile(file_.GetPlatformFile(), buf->data(), buf_len, | 88 if (!WriteFile(file_.GetPlatformFile(), buf->data(), buf_len, |
| 90 &bytes_written, &io_context_.overlapped)) { | 89 &bytes_written, &io_context_.overlapped)) { |
| 91 IOResult error = IOResult::FromOSError(GetLastError()); | 90 IOResult error = IOResult::FromOSError(GetLastError()); |
| 92 if (error.os_error == ERROR_IO_PENDING) { | 91 if (error.os_error == ERROR_IO_PENDING) |
| 93 IOCompletionIsPending(callback, buf); | 92 IOCompletionIsPending(callback, buf); |
| 94 } else { | 93 else |
| 95 LOG(WARNING) << "WriteFile failed: " << error.os_error; | 94 LOG(WARNING) << "WriteFile failed: " << error.os_error; |
| 96 } | 95 return static_cast<int>(error.result); |
| 97 return error.result; | |
| 98 } | 96 } |
| 99 | 97 |
| 100 IOCompletionIsPending(callback, buf); | 98 IOCompletionIsPending(callback, buf); |
| 101 return ERR_IO_PENDING; | 99 return ERR_IO_PENDING; |
| 102 } | 100 } |
| 103 | 101 |
| 104 FileStream::Context::IOResult FileStream::Context::SeekFileImpl( | 102 FileStream::Context::IOResult FileStream::Context::SeekFileImpl( |
| 105 base::File::Whence whence, | 103 base::File::Whence whence, |
| 106 int64 offset) { | 104 int64 offset) { |
| 107 LARGE_INTEGER result; | 105 LARGE_INTEGER result; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 in_flight_buf_ = NULL; | 140 in_flight_buf_ = NULL; |
| 143 CloseAndDelete(); | 141 CloseAndDelete(); |
| 144 return; | 142 return; |
| 145 } | 143 } |
| 146 | 144 |
| 147 int result; | 145 int result; |
| 148 if (error == ERROR_HANDLE_EOF) { | 146 if (error == ERROR_HANDLE_EOF) { |
| 149 result = 0; | 147 result = 0; |
| 150 } else if (error) { | 148 } else if (error) { |
| 151 IOResult error_result = IOResult::FromOSError(error); | 149 IOResult error_result = IOResult::FromOSError(error); |
| 152 result = error_result.result; | 150 result = static_cast<int>(error_result.result); |
| 153 } else { | 151 } else { |
| 154 result = bytes_read; | 152 result = bytes_read; |
| 155 IncrementOffset(&io_context_.overlapped, bytes_read); | 153 IncrementOffset(&io_context_.overlapped, bytes_read); |
| 156 } | 154 } |
| 157 | 155 |
| 158 CompletionCallback temp_callback = callback_; | 156 CompletionCallback temp_callback = callback_; |
| 159 callback_.Reset(); | 157 callback_.Reset(); |
| 160 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; | 158 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; |
| 161 in_flight_buf_ = NULL; | 159 in_flight_buf_ = NULL; |
| 162 temp_callback.Run(result); | 160 temp_callback.Run(result); |
| 163 } | 161 } |
| 164 | 162 |
| 165 } // namespace net | 163 } // namespace net |
| OLD | NEW |