| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/broker_host.h" | 5 #include "mojo/edk/system/broker_host.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 handles->at(0) = buffer->PassPlatformHandle().release(); | 75 handles->at(0) = buffer->PassPlatformHandle().release(); |
| 76 message->SetHandles(std::move(handles)); | 76 message->SetHandles(std::move(handles)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 channel_->Write(std::move(message)); | 79 channel_->Write(std::move(message)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void BrokerHost::OnChannelMessage(const void* payload, | 82 void BrokerHost::OnChannelMessage(const void* payload, |
| 83 size_t payload_size, | 83 size_t payload_size, |
| 84 ScopedPlatformHandleVectorPtr handles) { | 84 ScopedPlatformHandleVectorPtr handles) { |
| 85 if (payload_size < sizeof(BrokerMessageHeader)) |
| 86 return; |
| 87 |
| 85 const BrokerMessageHeader* header = | 88 const BrokerMessageHeader* header = |
| 86 static_cast<const BrokerMessageHeader*>(payload); | 89 static_cast<const BrokerMessageHeader*>(payload); |
| 87 switch (header->type) { | 90 switch (header->type) { |
| 88 case BrokerMessageType::BUFFER_REQUEST: { | 91 case BrokerMessageType::BUFFER_REQUEST: |
| 89 const BufferRequestData* request = | 92 if (payload_size == |
| 90 reinterpret_cast<const BufferRequestData*>(header + 1); | 93 sizeof(BrokerMessageHeader) + sizeof(BufferRequestData)) { |
| 91 OnBufferRequest(request->size); | 94 const BufferRequestData* request = |
| 95 reinterpret_cast<const BufferRequestData*>(header + 1); |
| 96 OnBufferRequest(request->size); |
| 97 return; |
| 98 } |
| 92 break; | 99 break; |
| 93 } | 100 |
| 94 default: | 101 default: |
| 95 LOG(ERROR) << "Unexpected broker message type: " << header->type; | |
| 96 break; | 102 break; |
| 97 } | 103 } |
| 104 |
| 105 LOG(ERROR) << "Unexpected broker message type: " << header->type; |
| 98 } | 106 } |
| 99 | 107 |
| 100 void BrokerHost::OnChannelError() { | 108 void BrokerHost::OnChannelError() { |
| 101 if (channel_) { | 109 if (channel_) { |
| 102 channel_->ShutDown(); | 110 channel_->ShutDown(); |
| 103 channel_ = nullptr; | 111 channel_ = nullptr; |
| 104 } | 112 } |
| 105 | 113 |
| 106 delete this; | 114 delete this; |
| 107 } | 115 } |
| 108 | 116 |
| 109 void BrokerHost::WillDestroyCurrentMessageLoop() { | 117 void BrokerHost::WillDestroyCurrentMessageLoop() { |
| 110 delete this; | 118 delete this; |
| 111 } | 119 } |
| 112 | 120 |
| 113 } // namespace edk | 121 } // namespace edk |
| 114 } // namespace mojo | 122 } // namespace mojo |
| OLD | NEW |