Skip to content

Commit

Permalink
Convert remoting/test to use Once/RepeatingCallback.
Browse files Browse the repository at this point in the history
Fixed: 1007828
Change-Id: I944e6aa42ce3bb6183fd1a685bc9104f59666489
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2049003
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Joe Downing <joedow@chromium.org>
Commit-Queue: Joey Scarr <jsca@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740944}
  • Loading branch information
Joey Scarr authored and Commit Bot committed Feb 13, 2020
1 parent 86ea349 commit 00b7c1f
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 57 deletions.
1 change: 0 additions & 1 deletion PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@
'^remoting/ios/',
'^remoting/protocol/',
'^remoting/signaling/',
'^remoting/test/',
'^services/',
'^third_party/blink/',
'^tools/clang/base_bind_rewriters/', # Intentional.
Expand Down
6 changes: 3 additions & 3 deletions remoting/client/display/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void GlRenderer::OnCursorVisibilityChanged(bool visible) {
}

void GlRenderer::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(frame->size().width() > 0 && frame->size().height() > 0);
if (canvas_width_ != frame->size().width() ||
Expand All @@ -91,7 +91,7 @@ void GlRenderer::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
}

desktop_.SetVideoFrame(*frame);
pending_done_callbacks_.push(done);
pending_done_callbacks_.push(std::move(done));
RequestRender();
}

Expand Down Expand Up @@ -176,7 +176,7 @@ void GlRenderer::OnRender() {
delegate_->OnFrameRendered();

while (!pending_done_callbacks_.empty()) {
pending_done_callbacks_.front().Run();
std::move(pending_done_callbacks_.front()).Run();
pending_done_callbacks_.pop();
}
}
Expand Down
4 changes: 2 additions & 2 deletions remoting/client/display/gl_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class GlRenderer {
// |done| will be queued up and called on the display thread after the actual
// rendering happens.
void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done);
base::OnceClosure done);

void OnCursorShapeChanged(const protocol::CursorShapeInfo& shape);

Expand Down Expand Up @@ -122,7 +122,7 @@ class GlRenderer {

// Done callbacks from OnFrameReceived. Will all be called once rendering
// takes place.
base::queue<base::Closure> pending_done_callbacks_;
base::queue<base::OnceClosure> pending_done_callbacks_;

bool render_scheduled_ = false;

Expand Down
4 changes: 2 additions & 2 deletions remoting/client/display/gl_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ std::vector<base::WeakPtr<Drawable>> GlRendererTest::GetDrawables() {
void GlRendererTest::SetDesktopFrameWithSize(const webrtc::DesktopSize& size) {
renderer_->OnFrameReceived(
std::make_unique<webrtc::BasicDesktopFrame>(size),
base::Bind(&GlRendererTest::OnDesktopFrameProcessed,
base::Unretained(this)));
base::BindOnce(&GlRendererTest::OnDesktopFrameProcessed,
base::Unretained(this)));
}

void GlRendererTest::PostSetDesktopFrameTasks(const webrtc::DesktopSize& size,
Expand Down
13 changes: 7 additions & 6 deletions remoting/client/dual_buffer_frame_consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::unique_ptr<webrtc::DesktopFrame> DualBufferFrameConsumer::AllocateFrame(

void DualBufferFrameConsumer::DrawFrame(
std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
DCHECK(thread_checker_.CalledOnValidThread());
webrtc::SharedDesktopFrame* shared_frame =
reinterpret_cast<webrtc::SharedDesktopFrame*> (frame.get());
Expand All @@ -131,7 +131,7 @@ void DualBufferFrameConsumer::DrawFrame(
buffers_[0]->GetUnderlyingFrame()) {
buffer_1_mask_.Subtract(frame->updated_region());
}
RunRenderCallback(std::move(frame), done);
RunRenderCallback(std::move(frame), std::move(done));
}

protocol::FrameConsumer::PixelFormat
Expand All @@ -145,18 +145,19 @@ base::WeakPtr<DualBufferFrameConsumer> DualBufferFrameConsumer::GetWeakPtr() {

void DualBufferFrameConsumer::RunRenderCallback(
std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
if (!task_runner_) {
callback_.Run(std::move(frame), done);
callback_.Run(std::move(frame), std::move(done));
return;
}

task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
callback_, std::move(frame),
base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask),
base::ThreadTaskRunnerHandle::Get(), FROM_HERE, done)));
base::BindOnce(base::IgnoreResult(&base::TaskRunner::PostTask),
base::ThreadTaskRunnerHandle::Get(), FROM_HERE,
std::move(done))));
}

} // namespace remoting
6 changes: 3 additions & 3 deletions remoting/client/dual_buffer_frame_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DualBufferFrameConsumer : public protocol::FrameConsumer {
// |done| should be run after it is rendered. Can be called on any thread.
using RenderCallback =
base::Callback<void(std::unique_ptr<webrtc::DesktopFrame>,
const base::Closure&)>;
base::OnceClosure)>;
DualBufferFrameConsumer(
const RenderCallback& callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Expand All @@ -48,14 +48,14 @@ class DualBufferFrameConsumer : public protocol::FrameConsumer {
std::unique_ptr<webrtc::DesktopFrame> AllocateFrame(
const webrtc::DesktopSize& size) override;
void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) override;
base::OnceClosure done) override;
PixelFormat GetPixelFormat() override;

