| 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/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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // It manages its own destruction. Destruction happens on the I/O thread when | 117 // It manages its own destruction. Destruction happens on the I/O thread when |
| 118 // all the following conditions are satisfied: | 118 // all the following conditions are satisfied: |
| 119 // - |DetachFromOwnerNoLock()| has been called; | 119 // - |DetachFromOwnerNoLock()| has been called; |
| 120 // - there is no pending read; | 120 // - there is no pending read; |
| 121 // - there is no pending write. | 121 // - there is no pending write. |
| 122 class RawChannelIOHandler { | 122 class RawChannelIOHandler { |
| 123 public: | 123 public: |
| 124 RawChannelIOHandler(RawChannelWin* owner, | 124 RawChannelIOHandler(RawChannelWin* owner, |
| 125 ScopedPlatformHandle handle) | 125 ScopedPlatformHandle handle) |
| 126 : handle_(handle.Pass()), | 126 : handle_(handle.Pass()), |
| 127 io_task_runner_(internal::g_io_thread_task_runner), |
| 127 owner_(owner), | 128 owner_(owner), |
| 128 suppress_self_destruct_(false), | 129 suppress_self_destruct_(false), |
| 129 pending_read_(false), | 130 pending_read_(false), |
| 130 pending_write_(false), | 131 pending_write_(false), |
| 131 platform_handles_written_(0), | 132 platform_handles_written_(0), |
| 132 read_event_(CreateEvent(NULL, FALSE, FALSE, NULL)), | 133 read_event_(CreateEvent(NULL, FALSE, FALSE, NULL)), |
| 133 write_event_(CreateEvent(NULL, FALSE, FALSE, NULL)), | 134 write_event_(CreateEvent(NULL, FALSE, FALSE, NULL)), |
| 134 read_wait_object_(NULL), | 135 read_wait_object_(NULL), |
| 135 write_wait_object_(NULL), | 136 write_wait_object_(NULL), |
| 136 read_event_signalled_(false), | 137 read_event_signalled_(false), |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 if (ShouldSelfDestruct()) | 459 if (ShouldSelfDestruct()) |
| 459 delete this; | 460 delete this; |
| 460 } | 461 } |
| 461 | 462 |
| 462 static void CALLBACK ReadCompleted(void* param, BOOLEAN timed_out) { | 463 static void CALLBACK ReadCompleted(void* param, BOOLEAN timed_out) { |
| 463 DCHECK(!timed_out); | 464 DCHECK(!timed_out); |
| 464 // The destructor blocks on any callbacks that are in flight, so we know | 465 // The destructor blocks on any callbacks that are in flight, so we know |
| 465 // that that is always a pointer to a valid RawChannelIOHandler. | 466 // that that is always a pointer to a valid RawChannelIOHandler. |
| 466 RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param); | 467 RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param); |
| 467 that->read_event_signalled_ = true; | 468 that->read_event_signalled_ = true; |
| 468 internal::g_io_thread_task_runner->PostTask( | 469 that->io_task_runner_->PostTask( |
| 469 FROM_HERE, | 470 FROM_HERE, |
| 470 base::Bind(&RawChannelIOHandler::OnObjectSignaled, | 471 base::Bind(&RawChannelIOHandler::OnObjectSignaled, |
| 471 that->this_weakptr_, that->read_event_.Get())); | 472 that->this_weakptr_, that->read_event_.Get())); |
| 472 } | 473 } |
| 473 | 474 |
| 474 static void CALLBACK WriteCompleted(void* param, BOOLEAN timed_out) { | 475 static void CALLBACK WriteCompleted(void* param, BOOLEAN timed_out) { |
| 475 DCHECK(!timed_out); | 476 DCHECK(!timed_out); |
| 476 // The destructor blocks on any callbacks that are in flight, so we know | 477 // The destructor blocks on any callbacks that are in flight, so we know |
| 477 // that that is always a pointer to a valid RawChannelIOHandler. | 478 // that that is always a pointer to a valid RawChannelIOHandler. |
| 478 RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param); | 479 RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param); |
| 479 that->write_event_signalled_ = true; | 480 that->write_event_signalled_ = true; |
| 480 internal::g_io_thread_task_runner->PostTask( | 481 that->io_task_runner_->PostTask( |
| 481 FROM_HERE, | 482 FROM_HERE, |
| 482 base::Bind(&RawChannelIOHandler::OnObjectSignaled, | 483 base::Bind(&RawChannelIOHandler::OnObjectSignaled, |
| 483 that->this_weakptr_, that->write_event_.Get())); | 484 that->this_weakptr_, that->write_event_.Get())); |
| 484 } | 485 } |
| 485 | 486 |
| 486 ScopedPlatformHandle handle_; | 487 ScopedPlatformHandle handle_; |
| 487 | 488 |
| 489 // We cache this because ReadCompleted and WriteCompleted might get fired |
| 490 // after ShutdownIPCSupport is called. |
| 491 scoped_refptr<base::TaskRunner> io_task_runner_; |
| 492 |
| 488 // |owner_| is reset on the I/O thread under |owner_->write_lock()|. | 493 // |owner_| is reset on the I/O thread under |owner_->write_lock()|. |
| 489 // Therefore, it may be used on any thread under lock; or on the I/O thread | 494 // Therefore, it may be used on any thread under lock; or on the I/O thread |
| 490 // without locking. | 495 // without locking. |
| 491 RawChannelWin* owner_; | 496 RawChannelWin* owner_; |
| 492 | 497 |
| 493 // The following members must be used on the I/O thread. | 498 // The following members must be used on the I/O thread. |
| 494 scoped_ptr<ReadBuffer> preserved_read_buffer_after_detach_; | 499 scoped_ptr<ReadBuffer> preserved_read_buffer_after_detach_; |
| 495 scoped_ptr<WriteBuffer> preserved_write_buffer_after_detach_; | 500 scoped_ptr<WriteBuffer> preserved_write_buffer_after_detach_; |
| 496 bool suppress_self_destruct_; | 501 bool suppress_self_destruct_; |
| 497 | 502 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } else { | 773 } else { |
| 769 // This is to catch developer errors. Let them be caught on Vista and above, | 774 // This is to catch developer errors. Let them be caught on Vista and above, |
| 770 // i.e. no point in implementing this on XP since support for it will be | 775 // i.e. no point in implementing this on XP since support for it will be |
| 771 // removed in early 2016. | 776 // removed in early 2016. |
| 772 return false; | 777 return false; |
| 773 } | 778 } |
| 774 } | 779 } |
| 775 | 780 |
| 776 } // namespace edk | 781 } // namespace edk |
| 777 } // namespace mojo | 782 } // namespace mojo |
| OLD | NEW |