Chromium Code Reviews| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 DCHECK(!callback_.is_null()); | 146 DCHECK(!callback_.is_null()); |
| 147 DCHECK(async_in_progress_); | 147 DCHECK(async_in_progress_); |
| 148 | 148 |
| 149 if (!async_read_initiated_) | 149 if (!async_read_initiated_) |
| 150 async_in_progress_ = false; | 150 async_in_progress_ = false; |
| 151 | 151 |
| 152 if (orphaned_) { | 152 if (orphaned_) { |
| 153 async_in_progress_ = false; | 153 async_in_progress_ = false; |
| 154 callback_.Reset(); | 154 callback_.Reset(); |
| 155 in_flight_buf_ = NULL; | 155 in_flight_buf_ = NULL; |
| 156 CloseAndDelete(); | 156 CloseAndDelete(); |
|
rvargas (doing something else)
2015/02/12 23:53:35
This looks wrong to me. Aren't we deleting the obj
ananta
2015/02/13 00:17:00
Reworked this a bit. Added a function DeleteOrphan
| |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 | 159 |
| 160 if (error == ERROR_HANDLE_EOF) { | 160 if (error == ERROR_HANDLE_EOF) { |
| 161 result_ = 0; | 161 result_ = 0; |
| 162 } else if (error) { | 162 } else if (error) { |
| 163 IOResult error_result = IOResult::FromOSError(error); | 163 IOResult error_result = IOResult::FromOSError(error); |
| 164 result_ = static_cast<int>(error_result.result); | 164 result_ = static_cast<int>(error_result.result); |
| 165 } else { | 165 } else { |
| 166 result_ = bytes_read; | 166 result_ = bytes_read; |
|
rvargas (doing something else)
2015/02/12 23:53:35
if (result_)
dcheck_eq(result_, bytes_read) ?
ananta
2015/02/13 00:17:01
Done.
| |
| 167 IncrementOffset(&io_context_.overlapped, bytes_read); | 167 IncrementOffset(&io_context_.overlapped, bytes_read); |
|
rvargas (doing something else)
2015/02/12 23:53:35
result_ ?
ananta
2015/02/13 00:17:01
I added result_ = 0 here.
ananta
2015/02/13 00:36:38
That is wrong :(. Removed it.
| |
| 168 } | 168 } |
| 169 | 169 |
| 170 if (async_read_initiated_) | 170 if (async_read_initiated_) |
| 171 io_complete_for_read_received_ = true; | 171 io_complete_for_read_received_ = true; |
| 172 | 172 |
| 173 InvokeUserCallback(); | 173 InvokeUserCallback(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void FileStream::Context::InvokeUserCallback() { | 176 void FileStream::Context::InvokeUserCallback() { |
| 177 if (callback_.is_null()) | |
| 178 return; | |
| 177 // For an asynchonous Read operation don't invoke the user callback until | 179 // For an asynchonous Read operation don't invoke the user callback until |
| 178 // we receive the IO completion notification and the asynchronous Read | 180 // we receive the IO completion notification and the asynchronous Read |
| 179 // completion notification. | 181 // completion notification. |
| 180 if (async_read_initiated_) { | 182 if (async_read_initiated_) { |
| 181 if (!io_complete_for_read_received_ || !async_read_completed_) | 183 if (!io_complete_for_read_received_ || !async_read_completed_) |
| 182 return; | 184 return; |
| 183 async_read_initiated_ = false; | 185 async_read_initiated_ = false; |
| 184 io_complete_for_read_received_ = false; | 186 io_complete_for_read_received_ = false; |
| 185 async_read_completed_ = false; | 187 async_read_completed_ = false; |
| 186 async_in_progress_ = false; | 188 async_in_progress_ = false; |
| 187 } | 189 } |
| 188 CompletionCallback temp_callback = callback_; | 190 CompletionCallback temp_callback = callback_; |
| 189 callback_.Reset(); | 191 callback_.Reset(); |
| 190 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; | 192 scoped_refptr<IOBuffer> temp_buf = in_flight_buf_; |
| 191 in_flight_buf_ = NULL; | 193 in_flight_buf_ = NULL; |
| 192 temp_callback.Run(result_); | 194 temp_callback.Run(result_); |
| 193 } | 195 } |
| 194 | 196 |
| 195 // static | 197 // static |
| 196 void FileStream::Context::ReadAsync( | 198 void FileStream::Context::ReadAsync( |
| 197 FileStream::Context* context, | 199 FileStream::Context* context, |
| 198 HANDLE file, | 200 HANDLE file, |
| 199 scoped_refptr<net::IOBuffer> buf, | 201 scoped_refptr<net::IOBuffer> buf, |
| 200 int buf_len, | 202 int buf_len, |
| 201 OVERLAPPED* overlapped, | 203 OVERLAPPED* overlapped, |
| 202 scoped_refptr<base::MessageLoopProxy> origin_thread_loop) { | 204 scoped_refptr<base::MessageLoopProxy> origin_thread_loop) { |
| 203 DWORD bytes_read = 0; | 205 DWORD bytes_read = 0; |
| 204 BOOL ret = ::ReadFile(file, buf->data(), buf_len, &bytes_read, overlapped); | 206 BOOL ret = ::ReadFile(file, buf->data(), buf_len, &bytes_read, overlapped); |
| 205 origin_thread_loop->PostTask( | 207 origin_thread_loop->PostTask( |
| 206 FROM_HERE, base::Bind(&FileStream::Context::ReadAsyncResult, | 208 FROM_HERE, |
| 207 base::Unretained(context), ret ? bytes_read : 0, | 209 base::Bind(&FileStream::Context::ReadAsyncResult, |
| 208 ret ? 0 : ::GetLastError())); | 210 base::Unretained(context), ret, bytes_read, ::GetLastError())); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void FileStream::Context::ReadAsyncResult(DWORD bytes_read, DWORD os_error) { | 213 void FileStream::Context::ReadAsyncResult(BOOL read_file_ret, |
| 212 if (!os_error) | 214 DWORD bytes_read, |
| 215 DWORD os_error) { | |
| 216 if (read_file_ret) { | |
|
rvargas (doing something else)
2015/02/12 23:53:35
Note that the original logic was:
DWORD byt
ananta
2015/02/13 00:17:00
Did something similar.
| |
| 217 DCHECK(!os_error); | |
| 213 result_ = bytes_read; | 218 result_ = bytes_read; |
| 214 | 219 } |
| 215 IOResult error = IOResult::FromOSError(os_error); | 220 IOResult error = IOResult::FromOSError(os_error); |
| 216 if (error.os_error == ERROR_HANDLE_EOF) { | 221 if (error.os_error == ERROR_HANDLE_EOF) { |
| 217 // Report EOF by returning 0 bytes read. | 222 // Report EOF by returning 0 bytes read. |
| 218 OnIOCompleted(&io_context_, 0, error.os_error); | 223 OnIOCompleted(&io_context_, 0, error.os_error); |
| 219 } else if (error.os_error != ERROR_IO_PENDING) { | 224 } else if (error.os_error != ERROR_IO_PENDING) { |
| 220 // We don't need to inform the caller about ERROR_PENDING_IO as that was | 225 // We don't need to inform the caller about ERROR_PENDING_IO as that was |
| 221 // already done when the ReadFile call was queued to the worker pool. | 226 // already done when the ReadFile call was queued to the worker pool. |
| 222 if (error.os_error) { | 227 if (error.os_error) { |
| 223 LOG(WARNING) << "ReadFile failed: " << error.os_error; | 228 LOG(WARNING) << "ReadFile failed: " << error.os_error; |
| 224 OnIOCompleted(&io_context_, 0, error.os_error); | 229 OnIOCompleted(&io_context_, 0, error.os_error); |
| 225 } | 230 } |
| 226 } | 231 } |
| 227 async_read_completed_ = true; | 232 async_read_completed_ = true; |
| 228 InvokeUserCallback(); | 233 InvokeUserCallback(); |
| 229 } | 234 } |
| 230 | 235 |
| 231 } // namespace net | 236 } // namespace net |
| OLD | NEW |