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/error.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/pipe_control_message_handler_delegate.h" | 10 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" |
10 #include "mojo/public/cpp/bindings/lib/serialization.h" | 11 #include "mojo/public/cpp/bindings/lib/serialization.h" |
11 #include "mojo/public/cpp/bindings/lib/validation_util.h" | 12 #include "mojo/public/cpp/bindings/lib/validation_util.h" |
12 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" | 13 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 PipeControlMessageHandler::PipeControlMessageHandler( | 18 PipeControlMessageHandler::PipeControlMessageHandler( |
18 PipeControlMessageHandlerDelegate* delegate) | 19 PipeControlMessageHandlerDelegate* delegate) |
19 : delegate_(delegate) {} | 20 : delegate_(delegate) {} |
20 | 21 |
21 PipeControlMessageHandler::~PipeControlMessageHandler() {} | 22 PipeControlMessageHandler::~PipeControlMessageHandler() {} |
22 | 23 |
23 // static | 24 // static |
24 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { | 25 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { |
25 return !IsValidInterfaceId(message->interface_id()); | 26 return !IsValidInterfaceId(message->interface_id()); |
26 } | 27 } |
27 | 28 |
28 bool PipeControlMessageHandler::Accept(Message* message) { | 29 bool PipeControlMessageHandler::Accept(Message* message, Error* error) { |
29 if (!Validate(message)) | 30 if (!Validate(message, error)) |
30 return false; | 31 return false; |
31 | 32 |
32 if (message->name() == pipe_control::kRunOrClosePipeMessageId) | 33 if (message->name() == pipe_control::kRunOrClosePipeMessageId) |
33 return RunOrClosePipe(message); | 34 return RunOrClosePipe(message); |
34 | 35 |
35 NOTREACHED(); | 36 NOTREACHED(); |
36 return false; | 37 return false; |
37 } | 38 } |
38 | 39 |
39 bool PipeControlMessageHandler::Validate(const Message* message) { | 40 bool PipeControlMessageHandler::Validate(Message* message, Error* error) { |
40 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { | 41 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { |
41 if (!ValidateMessageIsRequestWithoutResponse(message)) | 42 if (!ValidateMessageIsRequestWithoutResponse(message)) { |
| 43 *error = Error::ForBadMessage("Invalid pipe control request", message); |
42 return false; | 44 return false; |
| 45 } |
43 return ValidateMessagePayload< | 46 return ValidateMessagePayload< |
44 pipe_control::internal::RunOrClosePipeMessageParams_Data>(message); | 47 pipe_control::internal::RunOrClosePipeMessageParams_Data>(message); |
45 } | 48 } |
46 | 49 |
47 return false; | 50 return false; |
48 } | 51 } |
49 | 52 |
50 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { | 53 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { |
51 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = | 54 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = |
52 reinterpret_cast< | 55 reinterpret_cast< |
(...skipping 15 matching lines...) Expand all Loading... |
68 ->id); | 71 ->id); |
69 } | 72 } |
70 | 73 |
71 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " | 74 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " |
72 << "message. Closing the pipe."; | 75 << "message. Closing the pipe."; |
73 return false; | 76 return false; |
74 } | 77 } |
75 | 78 |
76 } // namespace internal | 79 } // namespace internal |
77 } // namespace mojo | 80 } // namespace mojo |
OLD | NEW |