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

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

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 3 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/control_message_handler.h" 5 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "mojo/public/cpp/bindings/lib/message_builder.h" 12 #include "mojo/public/cpp/bindings/lib/message_builder.h"
13 #include "mojo/public/cpp/bindings/lib/serialization.h" 13 #include "mojo/public/cpp/bindings/lib/serialization.h"
14 #include "mojo/public/cpp/bindings/lib/validation_util.h"
14 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" 15 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 namespace internal { 18 namespace internal {
19 namespace {
20
21 bool ValidateControlRequestWithResponse(Message* message) {
22 ValidationContext validation_context(
23 message->data(), message->data_num_bytes(), message->handles()->size(),
24 message, "ControlRequestValidator");
25 if (!ValidateMessageIsRequestExpectingResponse(message, &validation_context))
26 return false;
27
28 switch (message->header()->name) {
29 case interface_control::kRunMessageId:
30 return ValidateMessagePayload<
31 interface_control::internal::RunMessageParams_Data>(
32 message, &validation_context);
33 }
34 return false;
35 }
36
37 bool ValidateControlRequestWithoutResponse(Message* message) {
38 ValidationContext validation_context(
39 message->data(), message->data_num_bytes(), message->handles()->size(),
40 message, "ControlRequestValidator");
41 if (!ValidateMessageIsRequestWithoutResponse(message, &validation_context))
42 return false;
43
44 switch (message->header()->name) {
45 case interface_control::kRunOrClosePipeMessageId:
46 return ValidateMessageIsRequestWithoutResponse(message,
47 &validation_context) &&
48 ValidateMessagePayload<
49 interface_control::internal::RunOrClosePipeMessageParams_Data>(
50 message, &validation_context);
51 }
52 return false;
53 }
54
55 } // namespace
18 56
19 // static 57 // static
20 bool ControlMessageHandler::IsControlMessage(const Message* message) { 58 bool ControlMessageHandler::IsControlMessage(const Message* message) {
21 return message->header()->name == interface_control::kRunMessageId || 59 return message->header()->name == interface_control::kRunMessageId ||
22 message->header()->name == interface_control::kRunOrClosePipeMessageId; 60 message->header()->name == interface_control::kRunOrClosePipeMessageId;
23 } 61 }
24 62
25 ControlMessageHandler::ControlMessageHandler(uint32_t interface_version) 63 ControlMessageHandler::ControlMessageHandler(uint32_t interface_version)
26 : interface_version_(interface_version) { 64 : interface_version_(interface_version) {
27 } 65 }
28 66
29 ControlMessageHandler::~ControlMessageHandler() { 67 ControlMessageHandler::~ControlMessageHandler() {
30 } 68 }
31 69
32 bool ControlMessageHandler::Accept(Message* message) { 70 bool ControlMessageHandler::Accept(Message* message) {
71 if (!ValidateControlRequestWithoutResponse(message))
72 return false;
73
33 if (message->header()->name == interface_control::kRunOrClosePipeMessageId) 74 if (message->header()->name == interface_control::kRunOrClosePipeMessageId)
34 return RunOrClosePipe(message); 75 return RunOrClosePipe(message);
35 76
36 NOTREACHED(); 77 NOTREACHED();
37 return false; 78 return false;
38 } 79 }
39 80
40 bool ControlMessageHandler::AcceptWithResponder( 81 bool ControlMessageHandler::AcceptWithResponder(
41 Message* message, 82 Message* message,
42 MessageReceiverWithStatus* responder) { 83 MessageReceiverWithStatus* responder) {
84 if (!ValidateControlRequestWithResponse(message))
85 return false;
86
43 if (message->header()->name == interface_control::kRunMessageId) 87 if (message->header()->name == interface_control::kRunMessageId)
44 return Run(message, responder); 88 return Run(message, responder);
45 89
46 NOTREACHED(); 90 NOTREACHED();
47 return false; 91 return false;
48 } 92 }
49 93
50 bool ControlMessageHandler::Run(Message* message, 94 bool ControlMessageHandler::Run(Message* message,
51 MessageReceiverWithStatus* responder) { 95 MessageReceiverWithStatus* responder) {
52 interface_control::internal::RunMessageParams_Data* params = 96 interface_control::internal::RunMessageParams_Data* params =
53 reinterpret_cast<interface_control::internal::RunMessageParams_Data*>( 97 reinterpret_cast<interface_control::internal::RunMessageParams_Data*>(
54 message->mutable_payload()); 98 message->mutable_payload());
55 interface_control::RunMessageParamsPtr params_ptr; 99 interface_control::RunMessageParamsPtr params_ptr;
56 Deserialize<interface_control::RunMessageParamsDataView>(params, &params_ptr, 100 Deserialize<interface_control::RunMessageParamsDataView>(params, &params_ptr,
57 &context_); 101 &context_);
58 auto& input = *params_ptr->input; 102 auto& input = *params_ptr->input;
59 interface_control::RunOutputPtr output = interface_control::RunOutput::New(); 103 interface_control::RunOutputPtr output = interface_control::RunOutput::New();
60 if (input.is_query_version()) { 104 if (input.is_query_version()) {
61 output->set_query_version_result( 105 output->set_query_version_result(
62 interface_control::QueryVersionResult::New()); 106 interface_control::QueryVersionResult::New());
63 output->get_query_version_result()->version = interface_version_; 107 output->get_query_version_result()->version = interface_version_;
108 } else if (input.is_flush_for_testing()) {
109 output.reset();
64 } else { 110 } else {
65 output.reset(); 111 output.reset();
66 } 112 }
67 113
68 auto response_params_ptr = interface_control::RunResponseMessageParams::New(); 114 auto response_params_ptr = interface_control::RunResponseMessageParams::New();
69 response_params_ptr->output = std::move(output); 115 response_params_ptr->output = std::move(output);
70 size_t size = 116 size_t size =
71 PrepareToSerialize<interface_control::RunResponseMessageParamsDataView>( 117 PrepareToSerialize<interface_control::RunResponseMessageParamsDataView>(
72 response_params_ptr, &context_); 118 response_params_ptr, &context_);
73 ResponseMessageBuilder builder(interface_control::kRunMessageId, size, 119 ResponseMessageBuilder builder(interface_control::kRunMessageId, size,
(...skipping 20 matching lines...) Expand all
94 params, &params_ptr, &context_); 140 params, &params_ptr, &context_);
95 auto& input = *params_ptr->input; 141 auto& input = *params_ptr->input;
96 if (input.is_require_version()) 142 if (input.is_require_version())
97 return interface_version_ >= input.get_require_version()->version; 143 return interface_version_ >= input.get_require_version()->version;
98 144
99 return false; 145 return false;
100 } 146 }
101 147
102 } // namespace internal 148 } // namespace internal
103 } // namespace mojo 149 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.cc ('k') | mojo/public/cpp/bindings/lib/control_message_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698