| 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/public/cpp/bindings/pipe_control_message_handler.h" | 5 #include "mojo/public/cpp/bindings/pipe_control_message_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/public/cpp/bindings/interface_id.h" |
| 8 #include "mojo/public/cpp/bindings/lib/message_builder.h" | 9 #include "mojo/public/cpp/bindings/lib/message_builder.h" |
| 9 #include "mojo/public/cpp/bindings/lib/serialization.h" | 10 #include "mojo/public/cpp/bindings/lib/serialization.h" |
| 11 #include "mojo/public/cpp/bindings/lib/serialization_context.h" |
| 10 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 12 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validation_util.h" | 13 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
| 12 #include "mojo/public/cpp/bindings/pipe_control_message_handler_delegate.h" | 14 #include "mojo/public/cpp/bindings/pipe_control_message_handler_delegate.h" |
| 13 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" | 15 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" |
| 14 | 16 |
| 15 namespace mojo { | 17 namespace mojo { |
| 16 | 18 |
| 17 PipeControlMessageHandler::PipeControlMessageHandler( | 19 PipeControlMessageHandler::PipeControlMessageHandler( |
| 18 PipeControlMessageHandlerDelegate* delegate) | 20 PipeControlMessageHandlerDelegate* delegate) |
| 19 : delegate_(delegate) {} | 21 : delegate_(delegate) {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 34 return false; | 36 return false; |
| 35 | 37 |
| 36 if (message->name() == pipe_control::kRunOrClosePipeMessageId) | 38 if (message->name() == pipe_control::kRunOrClosePipeMessageId) |
| 37 return RunOrClosePipe(message); | 39 return RunOrClosePipe(message); |
| 38 | 40 |
| 39 NOTREACHED(); | 41 NOTREACHED(); |
| 40 return false; | 42 return false; |
| 41 } | 43 } |
| 42 | 44 |
| 43 bool PipeControlMessageHandler::Validate(Message* message) { | 45 bool PipeControlMessageHandler::Validate(Message* message) { |
| 44 internal::ValidationContext validation_context( | 46 internal::ValidationContext validation_context(message->payload(), |
| 45 message->data(), message->data_num_bytes(), 0, message, description_); | 47 message->payload_num_bytes(), |
| 48 0, 0, message, description_); |
| 46 | 49 |
| 47 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { | 50 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { |
| 48 if (!internal::ValidateMessageIsRequestWithoutResponse( | 51 if (!internal::ValidateMessageIsRequestWithoutResponse( |
| 49 message, &validation_context)) { | 52 message, &validation_context)) { |
| 50 return false; | 53 return false; |
| 51 } | 54 } |
| 52 return internal::ValidateMessagePayload< | 55 return internal::ValidateMessagePayload< |
| 53 pipe_control::internal::RunOrClosePipeMessageParams_Data>( | 56 pipe_control::internal::RunOrClosePipeMessageParams_Data>( |
| 54 message, &validation_context); | 57 message, &validation_context); |
| 55 } | 58 } |
| 56 | 59 |
| 57 return false; | 60 return false; |
| 58 } | 61 } |
| 59 | 62 |
| 60 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { | 63 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { |
| 64 internal::SerializationContext context; |
| 61 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = | 65 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = |
| 62 reinterpret_cast< | 66 reinterpret_cast< |
| 63 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( | 67 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( |
| 64 message->mutable_payload()); | 68 message->mutable_payload()); |
| 65 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr; | 69 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr; |
| 66 internal::Deserialize<pipe_control::RunOrClosePipeMessageParamsDataView>( | 70 internal::Deserialize<pipe_control::RunOrClosePipeMessageParamsDataView>( |
| 67 params, ¶ms_ptr, &context_); | 71 params, ¶ms_ptr, &context); |
| 68 | 72 |
| 69 if (params_ptr->input->is_peer_associated_endpoint_closed_event()) { | 73 if (params_ptr->input->is_peer_associated_endpoint_closed_event()) { |
| 70 const auto& event = | 74 const auto& event = |
| 71 params_ptr->input->get_peer_associated_endpoint_closed_event(); | 75 params_ptr->input->get_peer_associated_endpoint_closed_event(); |
| 72 | 76 |
| 73 base::Optional<DisconnectReason> reason; | 77 base::Optional<DisconnectReason> reason; |
| 74 if (event->disconnect_reason) { | 78 if (event->disconnect_reason) { |
| 75 reason.emplace(event->disconnect_reason->custom_reason, | 79 reason.emplace(event->disconnect_reason->custom_reason, |
| 76 event->disconnect_reason->description); | 80 event->disconnect_reason->description); |
| 77 } | 81 } |
| 78 return delegate_->OnPeerAssociatedEndpointClosed(event->id, reason); | 82 return delegate_->OnPeerAssociatedEndpointClosed(event->id, reason); |
| 79 } | 83 } |
| 80 if (params_ptr->input->is_associated_endpoint_closed_before_sent_event()) { | 84 if (params_ptr->input->is_associated_endpoint_closed_before_sent_event()) { |
| 81 return delegate_->OnAssociatedEndpointClosedBeforeSent( | 85 return delegate_->OnAssociatedEndpointClosedBeforeSent( |
| 82 params_ptr->input->get_associated_endpoint_closed_before_sent_event() | 86 params_ptr->input->get_associated_endpoint_closed_before_sent_event() |
| 83 ->id); | 87 ->id); |
| 84 } | 88 } |
| 85 | 89 |
| 86 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " | 90 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " |
| 87 << "message. Closing the pipe."; | 91 << "message. Closing the pipe."; |
| 88 return false; | 92 return false; |
| 89 } | 93 } |
| 90 | 94 |
| 91 } // namespace mojo | 95 } // namespace mojo |
| OLD | NEW |