| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 FileStream::Context::~Context() { | 64 FileStream::Context::~Context() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 int FileStream::Context::ReadAsync(IOBuffer* buf, | 67 int FileStream::Context::ReadAsync(IOBuffer* buf, |
| 68 int buf_len, | 68 int buf_len, |
| 69 const CompletionCallback& callback) { | 69 const CompletionCallback& callback) { |
| 70 DCHECK(!async_in_progress_); | 70 DCHECK(!async_in_progress_); |
| 71 | 71 |
| 72 DWORD bytes_read; | 72 DWORD bytes_read; |
| 73 if (!ReadFile(file_.GetPlatformFile(), buf->data(), buf_len, | 73 if (!ReadFile(file_.GetPlatformFile(), |
| 74 &bytes_read, &io_context_.overlapped)) { | 74 buf->data(), |
| 75 buf_len, |
| 76 &bytes_read, |
| 77 &io_context_.overlapped)) { |
| 75 IOResult error = IOResult::FromOSError(GetLastError()); | 78 IOResult error = IOResult::FromOSError(GetLastError()); |
| 76 if (error.os_error == ERROR_IO_PENDING) { | 79 if (error.os_error == ERROR_IO_PENDING) { |
| 77 IOCompletionIsPending(callback, buf); | 80 IOCompletionIsPending(callback, buf); |
| 78 } else if (error.os_error == ERROR_HANDLE_EOF) { | 81 } else if (error.os_error == ERROR_HANDLE_EOF) { |
| 79 return 0; // Report EOF by returning 0 bytes read. | 82 return 0; // Report EOF by returning 0 bytes read. |
| 80 } else { | 83 } else { |
| 81 LOG(WARNING) << "ReadFile failed: " << error.os_error; | 84 LOG(WARNING) << "ReadFile failed: " << error.os_error; |
| 82 } | 85 } |
| 83 return error.result; | 86 return error.result; |
| 84 } | 87 } |
| 85 | 88 |
| 86 IOCompletionIsPending(callback, buf); | 89 IOCompletionIsPending(callback, buf); |
| 87 return ERR_IO_PENDING; | 90 return ERR_IO_PENDING; |
| 88 } | 91 } |
| 89 | 92 |
| 90 int FileStream::Context::WriteAsync(IOBuffer* buf, | 93 int FileStream::Context::WriteAsync(IOBuffer* buf, |
| 91 int buf_len, | 94 int buf_len, |
| 92 const CompletionCallback& callback) { | 95 const CompletionCallback& callback) { |
| 93 DWORD bytes_written = 0; | 96 DWORD bytes_written = 0; |
| 94 if (!WriteFile(file_.GetPlatformFile(), buf->data(), buf_len, | 97 if (!WriteFile(file_.GetPlatformFile(), |
| 95 &bytes_written, &io_context_.overlapped)) { | 98 buf->data(), |
| 99 buf_len, |
| 100 &bytes_written, |
| 101 &io_context_.overlapped)) { |
| 96 IOResult error = IOResult::FromOSError(GetLastError()); | 102 IOResult error = IOResult::FromOSError(GetLastError()); |
| 97 if (error.os_error == ERROR_IO_PENDING) { | 103 if (error.os_error == ERROR_IO_PENDING) { |
| 98 IOCompletionIsPending(callback, buf); | 104 IOCompletionIsPending(callback, buf); |
| 99 } else { | 105 } else { |
| 100 LOG(WARNING) << "WriteFile failed: " << error.os_error; | 106 LOG(WARNING) << "WriteFile failed: " << error.os_error; |
| 101 } | 107 } |
| 102 return error.result; | 108 return error.result; |
| 103 } | 109 } |
| 104 | 110 |
| 105 IOCompletionIsPending(callback, buf); | 111 IOCompletionIsPending(callback, buf); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 174 } |
| 169 | 175 |
| 170 CompletionCallback temp_callback = callback_; | 176 CompletionCallback temp_callback = callback_; |
| 171 callback_.Reset(); | 177 callback_.Reset(); |
| 172 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; | 178 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; |
| 173 in_flight_buf_ = NULL; | 179 in_flight_buf_ = NULL; |
| 174 temp_callback.Run(result); | 180 temp_callback.Run(result); |
| 175 } | 181 } |
| 176 | 182 |
| 177 } // namespace net | 183 } // namespace net |
| OLD | NEW |