base::WeakPtr<DualBufferFrameConsumer> GetWeakPtr();

private:
void RunRenderCallback(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done);
base::OnceClosure done);

std::unique_ptr<webrtc::SharedDesktopFrame> buffers_[2];

Expand Down
9 changes: 5 additions & 4 deletions remoting/client/dual_buffer_frame_consumer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class DualBufferFrameConsumerTest : public testing::Test {
protected:
std::unique_ptr<DualBufferFrameConsumer> consumer_;
std::unique_ptr<webrtc::DesktopFrame> received_frame_;
base::Closure done_closure_;
base::OnceClosure done_closure_;

private:
void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done);
base::OnceClosure done);
};

void DualBufferFrameConsumerTest::SetUp() {
Expand All @@ -77,9 +78,9 @@ void DualBufferFrameConsumerTest::SetUp() {

void DualBufferFrameConsumerTest::OnFrameReceived(
std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
received_frame_ = std::move(frame);
done_closure_ = done;
done_closure_ = std::move(done);
}

TEST_F(DualBufferFrameConsumerTest, AllocateOneFrame) {
Expand Down
6 changes: 3 additions & 3 deletions remoting/client/jni/jni_gl_display_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class JniGlDisplayHandler::Core : public protocol::CursorShapeStub,
std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer();

void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done);
base::OnceClosure done);

void SurfaceCreated(base::android::ScopedJavaGlobalRef<jobject> surface);
void SurfaceChanged(int width, int height);
Expand Down Expand Up @@ -133,9 +133,9 @@ JniGlDisplayHandler::Core::GrabFrameConsumer() {

void JniGlDisplayHandler::Core::OnFrameReceived(
std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
renderer_->OnFrameReceived(std::move(frame), done);
renderer_->OnFrameReceived(std::move(frame), std::move(done));
}

void JniGlDisplayHandler::Core::SurfaceCreated(
Expand Down
15 changes: 7 additions & 8 deletions remoting/client/software_video_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ class TestFrameConsumer : public protocol::FrameConsumer {
~TestFrameConsumer() override = default;

std::unique_ptr<DesktopFrame> WaitForNextFrame(
base::Closure* out_done_callback) {
base::OnceClosure* out_done_callback) {
EXPECT_TRUE(thread_checker_.CalledOnValidThread());
frame_run_loop_.reset(new base::RunLoop());
frame_run_loop_->Run();
frame_run_loop_.reset();
*out_done_callback = last_frame_done_callback_;
last_frame_done_callback_.Reset();
*out_done_callback = std::move(last_frame_done_callback_);
return std::move(last_frame_);
}

Expand All @@ -55,10 +54,10 @@ class TestFrameConsumer : public protocol::FrameConsumer {
}

void DrawFrame(std::unique_ptr<DesktopFrame> frame,
const base::Closure& done) override {
base::OnceClosure done) override {
EXPECT_TRUE(thread_checker_.CalledOnValidThread());
last_frame_ = std::move(frame);
last_frame_done_callback_ = done;
last_frame_done_callback_ = std::move(done);
frame_run_loop_->Quit();
}

Expand All @@ -73,7 +72,7 @@ class TestFrameConsumer : public protocol::FrameConsumer {
std::unique_ptr<base::RunLoop> frame_run_loop_;

std::unique_ptr<DesktopFrame> last_frame_;
base::Closure last_frame_done_callback_;
base::OnceClosure last_frame_done_callback_;
};

std::unique_ptr<DesktopFrame> CreateTestFrame(int index) {
Expand Down Expand Up @@ -171,12 +170,12 @@ TEST_F(SoftwareVideoRendererTest, DecodeFrame) {
}

for (int frame_index = 0; frame_index < kFrameCount; frame_index++) {
base::Closure done_callback;
base::OnceClosure done_callback;
std::unique_ptr<DesktopFrame> decoded_frame =
frame_consumer_.WaitForNextFrame(&done_callback);

EXPECT_FALSE(callback_called[frame_index]);
done_callback.Run();
std::move(done_callback).Run();
EXPECT_TRUE(callback_called[frame_index]);

EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame));
Expand Down
6 changes: 3 additions & 3 deletions remoting/ios/display/gl_display_handler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
void OnSizeChanged(int width, int height) override;

void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done);
base::OnceClosure done);
void CreateRendererContext(EAGLView* view);
void DestroyRendererContext();
void SetSurfaceSize(int width, int height);
Expand Down Expand Up @@ -166,9 +166,9 @@ void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
}

void Core::OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread());
renderer_->OnFrameReceived(std::move(frame), done);
renderer_->OnFrameReceived(std::move(frame), std::move(done));
}

