| 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/lib/pipe_control_message_handler.h" | 5 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/public/cpp/bindings/lib/message_builder.h" | 8 #include "mojo/public/cpp/bindings/lib/message_builder.h" |
| 9 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" | 9 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" |
| 10 #include "mojo/public/cpp/bindings/lib/serialization.h" | 10 #include "mojo/public/cpp/bindings/lib/serialization.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validation_util.h" | 11 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
| 12 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" | 12 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 PipeControlMessageHandler::PipeControlMessageHandler( | 17 PipeControlMessageHandler::PipeControlMessageHandler( |
| 18 PipeControlMessageHandlerDelegate* delegate) | 18 PipeControlMessageHandlerDelegate* delegate) |
| 19 : delegate_(delegate) {} | 19 : delegate_(delegate) {} |
| 20 | 20 |
| 21 PipeControlMessageHandler::~PipeControlMessageHandler() {} | 21 PipeControlMessageHandler::~PipeControlMessageHandler() {} |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { | 24 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { |
| 25 return !IsValidInterfaceId(message->interface_id()); | 25 return !IsValidInterfaceId(message->interface_id()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool PipeControlMessageHandler::Accept(Message* message) { | 28 MessageReceiver::Result PipeControlMessageHandler::Accept(Message* message) { |
| 29 if (!Validate(message)) | 29 Result result = Validate(message); |
| 30 return false; | 30 if (!result.Succeeded()) |
| 31 return result; |
| 31 | 32 |
| 32 if (message->name() == pipe_control::kRunOrClosePipeMessageId) | 33 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { |
| 33 return RunOrClosePipe(message); | 34 if (RunOrClosePipe(message)) |
| 35 return Result::ForSuccess(); |
| 36 return Result::ForBadControlMessage(interface_name_, message); |
| 37 } |
| 34 | 38 |
| 35 NOTREACHED(); | 39 NOTREACHED(); |
| 36 return false; | 40 return Result::ForUnknownError(); |
| 37 } | 41 } |
| 38 | 42 |
| 39 bool PipeControlMessageHandler::Validate(const Message* message) { | 43 MessageReceiver::Result PipeControlMessageHandler::Validate(Message* message) { |
| 40 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { | 44 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { |
| 41 if (!ValidateMessageIsRequestWithoutResponse(message)) | 45 if (!ValidateMessageIsRequestWithoutResponse(message)) |
| 42 return false; | 46 return Result::ForBadControlMessage(interface_name_, message); |
| 43 return ValidateMessagePayload< | 47 if (!ValidateMessagePayload< |
| 44 pipe_control::internal::RunOrClosePipeMessageParams_Data>(message); | 48 pipe_control::internal::RunOrClosePipeMessageParams_Data>(message)) |
| 49 return Result::ForBadControlMessage(interface_name_, message); |
| 50 return Result::ForSuccess(); |
| 45 } | 51 } |
| 46 | 52 |
| 47 return false; | 53 return Result::ForBadControlMessage(interface_name_, message); |
| 48 } | 54 } |
| 49 | 55 |
| 50 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { | 56 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { |
| 51 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = | 57 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = |
| 52 reinterpret_cast< | 58 reinterpret_cast< |
| 53 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( | 59 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( |
| 54 message->mutable_payload()); | 60 message->mutable_payload()); |
| 55 params->DecodePointers(); | 61 params->DecodePointers(); |
| 56 | 62 |
| 57 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr; | 63 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 ->id); | 74 ->id); |
| 69 } | 75 } |
| 70 | 76 |
| 71 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " | 77 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " |
| 72 << "message. Closing the pipe."; | 78 << "message. Closing the pipe."; |
| 73 return false; | 79 return false; |
| 74 } | 80 } |
| 75 | 81 |
| 76 } // namespace internal | 82 } // namespace internal |
| 77 } // namespace mojo | 83 } // namespace mojo |
| OLD | NEW |