| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/message_pipe_dispatcher.h" | 5 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/edk/embedder/embedder_internal.h" | 10 #include "mojo/edk/embedder/embedder_internal.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 channel_->SetSerializedData( | 111 channel_->SetSerializedData( |
| 112 serialized_read_buffer, serialized_read_buffer_size, | 112 serialized_read_buffer, serialized_read_buffer_size, |
| 113 serialized_write_buffer, serialized_write_buffer_size); | 113 serialized_write_buffer, serialized_write_buffer_size); |
| 114 if (g_use_channel_on_io_thread_only) { | 114 if (g_use_channel_on_io_thread_only) { |
| 115 internal::g_io_thread_task_runner->PostTask( | 115 internal::g_io_thread_task_runner->PostTask( |
| 116 FROM_HERE, base::Bind(&MessagePipeDispatcher::InitOnIO, this)); | 116 FROM_HERE, base::Bind(&MessagePipeDispatcher::InitOnIO, this)); |
| 117 } else { | 117 } else { |
| 118 InitOnIO(); | 118 InitOnIO(); |
| 119 } | 119 } |
| 120 // TODO(jam): optimize for when running on IO thread? | 120 // TODO(jam): optimize for when running on IO thread? |
| 121 } else { |
| 122 error_ = true; |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 void MessagePipeDispatcher::InitOnIO() { | 126 void MessagePipeDispatcher::InitOnIO() { |
| 125 base::AutoLock locker(lock()); | 127 base::AutoLock locker(lock()); |
| 126 calling_init_ = true; | 128 calling_init_ = true; |
| 127 if (channel_) | 129 if (channel_) |
| 128 channel_->Init(this); | 130 channel_->Init(this); |
| 129 calling_init_ = false; | 131 calling_init_ = false; |
| 130 } | 132 } |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 serialization->shared_memory_size)); | 631 serialization->shared_memory_size)); |
| 630 scoped_ptr<PlatformSharedBufferMapping> mapping( | 632 scoped_ptr<PlatformSharedBufferMapping> mapping( |
| 631 shared_buffer->Map(0, serialization->shared_memory_size)); | 633 shared_buffer->Map(0, serialization->shared_memory_size)); |
| 632 char* start = static_cast<char*>(mapping->GetBase()); | 634 char* start = static_cast<char*>(mapping->GetBase()); |
| 633 start = SerializeBuffer(start, &serialized_read_buffer_); | 635 start = SerializeBuffer(start, &serialized_read_buffer_); |
| 634 start = SerializeBuffer(start, &serialized_write_buffer_); | 636 start = SerializeBuffer(start, &serialized_write_buffer_); |
| 635 start = SerializeBuffer(start, &serialized_message_queue_); | 637 start = SerializeBuffer(start, &serialized_message_queue_); |
| 636 | 638 |
| 637 serialization->shared_memory_handle_index = platform_handles->size(); | 639 serialization->shared_memory_handle_index = platform_handles->size(); |
| 638 platform_handles->push_back(shared_buffer->PassPlatformHandle().release()); | 640 platform_handles->push_back(shared_buffer->PassPlatformHandle().release()); |
| 641 } else { |
| 642 serialization->shared_memory_handle_index = kInvalidMessagePipeHandleIndex; |
| 639 } | 643 } |
| 640 | 644 |
| 641 *actual_size = sizeof(SerializedMessagePipeHandleDispatcher); | 645 *actual_size = sizeof(SerializedMessagePipeHandleDispatcher); |
| 642 return true; | 646 return true; |
| 643 } | 647 } |
| 644 | 648 |
| 645 void MessagePipeDispatcher::TransportStarted() { | 649 void MessagePipeDispatcher::TransportStarted() { |
| 646 started_transport_.Acquire(); | 650 started_transport_.Acquire(); |
| 647 } | 651 } |
| 648 | 652 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 case ERROR_WRITE: | 718 case ERROR_WRITE: |
| 715 // Write errors are slightly notable: they probably shouldn't happen under | 719 // Write errors are slightly notable: they probably shouldn't happen under |
| 716 // normal operation (but maybe the other side crashed). | 720 // normal operation (but maybe the other side crashed). |
| 717 LOG(WARNING) << "MessagePipeDispatcher write error"; | 721 LOG(WARNING) << "MessagePipeDispatcher write error"; |
| 718 break; | 722 break; |
| 719 } | 723 } |
| 720 | 724 |
| 721 error_ = true; | 725 error_ = true; |
| 722 if (started_transport_.Try()) { | 726 if (started_transport_.Try()) { |
| 723 base::AutoLock locker(lock()); | 727 base::AutoLock locker(lock()); |
| 728 // We can get two OnError callbacks before the post task below completes. |
| 729 // Although RawChannel still has a pointer to this object until Shutdown is |
| 730 // called, that is safe since this class always does a PostTask to the IO |
| 731 // thread to self destruct. |
| 732 if (!channel_) |
| 733 return; |
| 734 |
| 724 awakable_list_.AwakeForStateChange(GetHandleSignalsStateImplNoLock()); | 735 awakable_list_.AwakeForStateChange(GetHandleSignalsStateImplNoLock()); |
| 725 | 736 |
| 726 base::MessageLoop::current()->PostTask( | 737 base::MessageLoop::current()->PostTask( |
| 727 FROM_HERE, | 738 FROM_HERE, |
| 728 base::Bind(&RawChannel::Shutdown, base::Unretained(channel_))); | 739 base::Bind(&RawChannel::Shutdown, base::Unretained(channel_))); |
| 729 channel_ = nullptr; | 740 channel_ = nullptr; |
| 730 started_transport_.Release(); | 741 started_transport_.Release(); |
| 731 } else { | 742 } else { |
| 732 // We must be waiting to call ReleaseHandle. It will call Shutdown. | 743 // We must be waiting to call ReleaseHandle. It will call Shutdown. |
| 733 } | 744 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 LOG(WARNING) << "Enqueueing null dispatcher"; | 782 LOG(WARNING) << "Enqueueing null dispatcher"; |
| 772 dispatchers->push_back(nullptr); | 783 dispatchers->push_back(nullptr); |
| 773 } | 784 } |
| 774 } | 785 } |
| 775 message->SetDispatchers(dispatchers.Pass()); | 786 message->SetDispatchers(dispatchers.Pass()); |
| 776 return MOJO_RESULT_OK; | 787 return MOJO_RESULT_OK; |
| 777 } | 788 } |
| 778 | 789 |
| 779 } // namespace edk | 790 } // namespace edk |
| 780 } // namespace mojo | 791 } // namespace mojo |
| OLD | NEW |