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

Unified Diff: mojo/edk/system/remote_message_pipe_unittest.cc

Issue 1496663002: EDK: Make mojo::platform::TaskRunner's PostTask() take an std::function<void()>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/edk/system/remote_data_pipe_impl_unittest.cc ('k') | mojo/edk/system/slave_connection_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/remote_message_pipe_unittest.cc
diff --git a/mojo/edk/system/remote_message_pipe_unittest.cc b/mojo/edk/system/remote_message_pipe_unittest.cc
index 560ae64fad2baf59c827ba9dbaff3ac84bdd8b57..22495e30b11f164c03d672b8fb8c677dc29c4464 100644
--- a/mojo/edk/system/remote_message_pipe_unittest.cc
+++ b/mojo/edk/system/remote_message_pipe_unittest.cc
@@ -10,7 +10,6 @@
#include <utility>
#include <vector>
-#include "base/bind.h"
#include "base/logging.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/platform_shared_buffer.h"
@@ -54,13 +53,11 @@ class RemoteMessagePipeTest : public testing::Test {
~RemoteMessagePipeTest() override {}
void SetUp() override {
- io_thread_.PostTaskAndWait(base::Bind(
- &RemoteMessagePipeTest::SetUpOnIOThread, base::Unretained(this)));
+ io_thread_.PostTaskAndWait([this]() { SetUpOnIOThread(); });
}
void TearDown() override {
- io_thread_.PostTaskAndWait(base::Bind(
- &RemoteMessagePipeTest::TearDownOnIOThread, base::Unretained(this)));
+ io_thread_.PostTaskAndWait([this]() { TearDownOnIOThread(); });
}
protected:
@@ -69,10 +66,9 @@ class RemoteMessagePipeTest : public testing::Test {
// hosted on the channel).
void BootstrapChannelEndpoints(RefPtr<ChannelEndpoint>&& ep0,
RefPtr<ChannelEndpoint>&& ep1) {
- io_thread_.PostTaskAndWait(
- base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread,
- base::Unretained(this), base::Passed(ep0),
- base::Passed(ep1)));
+ io_thread_.PostTaskAndWait([this, &ep0, &ep1]() {
+ BootstrapChannelEndpointsOnIOThread(std::move(ep0), std::move(ep1));
+ });
}
// This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires
@@ -80,15 +76,15 @@ class RemoteMessagePipeTest : public testing::Test {
// hosted on the channel). This returns *without* waiting.
void BootstrapChannelEndpointNoWait(unsigned channel_index,
RefPtr<ChannelEndpoint>&& ep) {
- io_thread_.PostTask(
- base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread,
- base::Unretained(this), channel_index, base::Passed(&ep)));
+ // Note: We have to copy |ep| here, since we're not waiting for it.
+ // TODO(vtl): With C++14 lambda captures, we'll be able to move it.
+ io_thread_.PostTask([this, channel_index, ep]() mutable {
+ BootstrapChannelEndpointOnIOThread(channel_index, std::move(ep));
+ });
}
void RestoreInitialState() {
- io_thread_.PostTaskAndWait(
- base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread,
- base::Unretained(this)));
+ io_thread_.PostTaskAndWait([this]() { RestoreInitialStateOnIOThread(); });
}
embedder::PlatformSupport* platform_support() { return &platform_support_; }
@@ -129,10 +125,8 @@ class RemoteMessagePipeTest : public testing::Test {
RawChannel::Create(platform_handles_[channel_index].Pass()));
}
- // TODO(vtl): The arguments should be rvalue references, but that doesn't
- // currently work correctly with base::Bind.
- void BootstrapChannelEndpointsOnIOThread(RefPtr<ChannelEndpoint> ep0,
- RefPtr<ChannelEndpoint> ep1) {
+ void BootstrapChannelEndpointsOnIOThread(RefPtr<ChannelEndpoint>&& ep0,
+ RefPtr<ChannelEndpoint>&& ep1) {
CHECK(io_thread()->IsCurrentAndRunning());
if (!channels_[0])
@@ -144,10 +138,8 @@ class RemoteMessagePipeTest : public testing::Test {
channels_[1]->SetBootstrapEndpoint(std::move(ep1));
}
- // TODO(vtl): |ep| should be an rvalue reference, but that doesn't currently
- // work correctly with base::Bind.
void BootstrapChannelEndpointOnIOThread(unsigned channel_index,
- RefPtr<ChannelEndpoint> ep) {
+ RefPtr<ChannelEndpoint>&& ep) {
CHECK(io_thread()->IsCurrentAndRunning());
CHECK(channel_index == 0 || channel_index == 1);
@@ -1131,7 +1123,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) {
BootstrapChannelEndpointNoWait(1, std::move(ep1));
if (i & 1u) {
- io_thread()->PostTask(base::Bind(&test::Sleep, delay));
+ io_thread()->PostTask([delay]() { test::Sleep(delay); });
}
if (i & 2u)
test::Sleep(delay);
@@ -1139,7 +1131,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) {
mp0->Close(0);
if (i & 4u) {
- io_thread()->PostTask(base::Bind(&test::Sleep, delay));
+ io_thread()->PostTask([delay]() { test::Sleep(delay); });
}
if (i & 8u)
test::Sleep(delay);
« no previous file with comments | « mojo/edk/system/remote_data_pipe_impl_unittest.cc ('k') | mojo/edk/system/slave_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698