| Index: mojo/public/cpp/bindings/tests/binding_callback_unittest.cc
|
| diff --git a/mojo/public/cpp/bindings/tests/binding_callback_unittest.cc b/mojo/public/cpp/bindings/tests/binding_callback_unittest.cc
|
| index e6bdfa9a59d9cc9b5491133b22b7d8f7d1c66ef3..6f00d2e980dde1c9d4c840b99f7da9ce989b211d 100644
|
| --- a/mojo/public/cpp/bindings/tests/binding_callback_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/binding_callback_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include <stdint.h>
|
|
|
| #include "base/bind.h"
|
| +#include "base/callback.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| @@ -32,24 +33,16 @@ namespace mojo {
|
| namespace test {
|
| namespace {
|
|
|
| -// A Runnable object that saves the last value it sees via the
|
| -// provided int32_t*. Used on the client side.
|
| -class ValueSaver {
|
| - public:
|
| - ValueSaver(int32_t* last_value_seen, const base::Closure& closure)
|
| - : last_value_seen_(last_value_seen), closure_(closure) {}
|
| - void Run(int32_t x) const {
|
| - *last_value_seen_ = x;
|
| - if (!closure_.is_null()) {
|
| - closure_.Run();
|
| - closure_.Reset();
|
| - }
|
| - }
|
| +void SaveValue(int32_t* storage, const base::Closure& closure, int32_t value) {
|
| + *storage = value;
|
| + if (!closure.is_null())
|
| + closure.Run();
|
| +}
|
|
|
| - private:
|
| - int32_t* const last_value_seen_;
|
| - mutable base::Closure closure_;
|
| -};
|
| +base::Callback<void(int32_t)> BindValueSaver(int32_t* last_value_seen,
|
| + const base::Closure& closure) {
|
| + return base::Bind(&SaveValue, last_value_seen, closure);
|
| +}
|
|
|
| // An implementation of sample::Provider used on the server side.
|
| // It only implements one of the methods: EchoInt().
|
| @@ -159,7 +152,8 @@ TEST_F(BindingCallbackTest, Basic) {
|
| server_impl.set_closure(run_loop.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 7,
|
| - ValueSaver(&last_client_callback_value_seen_, run_loop2.QuitClosure()));
|
| + BindValueSaver(&last_client_callback_value_seen_,
|
| + run_loop2.QuitClosure()));
|
| run_loop.Run();
|
|
|
| // Check that server saw the correct value, but the client has not yet.
|
| @@ -182,7 +176,8 @@ TEST_F(BindingCallbackTest, Basic) {
|
| server_impl.set_closure(run_loop3.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 13,
|
| - ValueSaver(&last_client_callback_value_seen_, run_loop4.QuitClosure()));
|
| + BindValueSaver(&last_client_callback_value_seen_,
|
| + run_loop4.QuitClosure()));
|
| run_loop3.Run();
|
|
|
| // Check that server saw the correct value, but the client has not yet.
|
| @@ -217,7 +212,7 @@ TEST_F(BindingCallbackTest, DeleteBindingThenRunCallback) {
|
| server_impl.set_closure(run_loop2.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 7,
|
| - ValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| + BindValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| run_loop2.Run();
|
| }
|
| // The binding has now been destroyed and the pipe is closed.
|
| @@ -238,7 +233,7 @@ TEST_F(BindingCallbackTest, DeleteBindingThenRunCallback) {
|
| // encountered.
|
| interface_ptr_->EchoInt(
|
| 13,
|
| - ValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| + BindValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| run_loop.Run();
|
| EXPECT_TRUE(interface_ptr_.encountered_error());
|
| }
|
| @@ -261,7 +256,7 @@ TEST_F(BindingCallbackTest, DeleteBindingThenDeleteCallback) {
|
| server_impl.set_closure(run_loop.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 7,
|
| - ValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| + BindValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| run_loop.Run();
|
| }
|
| // The binding has now been destroyed and the pipe is closed.
|
| @@ -292,7 +287,7 @@ TEST_F(BindingCallbackTest, CloseBindingBeforeDeletingCallback) {
|
| server_impl.set_closure(run_loop.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 7,
|
| - ValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| + BindValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| run_loop.Run();
|
|
|
| // Check that server saw the correct value, but the client has not yet.
|
| @@ -327,7 +322,7 @@ TEST_F(BindingCallbackTest, DeleteCallbackBeforeBindingDeathTest) {
|
| server_impl.set_closure(run_loop.QuitClosure());
|
| interface_ptr_->EchoInt(
|
| 7,
|
| - ValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| + BindValueSaver(&last_client_callback_value_seen_, base::Closure()));
|
| run_loop.Run();
|
|
|
| // Check that server saw the correct value, but the client has not yet.
|
|
|