OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/system/raw_channel.h" | 5 #include "mojo/system/raw_channel.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 base::MessageLoop::current() == owner_->message_loop_for_io()); | 291 base::MessageLoop::current() == owner_->message_loop_for_io()); |
292 DCHECK(suppress_self_destruct_); | 292 DCHECK(suppress_self_destruct_); |
293 | 293 |
294 CHECK(pending_read_); | 294 CHECK(pending_read_); |
295 pending_read_ = false; | 295 pending_read_ = false; |
296 if (!owner_) | 296 if (!owner_) |
297 return; | 297 return; |
298 | 298 |
299 if (error != ERROR_SUCCESS) { | 299 if (error != ERROR_SUCCESS) { |
300 DCHECK_EQ(bytes_read, 0u); | 300 DCHECK_EQ(bytes_read, 0u); |
301 PLOG_IF(ERROR, error != ERROR_BROKEN_PIPE) << "ReadFile"; | 301 LOG_IF(ERROR, error != ERROR_BROKEN_PIPE) |
302 << "ReadFile: " << logging::SystemErrorCodeToString(error); | |
302 owner_->OnReadCompleted(false, 0); | 303 owner_->OnReadCompleted(false, 0); |
303 } else { | 304 } else { |
304 DCHECK_GT(bytes_read, 0u); | 305 DCHECK_GT(bytes_read, 0u); |
305 owner_->OnReadCompleted(true, bytes_read); | 306 owner_->OnReadCompleted(true, bytes_read); |
306 } | 307 } |
307 } | 308 } |
308 | 309 |
309 void RawChannelWin::RawChannelIOHandler::OnWriteCompleted(DWORD bytes_written, | 310 void RawChannelWin::RawChannelIOHandler::OnWriteCompleted(DWORD bytes_written, |
310 DWORD error) { | 311 DWORD error) { |
311 DCHECK(!owner_ || | 312 DCHECK(!owner_ || |
312 base::MessageLoop::current() == owner_->message_loop_for_io()); | 313 base::MessageLoop::current() == owner_->message_loop_for_io()); |
313 DCHECK(suppress_self_destruct_); | 314 DCHECK(suppress_self_destruct_); |
314 | 315 |
315 if (!owner_) { | 316 if (!owner_) { |
316 // No lock needed. | 317 // No lock needed. |
317 CHECK(pending_write_); | 318 CHECK(pending_write_); |
318 pending_write_ = false; | 319 pending_write_ = false; |
319 return; | 320 return; |
320 } | 321 } |
321 | 322 |
322 { | 323 { |
323 base::AutoLock locker(owner_->write_lock()); | 324 base::AutoLock locker(owner_->write_lock()); |
324 CHECK(pending_write_); | 325 CHECK(pending_write_); |
325 pending_write_ = false; | 326 pending_write_ = false; |
326 } | 327 } |
327 | 328 |
328 if (error != ERROR_SUCCESS) { | 329 if (error != ERROR_SUCCESS) { |
329 LOG(ERROR) << "WriteFile failed: " << error; | 330 LOG(ERROR) << "WriteFile failed: " << error; |
viettrungluu
2014/04/25 20:58:01
Done here too.
| |
330 owner_->OnWriteCompleted(false, 0); | 331 owner_->OnWriteCompleted(false, 0); |
331 } else { | 332 } else { |
332 owner_->OnWriteCompleted(true, bytes_written); | 333 owner_->OnWriteCompleted(true, bytes_written); |
333 } | 334 } |
334 } | 335 } |
335 | 336 |
336 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle) | 337 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle) |
337 : handle_(handle.Pass()), | 338 : handle_(handle.Pass()), |
338 io_handler_(NULL), | 339 io_handler_(NULL), |
339 skip_completion_port_on_success_( | 340 skip_completion_port_on_success_( |
(...skipping 17 matching lines...) Expand all Loading... | |
357 DWORD bytes_read_dword = 0; | 358 DWORD bytes_read_dword = 0; |
358 BOOL result = ReadFile(io_handler_->handle(), | 359 BOOL result = ReadFile(io_handler_->handle(), |
359 buffer, | 360 buffer, |
360 static_cast<DWORD>(bytes_to_read), | 361 static_cast<DWORD>(bytes_to_read), |
361 &bytes_read_dword, | 362 &bytes_read_dword, |
362 &io_handler_->read_context()->overlapped); | 363 &io_handler_->read_context()->overlapped); |
363 if (!result) { | 364 if (!result) { |
364 DCHECK_EQ(bytes_read_dword, 0u); | 365 DCHECK_EQ(bytes_read_dword, 0u); |
365 DWORD error = GetLastError(); | 366 DWORD error = GetLastError(); |
366 if (error != ERROR_IO_PENDING) { | 367 if (error != ERROR_IO_PENDING) { |
367 LOG_IF(ERROR, error != ERROR_BROKEN_PIPE) << "ReadFile failed: " << error; | 368 LOG_IF(ERROR, error != ERROR_BROKEN_PIPE) << "ReadFile failed: " << error; |
yzshen1
2014/04/25 20:24:07
Maybe we could output the same info here, using lo
viettrungluu
2014/04/25 20:58:01
Done.
| |
368 return IO_FAILED; | 369 return IO_FAILED; |
369 } | 370 } |
370 } | 371 } |
371 | 372 |
372 if (result && skip_completion_port_on_success_) { | 373 if (result && skip_completion_port_on_success_) { |
373 *bytes_read = bytes_read_dword; | 374 *bytes_read = bytes_read_dword; |
374 return IO_SUCCEEDED; | 375 return IO_SUCCEEDED; |
375 } | 376 } |
376 | 377 |
377 // If the read is pending or the read has succeeded but we don't skip | 378 // If the read is pending or the read has succeeded but we don't skip |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 | 528 |
528 // Static factory method declared in raw_channel.h. | 529 // Static factory method declared in raw_channel.h. |
529 // static | 530 // static |
530 scoped_ptr<RawChannel> RawChannel::Create( | 531 scoped_ptr<RawChannel> RawChannel::Create( |
531 embedder::ScopedPlatformHandle handle) { | 532 embedder::ScopedPlatformHandle handle) { |
532 return scoped_ptr<RawChannel>(new RawChannelWin(handle.Pass())); | 533 return scoped_ptr<RawChannel>(new RawChannelWin(handle.Pass())); |
533 } | 534 } |
534 | 535 |
535 } // namespace system | 536 } // namespace system |
536 } // namespace mojo | 537 } // namespace mojo |
OLD | NEW |