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

Side by Side Diff: mojo/public/cpp/bindings/lib/control_message_proxy.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_proxy.h" 5 #include "mojo/public/cpp/bindings/lib/control_message_proxy.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/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/run_loop.h"
13 #include "mojo/public/cpp/bindings/lib/message_builder.h" 14 #include "mojo/public/cpp/bindings/lib/message_builder.h"
14 #include "mojo/public/cpp/bindings/lib/serialization.h" 15 #include "mojo/public/cpp/bindings/lib/serialization.h"
15 #include "mojo/public/cpp/bindings/message.h" 16 #include "mojo/public/cpp/bindings/message.h"
16 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" 17 #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
17 18
18 namespace mojo { 19 namespace mojo {
19 namespace internal { 20 namespace internal {
20 21
21 namespace { 22 namespace {
22 23
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 void RunVersionCallback( 90 void RunVersionCallback(
90 const base::Callback<void(uint32_t)>& callback, 91 const base::Callback<void(uint32_t)>& callback,
91 interface_control::RunResponseMessageParamsPtr run_response) { 92 interface_control::RunResponseMessageParamsPtr run_response) {
92 uint32_t version = 0u; 93 uint32_t version = 0u;
93 if (run_response->output && run_response->output->is_query_version_result()) 94 if (run_response->output && run_response->output->is_query_version_result())
94 version = run_response->output->get_query_version_result()->version; 95 version = run_response->output->get_query_version_result()->version;
95 callback.Run(version); 96 callback.Run(version);
96 } 97 }
97 98
99 void RunClosure(const base::Closure& callback,
100 interface_control::RunResponseMessageParamsPtr run_response) {
101 callback.Run();
102 }
103
98 } // namespace 104 } // namespace
99 105
100 ControlMessageProxy::ControlMessageProxy(MessageReceiverWithResponder* receiver) 106 ControlMessageProxy::ControlMessageProxy(MessageReceiverWithResponder* receiver)
101 : receiver_(receiver) { 107 : receiver_(receiver) {
102 } 108 }
103 109
110 ControlMessageProxy::~ControlMessageProxy() = default;
111
104 void ControlMessageProxy::QueryVersion( 112 void ControlMessageProxy::QueryVersion(
105 const base::Callback<void(uint32_t)>& callback) { 113 const base::Callback<void(uint32_t)>& callback) {
106 auto input_ptr = interface_control::RunInput::New(); 114 auto input_ptr = interface_control::RunInput::New();
107 input_ptr->set_query_version(interface_control::QueryVersion::New()); 115 input_ptr->set_query_version(interface_control::QueryVersion::New());
108 SendRunMessage(receiver_, std::move(input_ptr), 116 SendRunMessage(receiver_, std::move(input_ptr),
109 base::Bind(&RunVersionCallback, callback), &context_); 117 base::Bind(&RunVersionCallback, callback), &context_);
110 } 118 }
111 119
112 void ControlMessageProxy::RequireVersion(uint32_t version) { 120 void ControlMessageProxy::RequireVersion(uint32_t version) {
113 auto require_version = interface_control::RequireVersion::New(); 121 auto require_version = interface_control::RequireVersion::New();
114 require_version->version = version; 122 require_version->version = version;
115 auto input_ptr = interface_control::RunOrClosePipeInput::New(); 123 auto input_ptr = interface_control::RunOrClosePipeInput::New();
116 input_ptr->set_require_version(std::move(require_version)); 124 input_ptr->set_require_version(std::move(require_version));
117 SendRunOrClosePipeMessage(receiver_, std::move(input_ptr), &context_); 125 SendRunOrClosePipeMessage(receiver_, std::move(input_ptr), &context_);
118 } 126 }
119 127
128 void ControlMessageProxy::FlushForTesting() {
129 auto input_ptr = interface_control::RunInput::New();
130 input_ptr->set_flush_for_testing(interface_control::FlushForTesting::New());
131 base::RunLoop run_loop;
132 run_loop_quit_closure_ = run_loop.QuitClosure();
133 SendRunMessage(
134 receiver_, std::move(input_ptr),
135 base::Bind(&RunClosure,
136 base::Bind(&ControlMessageProxy::RunFlushForTestingClosure,
137 base::Unretained(this))),
138 &context_);
139 run_loop.Run();
140 }
141
142 void ControlMessageProxy::RunFlushForTestingClosure() {
143 DCHECK(!run_loop_quit_closure_.is_null());
144 run_loop_quit_closure_.Run();
145 run_loop_quit_closure_.Reset();
146 }
147
148 void ControlMessageProxy::OnConnectionError() {
149 if (!run_loop_quit_closure_.is_null())
150 RunFlushForTestingClosure();
151 }
152
120 } // namespace internal 153 } // namespace internal
121 } // namespace mojo 154 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698