void Core::OnFrameRendered() {
Expand Down
4 changes: 2 additions & 2 deletions remoting/protocol/fake_video_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ std::unique_ptr<webrtc::DesktopFrame> FakeFrameConsumer::AllocateFrame(
}

void FakeFrameConsumer::DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) {
base::OnceClosure done) {
CHECK(thread_checker_.CalledOnValidThread());
received_frames_.push_back(std::move(frame));
if (!done.is_null())
done.Run();
std::move(done).Run();
if (!on_frame_callback_.is_null())
on_frame_callback_.Run();
}
Expand Down
2 changes: 1 addition & 1 deletion remoting/protocol/fake_video_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FakeFrameConsumer : public FrameConsumer {
std::unique_ptr<webrtc::DesktopFrame> AllocateFrame(
const webrtc::DesktopSize& size) override;
void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) override;
base::OnceClosure done) override;
PixelFormat GetPixelFormat() override;

private:
Expand Down
2 changes: 1 addition & 1 deletion remoting/protocol/frame_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FrameConsumer {
const webrtc::DesktopSize& size) = 0;

virtual void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) = 0;
const base::OnceClosure done) = 0;

// Returns the preferred pixel encoding for the platform.
virtual PixelFormat GetPixelFormat() = 0;
Expand Down
4 changes: 2 additions & 2 deletions remoting/test/fake_socket_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateUdpSocket(
new FakeUdpSocket(this, dispatcher_,
rtc::SocketAddress(local_address.ipaddr(), port));

udp_sockets_[port] =
base::Bind(&FakeUdpSocket::ReceivePacket, base::Unretained(result));
udp_sockets_[port] = base::BindRepeating(&FakeUdpSocket::ReceivePacket,
base::Unretained(result));

return result;
}
Expand Down
9 changes: 5 additions & 4 deletions remoting/test/fake_socket_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory,
int data_size;
};

