EDK: Make mojo::embedder::AsyncWait (etc.) take an std::function instead of a base::Callback. R=jamesr@chromium.org Review URL: https://codereview.chromium.org/1420533012 .
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc index 8f81407..09690f4 100644 --- a/mojo/edk/embedder/embedder.cc +++ b/mojo/edk/embedder/embedder.cc
@@ -95,7 +95,7 @@ MojoResult AsyncWait(MojoHandle handle, MojoHandleSignals signals, - const base::Callback<void(MojoResult)>& callback) { + const std::function<void(MojoResult)>& callback) { return internal::g_core->AsyncWait(handle, signals, callback); }
diff --git a/mojo/edk/embedder/embedder.h b/mojo/edk/embedder/embedder.h index 8899aea..0f8a6ab 100644 --- a/mojo/edk/embedder/embedder.h +++ b/mojo/edk/embedder/embedder.h
@@ -5,11 +5,11 @@ #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_H_ #define MOJO_EDK_EMBEDDER_EMBEDDER_H_ +#include <functional> #include <memory> #include <string> #include "base/callback.h" -#include "base/task_runner.h" #include "mojo/edk/embedder/channel_info_forward.h" #include "mojo/edk/embedder/platform_task_runner.h" #include "mojo/edk/embedder/process_type.h" @@ -48,7 +48,7 @@ // arbitrary thread, so it must not call any Mojo system or embedder functions. MojoResult AsyncWait(MojoHandle handle, MojoHandleSignals signals, - const base::Callback<void(MojoResult)>& callback); + const std::function<void(MojoResult)>& callback); // Creates a |MojoHandle| that wraps the given |PlatformHandle| (taking // ownership of it). This |MojoHandle| can then, e.g., be passed through message
diff --git a/mojo/edk/embedder/embedder_unittest.cc b/mojo/edk/embedder/embedder_unittest.cc index 066a190..3a3e799 100644 --- a/mojo/edk/embedder/embedder_unittest.cc +++ b/mojo/edk/embedder/embedder_unittest.cc
@@ -243,8 +243,7 @@ TestAsyncWaiter waiter; EXPECT_EQ(MOJO_RESULT_OK, AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, - base::Bind(&TestAsyncWaiter::Awake, - base::Unretained(&waiter)))); + [&waiter](MojoResult result) { waiter.Awake(result); })); test_io_thread().PostTask(base::Bind(&WriteHello, server_mp.get())); EXPECT_TRUE(waiter.TryWait()); @@ -254,8 +253,9 @@ TestAsyncWaiter waiter_that_doesnt_wait; EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, - base::Bind(&TestAsyncWaiter::Awake, - base::Unretained(&waiter_that_doesnt_wait)))); + [&waiter_that_doesnt_wait](MojoResult result) { + waiter_that_doesnt_wait.Awake(result); + })); char buffer[1000]; uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); @@ -266,8 +266,9 @@ TestAsyncWaiter unsatisfiable_waiter; EXPECT_EQ(MOJO_RESULT_OK, AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, - base::Bind(&TestAsyncWaiter::Awake, - base::Unretained(&unsatisfiable_waiter)))); + [&unsatisfiable_waiter](MojoResult result) { + unsatisfiable_waiter.Awake(result); + })); test_io_thread().PostTask( base::Bind(&CloseScopedHandle, base::Passed(server_mp.Pass())));
diff --git a/mojo/edk/system/async_waiter.cc b/mojo/edk/system/async_waiter.cc index 4f539b9..c97e9ff 100644 --- a/mojo/edk/system/async_waiter.cc +++ b/mojo/edk/system/async_waiter.cc
@@ -14,7 +14,7 @@ } bool AsyncWaiter::Awake(MojoResult result, uintptr_t context) { - callback_.Run(result); + callback_(result); delete this; return false; }
diff --git a/mojo/edk/system/async_waiter.h b/mojo/edk/system/async_waiter.h index 9dece06..35a72f4 100644 --- a/mojo/edk/system/async_waiter.h +++ b/mojo/edk/system/async_waiter.h
@@ -5,7 +5,8 @@ #ifndef MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ #define MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ -#include "base/callback.h" +#include <functional> + #include "mojo/edk/system/awakable.h" #include "mojo/public/c/system/types.h" #include "mojo/public/cpp/system/macros.h" @@ -16,7 +17,7 @@ // An |Awakable| implementation that just calls a given callback object. class AsyncWaiter final : public Awakable { public: - using AwakeCallback = base::Callback<void(MojoResult)>; + using AwakeCallback = std::function<void(MojoResult)>; // |callback| must satisfy the same contract as |Awakable::Awake()|. explicit AsyncWaiter(const AwakeCallback& callback);
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc index 8e1340f..577041a 100644 --- a/mojo/edk/system/core.cc +++ b/mojo/edk/system/core.cc
@@ -112,7 +112,7 @@ MojoResult Core::AsyncWait(MojoHandle handle, MojoHandleSignals signals, - const base::Callback<void(MojoResult)>& callback) { + const std::function<void(MojoResult)>& callback) { RefPtr<Dispatcher> dispatcher(GetDispatcher(handle)); DCHECK(dispatcher);
diff --git a/mojo/edk/system/core.h b/mojo/edk/system/core.h index c8a47e0..7217888 100644 --- a/mojo/edk/system/core.h +++ b/mojo/edk/system/core.h
@@ -7,7 +7,8 @@ #include <stdint.h> -#include "base/callback.h" +#include <functional> + #include "mojo/edk/system/handle_table.h" #include "mojo/edk/system/mapping_table.h" #include "mojo/edk/system/memory.h" @@ -66,7 +67,7 @@ // awakable.h. In particular, it must not call any Mojo system functions. MojoResult AsyncWait(MojoHandle handle, MojoHandleSignals signals, - const base::Callback<void(MojoResult)>& callback); + const std::function<void(MojoResult)>& callback); embedder::PlatformSupport* platform_support() const { return platform_support_;
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc index 89f9856..18f3fda 100644 --- a/mojo/edk/system/core_unittest.cc +++ b/mojo/edk/system/core_unittest.cc
@@ -8,7 +8,6 @@ #include <limits> -#include "base/bind.h" #include "mojo/edk/system/awakable.h" #include "mojo/edk/system/core_test_base.h" #include "mojo/edk/system/test/sleep.h" @@ -1292,16 +1291,16 @@ MojoHandle h = CreateMockHandle(&info); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, - core()->AsyncWait(h, MOJO_HANDLE_SIGNAL_READABLE, - base::Bind(&TestAsyncWaiter::Awake, - base::Unretained(&waiter)))); + core()->AsyncWait( + h, MOJO_HANDLE_SIGNAL_READABLE, + [&waiter](MojoResult result) { waiter.Awake(result); })); EXPECT_EQ(0u, info.GetAddedAwakableSize()); info.AllowAddAwakable(true); - EXPECT_EQ(MOJO_RESULT_OK, - core()->AsyncWait(h, MOJO_HANDLE_SIGNAL_READABLE, - base::Bind(&TestAsyncWaiter::Awake, - base::Unretained(&waiter)))); + EXPECT_EQ(MOJO_RESULT_OK, core()->AsyncWait(h, MOJO_HANDLE_SIGNAL_READABLE, + [&waiter](MojoResult result) { + waiter.Awake(result); + })); EXPECT_EQ(1u, info.GetAddedAwakableSize()); EXPECT_FALSE(info.GetAddedAwakableAt(0)->Awake(MOJO_RESULT_BUSY, 0));