Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1967)

Side by Side Diff: mojo/edk/system/raw_channel_win.cc

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/edk/system/raw_channel.h" 5 #include "mojo/edk/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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) { 365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) {
366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); 366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io());
367 DCHECK(io_handler_); 367 DCHECK(io_handler_);
368 DCHECK(!io_handler_->pending_read()); 368 DCHECK(!io_handler_->pending_read());
369 369
370 char* buffer = nullptr; 370 char* buffer = nullptr;
371 size_t bytes_to_read = 0; 371 size_t bytes_to_read = 0;
372 read_buffer()->GetBuffer(&buffer, &bytes_to_read); 372 read_buffer()->GetBuffer(&buffer, &bytes_to_read);
373 373
374 BOOL result = 374 BOOL result = ReadFile(io_handler_->handle(),
375 ReadFile(io_handler_->handle(), buffer, static_cast<DWORD>(bytes_to_read), 375 buffer,
376 nullptr, &io_handler_->read_context()->overlapped); 376 static_cast<DWORD>(bytes_to_read),
377 nullptr,
378 &io_handler_->read_context()->overlapped);
377 if (!result) { 379 if (!result) {
378 DWORD error = GetLastError(); 380 DWORD error = GetLastError();
379 if (error == ERROR_BROKEN_PIPE) 381 if (error == ERROR_BROKEN_PIPE)
380 return IO_FAILED_SHUTDOWN; 382 return IO_FAILED_SHUTDOWN;
381 if (error != ERROR_IO_PENDING) { 383 if (error != ERROR_IO_PENDING) {
382 LOG(WARNING) << "ReadFile: " << logging::SystemErrorCodeToString(error); 384 LOG(WARNING) << "ReadFile: " << logging::SystemErrorCodeToString(error);
383 return IO_FAILED_UNKNOWN; 385 return IO_FAILED_UNKNOWN;
384 } 386 }
385 } 387 }
386 388
387 if (result && skip_completion_port_on_success_) { 389 if (result && skip_completion_port_on_success_) {
388 DWORD bytes_read_dword = 0; 390 DWORD bytes_read_dword = 0;
389 BOOL get_size_result = GetOverlappedResult( 391 BOOL get_size_result =
390 io_handler_->handle(), &io_handler_->read_context()->overlapped, 392 GetOverlappedResult(io_handler_->handle(),
391 &bytes_read_dword, FALSE); 393 &io_handler_->read_context()->overlapped,
394 &bytes_read_dword,
395 FALSE);
392 DPCHECK(get_size_result); 396 DPCHECK(get_size_result);
393 *bytes_read = bytes_read_dword; 397 *bytes_read = bytes_read_dword;
394 return IO_SUCCEEDED; 398 return IO_SUCCEEDED;
395 } 399 }
396 400
397 // If the read is pending or the read has succeeded but we don't skip 401 // If the read is pending or the read has succeeded but we don't skip
398 // completion port on success, instruct |io_handler_| to wait for the 402 // completion port on success, instruct |io_handler_| to wait for the
399 // completion packet. 403 // completion packet.
400 // 404 //
401 // TODO(yzshen): It seems there isn't document saying that all error cases 405 // TODO(yzshen): It seems there isn't document saying that all error cases
(...skipping 13 matching lines...) Expand all
415 size_t bytes_read = 0; 419 size_t bytes_read = 0;
416 IOResult io_result = Read(&bytes_read); 420 IOResult io_result = Read(&bytes_read);
417 if (io_result == IO_SUCCEEDED) { 421 if (io_result == IO_SUCCEEDED) {
418 DCHECK(skip_completion_port_on_success_); 422 DCHECK(skip_completion_port_on_success_);
419 423
420 // We have finished reading successfully. Queue a notification manually. 424 // We have finished reading successfully. Queue a notification manually.
421 io_handler_->OnPendingReadStarted(); 425 io_handler_->OnPendingReadStarted();
422 // |io_handler_| won't go away before the task is run, so it is safe to use 426 // |io_handler_| won't go away before the task is run, so it is safe to use
423 // |base::Unretained()|. 427 // |base::Unretained()|.
424 message_loop_for_io()->PostTask( 428 message_loop_for_io()->PostTask(
425 FROM_HERE, base::Bind(&RawChannelIOHandler::OnIOCompleted, 429 FROM_HERE,
426 base::Unretained(io_handler_), 430 base::Bind(&RawChannelIOHandler::OnIOCompleted,
427 base::Unretained(io_handler_->read_context()), 431 base::Unretained(io_handler_),
428 static_cast<DWORD>(bytes_read), ERROR_SUCCESS)); 432 base::Unretained(io_handler_->read_context()),
433 static_cast<DWORD>(bytes_read),
434 ERROR_SUCCESS));
429 return IO_PENDING; 435 return IO_PENDING;
430 } 436 }
431 437
432 return io_result; 438 return io_result;
433 } 439 }
434 440
435 embedder::ScopedPlatformHandleVectorPtr RawChannelWin::GetReadPlatformHandles( 441 embedder::ScopedPlatformHandleVectorPtr RawChannelWin::GetReadPlatformHandles(
436 size_t num_platform_handles, 442 size_t num_platform_handles,
437 const void* platform_handle_table) { 443 const void* platform_handle_table) {
438 // TODO(vtl): Implement. 444 // TODO(vtl): Implement.
(...skipping 13 matching lines...) Expand all
452 // TODO(vtl): Implement. 458 // TODO(vtl): Implement.
453 NOTIMPLEMENTED(); 459 NOTIMPLEMENTED();
454 } 460 }
455 461
456 std::vector<WriteBuffer::Buffer> buffers; 462 std::vector<WriteBuffer::Buffer> buffers;
457 write_buffer_no_lock()->GetBuffers(&buffers); 463 write_buffer_no_lock()->GetBuffers(&buffers);
458 DCHECK(!buffers.empty()); 464 DCHECK(!buffers.empty());
459 465
460 // TODO(yzshen): Handle multi-segment writes more efficiently. 466 // TODO(yzshen): Handle multi-segment writes more efficiently.
461 DWORD bytes_written_dword = 0; 467 DWORD bytes_written_dword = 0;
462 BOOL result = 468 BOOL result = WriteFile(io_handler_->handle(),
463 WriteFile(io_handler_->handle(), buffers[0].addr, 469 buffers[0].addr,
464 static_cast<DWORD>(buffers[0].size), &bytes_written_dword, 470 static_cast<DWORD>(buffers[0].size),
465 &io_handler_->write_context_no_lock()->overlapped); 471 &bytes_written_dword,
472 &io_handler_->write_context_no_lock()->overlapped);
466 if (!result) { 473 if (!result) {
467 DWORD error = GetLastError(); 474 DWORD error = GetLastError();
468 if (error == ERROR_BROKEN_PIPE) 475 if (error == ERROR_BROKEN_PIPE)
469 return IO_FAILED_SHUTDOWN; 476 return IO_FAILED_SHUTDOWN;
470 if (error != ERROR_IO_PENDING) { 477 if (error != ERROR_IO_PENDING) {
471 LOG(WARNING) << "WriteFile: " << logging::SystemErrorCodeToString(error); 478 LOG(WARNING) << "WriteFile: " << logging::SystemErrorCodeToString(error);
472 return IO_FAILED_UNKNOWN; 479 return IO_FAILED_UNKNOWN;
473 } 480 }
474 } 481 }
475 482
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 514
508 // We have finished writing successfully. Queue a notification manually. 515 // We have finished writing successfully. Queue a notification manually.
509 io_handler_->OnPendingWriteStartedNoLock(); 516 io_handler_->OnPendingWriteStartedNoLock();
510 // |io_handler_| won't go away before that task is run, so it is safe to use 517 // |io_handler_| won't go away before that task is run, so it is safe to use
511 // |base::Unretained()|. 518 // |base::Unretained()|.
512 message_loop_for_io()->PostTask( 519 message_loop_for_io()->PostTask(
513 FROM_HERE, 520 FROM_HERE,
514 base::Bind(&RawChannelIOHandler::OnIOCompleted, 521 base::Bind(&RawChannelIOHandler::OnIOCompleted,
515 base::Unretained(io_handler_), 522 base::Unretained(io_handler_),
516 base::Unretained(io_handler_->write_context_no_lock()), 523 base::Unretained(io_handler_->write_context_no_lock()),
517 static_cast<DWORD>(bytes_written), ERROR_SUCCESS)); 524 static_cast<DWORD>(bytes_written),
525 ERROR_SUCCESS));
518 return IO_PENDING; 526 return IO_PENDING;
519 } 527 }
520 528
521 return io_result; 529 return io_result;
522 } 530 }
523 531
524 bool RawChannelWin::OnInit() { 532 bool RawChannelWin::OnInit() {
525 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); 533 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io());
526 534
527 DCHECK(handle_.is_valid()); 535 DCHECK(handle_.is_valid());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 576
569 // Static factory method declared in raw_channel.h. 577 // Static factory method declared in raw_channel.h.
570 // static 578 // static
571 scoped_ptr<RawChannel> RawChannel::Create( 579 scoped_ptr<RawChannel> RawChannel::Create(
572 embedder::ScopedPlatformHandle handle) { 580 embedder::ScopedPlatformHandle handle) {
573 return make_scoped_ptr(new RawChannelWin(handle.Pass())); 581 return make_scoped_ptr(new RawChannelWin(handle.Pass()));
574 } 582 }
575 583
576 } // namespace system 584 } // namespace system
577 } // namespace mojo 585 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel_unittest.cc ('k') | mojo/edk/system/remote_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698