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

Unified Diff: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc

Issue 1174073002: C++ bindings: support using a callback as connection error handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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/tests/interface_ptr_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index 57abf8fd835edf4780c87f5f754932825c7d31be..6486192c955551d31b82c000b21203f91335f700 100644
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "mojo/public/cpp/bindings/binding.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/utility/run_loop.h"
@@ -16,18 +15,6 @@ namespace mojo {
namespace test {
namespace {
-class ErrorObserver : public ErrorHandler {
- public:
- ErrorObserver() : encountered_error_(false) {}
-
- bool encountered_error() const { return encountered_error_; }
-
- void OnConnectionError() override { encountered_error_ = true; }
-
- private:
- bool encountered_error_;
-};
-
template <typename Method, typename Class>
class RunnableImpl {
public:
@@ -319,8 +306,9 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) {
math::CalculatorPtr proxy;
MathCalculatorImpl calc_impl(GetProxy(&proxy));
- ErrorObserver error_observer;
- proxy.set_error_handler(&error_observer);
+ bool encountered_error = false;
+ proxy.set_connection_error_handler(
+ [&encountered_error]() { encountered_error = true; });
MathCalculatorUI calculator_ui(proxy.Pass());
@@ -343,9 +331,9 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) {
// OK, now we see the error.
EXPECT_TRUE(calculator_ui.encountered_error());
- // We should have also been able to observe the error through the
- // ErrorHandler interface.
- EXPECT_TRUE(error_observer.encountered_error());
+ // We should have also been able to observe the error through the error
+ // handler.
+ EXPECT_TRUE(encountered_error);
}
TEST_F(InterfacePtrTest, DestroyInterfacePtrOnMethodResponse) {
@@ -439,7 +427,7 @@ TEST_F(InterfacePtrTest, RequireVersion) {
EXPECT_EQ(456, impl.integer());
}
-class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
+class StrongMathCalculatorImpl : public math::Calculator {
public:
StrongMathCalculatorImpl(ScopedMessagePipeHandle handle,
bool* error_received,
@@ -447,7 +435,8 @@ class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
: error_received_(error_received),
destroyed_(destroyed),
binding_(this, handle.Pass()) {
- binding_.set_error_handler(this);
+ binding_.set_connection_error_handler(
+ [this]() { *error_received_ = true; });
}
~StrongMathCalculatorImpl() override { *destroyed_ = true; }
@@ -464,9 +453,6 @@ class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
callback.Run(total_);
}
- // ErrorHandler implementation.
- void OnConnectionError() override { *error_received_ = true; }
-
private:
double total_ = 0.0;
bool* error_received_;
@@ -511,7 +497,7 @@ TEST(StrongConnectorTest, Math) {
EXPECT_TRUE(destroyed);
}
-class WeakMathCalculatorImpl : public math::Calculator, public ErrorHandler {
+class WeakMathCalculatorImpl : public math::Calculator {
public:
WeakMathCalculatorImpl(ScopedMessagePipeHandle handle,
bool* error_received,
@@ -519,7 +505,8 @@ class WeakMathCalculatorImpl : public math::Calculator, public ErrorHandler {
: error_received_(error_received),
destroyed_(destroyed),
binding_(this, handle.Pass()) {
- binding_.set_error_handler(this);
+ binding_.set_connection_error_handler(
+ [this]() { *error_received_ = true; });
}
~WeakMathCalculatorImpl() override { *destroyed_ = true; }
@@ -535,9 +522,6 @@ class WeakMathCalculatorImpl : public math::Calculator, public ErrorHandler {
callback.Run(total_);
}
- // ErrorHandler implementation.
- void OnConnectionError() override { *error_received_ = true; }
-
private:
double total_ = 0.0;
bool* error_received_;
« mojo/public/cpp/bindings/binding.h ('K') | « mojo/public/cpp/bindings/tests/binding_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698