Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Side by Side Diff: mojo/public/cpp/bindings/lib/pipe_control_message_handler.cc

Issue 2114523002: Move more Mojo bindings helpers out of internal namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@group-controller
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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"
10 #include "mojo/public/cpp/bindings/lib/serialization.h" 9 #include "mojo/public/cpp/bindings/lib/serialization.h"
11 #include "mojo/public/cpp/bindings/lib/validation_context.h" 10 #include "mojo/public/cpp/bindings/lib/validation_context.h"
12 #include "mojo/public/cpp/bindings/lib/validation_util.h" 11 #include "mojo/public/cpp/bindings/lib/validation_util.h"
12 #include "mojo/public/cpp/bindings/pipe_control_message_handler_delegate.h"
13 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h" 13 #include "mojo/public/interfaces/bindings/pipe_control_messages.mojom.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace internal {
17 16
18 PipeControlMessageHandler::PipeControlMessageHandler( 17 PipeControlMessageHandler::PipeControlMessageHandler(
19 PipeControlMessageHandlerDelegate* delegate) 18 PipeControlMessageHandlerDelegate* delegate)
20 : delegate_(delegate) {} 19 : delegate_(delegate) {}
21 20
22 PipeControlMessageHandler::~PipeControlMessageHandler() {} 21 PipeControlMessageHandler::~PipeControlMessageHandler() {}
23 22
24 void PipeControlMessageHandler::SetDescription(const std::string& description) { 23 void PipeControlMessageHandler::SetDescription(const std::string& description) {
25 description_ = description; 24 description_ = description;
26 } 25 }
27 26
28 // static 27 // static
29 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) { 28 bool PipeControlMessageHandler::IsPipeControlMessage(const Message* message) {
30 return !IsValidInterfaceId(message->interface_id()); 29 return !IsValidInterfaceId(message->interface_id());
31 } 30 }
32 31
33 bool PipeControlMessageHandler::Accept(Message* message) { 32 bool PipeControlMessageHandler::Accept(Message* message) {
34 if (!Validate(message)) 33 if (!Validate(message))
35 return false; 34 return false;
36 35
37 if (message->name() == pipe_control::kRunOrClosePipeMessageId) 36 if (message->name() == pipe_control::kRunOrClosePipeMessageId)
38 return RunOrClosePipe(message); 37 return RunOrClosePipe(message);
39 38
40 NOTREACHED(); 39 NOTREACHED();
41 return false; 40 return false;
42 } 41 }
43 42
44 bool PipeControlMessageHandler::Validate(Message* message) { 43 bool PipeControlMessageHandler::Validate(Message* message) {
45 ValidationContext validation_context( 44 internal::ValidationContext validation_context(
46 message->data(), message->data_num_bytes(), 0, message, description_); 45 message->data(), message->data_num_bytes(), 0, message, description_);
47 46
48 if (message->name() == pipe_control::kRunOrClosePipeMessageId) { 47 if (message->name() == pipe_control::kRunOrClosePipeMessageId) {
49 if (!ValidateMessageIsRequestWithoutResponse(message, &validation_context)) 48 if (!internal::ValidateMessageIsRequestWithoutResponse(
49 message, &validation_context)) {
50 return false; 50 return false;
51 return ValidateMessagePayload< 51 }
52 return internal::ValidateMessagePayload<
52 pipe_control::internal::RunOrClosePipeMessageParams_Data>( 53 pipe_control::internal::RunOrClosePipeMessageParams_Data>(
53 message, &validation_context); 54 message, &validation_context);
54 } 55 }
55 56
56 return false; 57 return false;
57 } 58 }
58 59
59 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) { 60 bool PipeControlMessageHandler::RunOrClosePipe(Message* message) {
60 pipe_control::internal::RunOrClosePipeMessageParams_Data* params = 61 pipe_control::internal::RunOrClosePipeMessageParams_Data* params =
61 reinterpret_cast< 62 reinterpret_cast<
62 pipe_control::internal::RunOrClosePipeMessageParams_Data*>( 63 pipe_control::internal::RunOrClosePipeMessageParams_Data*>(
63 message->mutable_payload()); 64 message->mutable_payload());
64 params->DecodePointers(); 65 params->DecodePointers();
65 66
66 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr; 67 pipe_control::RunOrClosePipeMessageParamsPtr params_ptr;
67 Deserialize<pipe_control::RunOrClosePipeMessageParamsPtr>(params, &params_ptr, 68 internal::Deserialize<pipe_control::RunOrClosePipeMessageParamsPtr>(
68 &context_); 69 params, &params_ptr, &context_);
69 70
70 if (params_ptr->input->is_peer_associated_endpoint_closed_event()) { 71 if (params_ptr->input->is_peer_associated_endpoint_closed_event()) {
71 return delegate_->OnPeerAssociatedEndpointClosed( 72 return delegate_->OnPeerAssociatedEndpointClosed(
72 params_ptr->input->get_peer_associated_endpoint_closed_event()->id); 73 params_ptr->input->get_peer_associated_endpoint_closed_event()->id);
73 } 74 }
74 if (params_ptr->input->is_associated_endpoint_closed_before_sent_event()) { 75 if (params_ptr->input->is_associated_endpoint_closed_before_sent_event()) {
75 return delegate_->OnAssociatedEndpointClosedBeforeSent( 76 return delegate_->OnAssociatedEndpointClosedBeforeSent(
76 params_ptr->input->get_associated_endpoint_closed_before_sent_event() 77 params_ptr->input->get_associated_endpoint_closed_before_sent_event()
77 ->id); 78 ->id);
78 } 79 }
79 80
80 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control " 81 DVLOG(1) << "Unsupported command in a RunOrClosePipe message pipe control "
81 << "message. Closing the pipe."; 82 << "message. Closing the pipe.";
82 return false; 83 return false;
83 } 84 }
84 85
85 } // namespace internal
86 } // namespace mojo 86 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698