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

Unified Diff: mojo/public/cpp/bindings/lib/control_message_proxy.cc

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/control_message_proxy.cc
diff --git a/mojo/public/cpp/bindings/lib/control_message_proxy.cc b/mojo/public/cpp/bindings/lib/control_message_proxy.cc
index 06d9815bc08ba8a6fcfb4741579d60b9a8cd81c8..79da7d8971b34bea6bdd80d425975984f51a154b 100644
--- a/mojo/public/cpp/bindings/lib/control_message_proxy.cc
+++ b/mojo/public/cpp/bindings/lib/control_message_proxy.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/macros.h"
+#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/lib/message_builder.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/message.h"
@@ -95,12 +96,19 @@ void RunVersionCallback(
callback.Run(version);
}
+void RunClosure(const base::Closure& callback,
+ interface_control::RunResponseMessageParamsPtr run_response) {
+ callback.Run();
+}
+
} // namespace
ControlMessageProxy::ControlMessageProxy(MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
+ControlMessageProxy::~ControlMessageProxy() = default;
+
void ControlMessageProxy::QueryVersion(
const base::Callback<void(uint32_t)>& callback) {
auto input_ptr = interface_control::RunInput::New();
@@ -117,5 +125,30 @@ void ControlMessageProxy::RequireVersion(uint32_t version) {
SendRunOrClosePipeMessage(receiver_, std::move(input_ptr), &context_);
}
+void ControlMessageProxy::FlushForTesting() {
+ auto input_ptr = interface_control::RunInput::New();
+ input_ptr->set_flush_for_testing(interface_control::FlushForTesting::New());
+ base::RunLoop run_loop;
+ run_loop_quit_closure_ = run_loop.QuitClosure();
+ SendRunMessage(
+ receiver_, std::move(input_ptr),
+ base::Bind(&RunClosure,
+ base::Bind(&ControlMessageProxy::RunFlushForTestingClosure,
+ base::Unretained(this))),
+ &context_);
+ run_loop.Run();
+}
+
+void ControlMessageProxy::RunFlushForTestingClosure() {
+ DCHECK(!run_loop_quit_closure_.is_null());
+ run_loop_quit_closure_.Run();
+ run_loop_quit_closure_.Reset();
+}
+
+void ControlMessageProxy::OnConnectionError() {
+ if (!run_loop_quit_closure_.is_null())
+ RunFlushForTestingClosure();
+}
+
} // namespace internal
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698