| 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/node_channel.h" | 5 #include "mojo/edk/system/node_channel.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector()); | 352 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector()); |
| 353 if (channel_handle.is_valid()) | 353 if (channel_handle.is_valid()) |
| 354 handles->push_back(channel_handle.release()); | 354 handles->push_back(channel_handle.release()); |
| 355 Channel::MessagePtr message = CreateMessage( | 355 Channel::MessagePtr message = CreateMessage( |
| 356 MessageType::INTRODUCE, sizeof(IntroductionData), handles->size(), &data); | 356 MessageType::INTRODUCE, sizeof(IntroductionData), handles->size(), &data); |
| 357 message->SetHandles(std::move(handles)); | 357 message->SetHandles(std::move(handles)); |
| 358 data->name = name; | 358 data->name = name; |
| 359 WriteChannelMessage(std::move(message)); | 359 WriteChannelMessage(std::move(message)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void NodeChannel::Broadcast(Channel::MessagePtr message) { |
| 363 DCHECK(!message->has_handles()); |
| 364 void* data; |
| 365 Channel::MessagePtr broadcast_message = CreateMessage( |
| 366 MessageType::BROADCAST, message->data_num_bytes(), 0, &data); |
| 367 memcpy(data, message->data(), message->data_num_bytes()); |
| 368 WriteChannelMessage(std::move(broadcast_message)); |
| 369 } |
| 370 |
| 362 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 371 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 363 void NodeChannel::RelayPortsMessage(const ports::NodeName& destination, | 372 void NodeChannel::RelayPortsMessage(const ports::NodeName& destination, |
| 364 Channel::MessagePtr message) { | 373 Channel::MessagePtr message) { |
| 365 #if defined(OS_WIN) | 374 #if defined(OS_WIN) |
| 366 DCHECK(message->has_handles()); | 375 DCHECK(message->has_handles()); |
| 367 | 376 |
| 368 // Note that this is only used on Windows, and on Windows all platform | 377 // Note that this is only used on Windows, and on Windows all platform |
| 369 // handles are included in the message data. We blindly copy all the data | 378 // handles are included in the message data. We blindly copy all the data |
| 370 // here and the relay node (the parent) will duplicate handles as needed. | 379 // here and the relay node (the parent) will duplicate handles as needed. |
| 371 size_t num_bytes = sizeof(RelayPortsMessageData) + message->data_num_bytes(); | 380 size_t num_bytes = sizeof(RelayPortsMessageData) + message->data_num_bytes(); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 677 } |
| 669 #endif | 678 #endif |
| 670 delegate_->OnRelayPortsMessage(remote_node_name_, from_process, | 679 delegate_->OnRelayPortsMessage(remote_node_name_, from_process, |
| 671 data->destination, std::move(message)); | 680 data->destination, std::move(message)); |
| 672 return; | 681 return; |
| 673 } | 682 } |
| 674 break; | 683 break; |
| 675 } | 684 } |
| 676 #endif | 685 #endif |
| 677 | 686 |
| 678 case MessageType::BROADCAST: | 687 case MessageType::BROADCAST: { |
| 679 // This is here as a placeholder for now because nothing sends a BROADCAST | 688 if (payload_size <= sizeof(Header)) |
| 680 // message yet. This avoids breakage on version skew (namely for ARC) when | 689 break; |
| 681 // we actually begin using the message. | 690 const void* data = static_cast<const void*>( |
| 682 DVLOG(1) << "Ignoring unhandled BROADCAST message."; | 691 reinterpret_cast<const Header*>(payload) + 1); |
| 692 Channel::MessagePtr message = |
| 693 Channel::Message::Deserialize(data, payload_size - sizeof(Header)); |
| 694 if (!message || message->has_handles()) { |
| 695 DLOG(ERROR) << "Dropping invalid broadcast message."; |
| 696 break; |
| 697 } |
| 698 delegate_->OnBroadcast(remote_node_name_, std::move(message)); |
| 683 return; | 699 return; |
| 700 } |
| 684 | 701 |
| 685 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) | 702 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 686 case MessageType::PORTS_MESSAGE_FROM_RELAY: | 703 case MessageType::PORTS_MESSAGE_FROM_RELAY: |
| 687 const PortsMessageFromRelayData* data; | 704 const PortsMessageFromRelayData* data; |
| 688 if (GetMessagePayload(payload, payload_size, &data)) { | 705 if (GetMessagePayload(payload, payload_size, &data)) { |
| 689 size_t num_bytes = payload_size - sizeof(*data); | 706 size_t num_bytes = payload_size - sizeof(*data); |
| 690 if (num_bytes < sizeof(Header)) | 707 if (num_bytes < sizeof(Header)) |
| 691 break; | 708 break; |
| 692 num_bytes -= sizeof(Header); | 709 num_bytes -= sizeof(Header); |
| 693 | 710 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 861 |
| 845 base::AutoLock lock(channel_lock_); | 862 base::AutoLock lock(channel_lock_); |
| 846 if (!channel_) | 863 if (!channel_) |
| 847 DLOG(ERROR) << "Dropping message on closed channel."; | 864 DLOG(ERROR) << "Dropping message on closed channel."; |
| 848 else | 865 else |
| 849 channel_->Write(std::move(message)); | 866 channel_->Write(std::move(message)); |
| 850 } | 867 } |
| 851 | 868 |
| 852 } // namespace edk | 869 } // namespace edk |
| 853 } // namespace mojo | 870 } // namespace mojo |
| OLD | NEW |