typedef base::Callback<void(const rtc::SocketAddress& from,
const rtc::SocketAddress& to,
const scoped_refptr<net::IOBuffer>& data,
int data_size)> ReceiveCallback;
typedef base::RepeatingCallback<void(const rtc::SocketAddress& from,
const rtc::SocketAddress& to,
const scoped_refptr<net::IOBuffer>& data,
int data_size)>
ReceiveCallback;
typedef std::map<uint16_t, ReceiveCallback> UdpSocketsMap;

void DoReceivePacket();
Expand Down
6 changes: 3 additions & 3 deletions remoting/test/it2me_standalone_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ void It2MeStandaloneHost::Run() {
}

void It2MeStandaloneHost::StartOutputTimer() {
timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(1),
base::Bind(&OutputFakeConnectionEventLogger, std::cref(event_logger_)));
timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
base::BindRepeating(&OutputFakeConnectionEventLogger,
std::cref(event_logger_)));
}

void It2MeStandaloneHost::Connect() {
Expand Down
18 changes: 9 additions & 9 deletions remoting/test/protocol_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ class ProtocolPerfTest
}

void DrawFrame(std::unique_ptr<webrtc::DesktopFrame> frame,
const base::Closure& done) override {
base::OnceClosure done) override {
last_video_frame_ = std::move(frame);
if (!on_frame_task_.is_null())
on_frame_task_.Run();
if (!done.is_null())
done.Run();
std::move(done).Run();
}

protocol::FrameConsumer::PixelFormat GetPixelFormat() override {
Expand Down Expand Up @@ -362,8 +362,8 @@ class ProtocolPerfTest

protocol::ClientAuthenticationConfig client_auth_config;
client_auth_config.host_id = kHostId;
client_auth_config.fetch_secret_callback =
base::Bind(&ProtocolPerfTest::FetchPin, base::Unretained(this));
client_auth_config.fetch_secret_callback = base::BindRepeating(
&ProtocolPerfTest::FetchPin, base::Unretained(this));

video_renderer_.reset(new SoftwareVideoRenderer(this));
video_renderer_->Initialize(*client_context_, this);
Expand Down Expand Up @@ -419,7 +419,7 @@ class ProtocolPerfTest
bool client_connected_;
bool host_connected_;

base::Closure on_frame_task_;
base::RepeatingClosure on_frame_task_;

std::unique_ptr<VideoPacket> last_video_packet_;
std::unique_ptr<webrtc::DesktopFrame> last_video_frame_;
Expand Down Expand Up @@ -481,8 +481,8 @@ INSTANTIATE_TEST_SUITE_P(
void ProtocolPerfTest::MeasureTotalLatency(bool use_webrtc) {
scoped_refptr<test::CyclicFrameGenerator> frame_generator =
test::CyclicFrameGenerator::Create();
desktop_environment_factory_->set_frame_generator(
base::Bind(&test::CyclicFrameGenerator::GenerateFrame, frame_generator));
desktop_environment_factory_->set_frame_generator(base::BindRepeating(
&test::CyclicFrameGenerator::GenerateFrame, frame_generator));
event_timestamp_source_ = frame_generator;

StartHostAndClient(use_webrtc);
Expand Down Expand Up @@ -579,8 +579,8 @@ TEST_P(ProtocolPerfTest, TotalLatencyWebrtc) {
void ProtocolPerfTest::MeasureScrollPerformance(bool use_webrtc) {
scoped_refptr<test::ScrollFrameGenerator> frame_generator =
new test::ScrollFrameGenerator();
desktop_environment_factory_->set_frame_generator(
base::Bind(&test::ScrollFrameGenerator::GenerateFrame, frame_generator));
desktop_environment_factory_->set_frame_generator(base::BindRepeating(
&test::ScrollFrameGenerator::GenerateFrame, frame_generator));
event_timestamp_source_ = frame_generator;

StartHostAndClient(use_webrtc);
Expand Down

0 comments on commit 00b7c1f

Please sign in to comment.