Commit 29a9efd8 authored by jamescook's avatar jamescook Committed by Commit bot

Revert of Update ozone/drm proxy_helpers.h to support move-only types....

Revert of Update ozone/drm proxy_helpers.h to support move-only types. (patchset #1 id:1 of https://codereview.chromium.org/2873963004/ )

Reason for revert:
ozone_unittests has been failing continuously since this landed:

https://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Ozone%20Tests%20%281%29/builds/46812

[ RUN      ] ProxyHelpersTest.PostTask
../../ui/ozone/platform/drm/gpu/proxy_helpers_unittest.cc:69: Failure
Value of: main_checker_.CalledOnValidThread()
  Actual: true
Expected: false
../../ui/ozone/platform/drm/gpu/proxy_helpers_unittest.cc:50: Failure
Value of: main_checker_.CalledOnValidThread()
  Actual: true
Expected: false
../../ui/ozone/platform/drm/gpu/proxy_helpers_unittest.cc:75: Failure
Value of: drm_checker_.CalledOnValidThread()
  Actual: true
Expected: false

Original issue's description:
> Update ozone/drm proxy_helpers.h to support move-only types.
>
> As a helpful prerequisite for the use of mojo IPC in ozone/drm,
> support move only types in proxy_helpers.h callback sequences.
>
> BUG=620927
>
> Review-Url: https://codereview.chromium.org/2873963004
> Cr-Commit-Position: refs/heads/master@{#470715}
> Committed: https://chromium.googlesource.com/chromium/src/+/a82a006f8420ecc7c75deab4f1e9d23c43616e1f

TBR=dnicoara@chromium.org,rjkroege@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=620927

Review-Url: https://codereview.chromium.org/2873153005
Cr-Commit-Position: refs/heads/master@{#471033}
parent 8223eacf
......@@ -162,7 +162,6 @@ source_set("gbm_unittests") {
"gpu/mock_scanout_buffer.h",
"gpu/mock_scanout_buffer_generator.cc",
"gpu/mock_scanout_buffer_generator.h",
"gpu/proxy_helpers_unittest.cc",
"gpu/screen_manager_unittest.cc",
]
......
......@@ -22,15 +22,6 @@ void PostAsyncTask(
task_runner->PostTask(FROM_HERE, base::Bind(callback, args...));
}
template <typename... Args>
void PostAsyncTaskOnce(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
base::OnceCallback<void(Args...)> callback,
Args... args) {
auto closure = base::BindOnce(std::move(callback), std::move(args)...);
task_runner->PostTask(FROM_HERE, std::move(closure));
}
} // namespace internal
// Posts a task to a different thread and blocks waiting for the task to finish
......@@ -49,17 +40,6 @@ base::Callback<void(Args...)> CreateSafeCallback(
base::ThreadTaskRunnerHandle::Get(), callback);
}
// Creates a OnceCallback that will run |callback| on the calling thread. Useful
// when posting a task on a different thread and expecting a callback when the
// task finished (and the callback needs to run on the original thread).
template <typename... Args>
base::OnceCallback<void(Args...)> CreateSafeOnceCallback(
base::OnceCallback<void(Args...)> callback) {
return base::BindOnce(&internal::PostAsyncTaskOnce<Args...>,
base::ThreadTaskRunnerHandle::Get(),
std::move(callback));
}
} // namespace ui
#endif // UI_OZONE_PLATFORM_DRM_GPU_PROXY_HELPERS_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/drm/gpu/proxy_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ui {
class ProxyHelpersTest : public testing::Test {
public:
void SetUp() override {
drm_thread_.reset(new base::Thread("drm_thread"));
drm_thread_->Start();
}
void TearDown() override {
drm_thread_->Stop();
drm_thread_ = nullptr;
}
// QuitFunction runs on the DRM thread.
void QuitFunction(int a) {
EXPECT_TRUE(drm_checker_.CalledOnValidThread());
EXPECT_FALSE(main_checker_.CalledOnValidThread());
message_loop_.task_runner()->PostTask(
FROM_HERE, base::Bind(&ProxyHelpersTest::QuitFunctionCallback,
base::Unretained(this), 8));
}
// QuitFunctionCallback runs on the main thread.
void QuitFunctionCallback(int a) {
EXPECT_FALSE(drm_checker_.CalledOnValidThread());
EXPECT_TRUE(main_checker_.CalledOnValidThread());
auto quitter = run_loop_.QuitWhenIdleClosure();
message_loop_.task_runner()->PostTask(FROM_HERE, quitter);
}
void SetDrmChecker() { drm_checker_.DetachFromThread(); }
void MoveType(int a,
base::OnceCallback<void(std::unique_ptr<int>)> callback) {
EXPECT_TRUE(drm_checker_.CalledOnValidThread());
EXPECT_FALSE(main_checker_.CalledOnValidThread());
std::unique_ptr<int> p(new int);
*p = a + 1;
std::move(callback).Run(std::move(p));
}
void MoveTypeCallback(std::unique_ptr<int> p) {
EXPECT_FALSE(drm_checker_.CalledOnValidThread());
EXPECT_TRUE(main_checker_.CalledOnValidThread());
*p = *p + 1;
move_type_.swap(p);
EXPECT_EQ(*p, 50);
}
void ValueType(int a, base::OnceCallback<void(int)> callback) {
EXPECT_TRUE(drm_checker_.CalledOnValidThread());
EXPECT_FALSE(main_checker_.CalledOnValidThread());
std::move(callback).Run(a + 1);
}
void ValueTypeCallback(int a) {
EXPECT_FALSE(drm_checker_.CalledOnValidThread());
EXPECT_TRUE(main_checker_.CalledOnValidThread());
value_type_ = a + 1;
}
void StringType(std::string a,
base::OnceCallback<void(std::string)> callback) {
EXPECT_TRUE(drm_checker_.CalledOnValidThread());
EXPECT_FALSE(main_checker_.CalledOnValidThread());
std::move(callback).Run(a.append("e"));
}
void StringTypeCallback(std::string a) {
EXPECT_FALSE(drm_checker_.CalledOnValidThread());
EXPECT_TRUE(main_checker_.CalledOnValidThread());
derived_string_ = a.append("r");
}
protected:
// Main thread message loop.
base::MessageLoop message_loop_;
base::RunLoop run_loop_;
// Thread to simulate the drm thread in ozone viz process.
std::unique_ptr<base::Thread> drm_thread_;
base::ThreadChecker main_checker_;
base::ThreadChecker drm_checker_;
// Variables to record operation.
int value_type_ = 0;
std::unique_ptr<int> move_type_;
std::string original_string_;
std::string derived_string_;
};
TEST_F(ProxyHelpersTest, PostTask) {
// Binds the thread checker on the drm thread.
drm_thread_->task_runner()->PostTask(
FROM_HERE,
base::Bind(&ProxyHelpersTest::SetDrmChecker, base::Unretained(this)));
// Test passing a type by value.
auto value_callback = base::BindOnce(&ProxyHelpersTest::ValueTypeCallback,
base::Unretained(this));
auto safe_value_callback = CreateSafeOnceCallback(std::move(value_callback));
drm_thread_->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&ProxyHelpersTest::ValueType, base::Unretained(this), 100,
std::move(safe_value_callback)));
// Test passing a move-only type.
move_type_.reset(new int);
*move_type_ = 50;
auto move_callback = base::BindOnce(&ProxyHelpersTest::MoveTypeCallback,
base::Unretained(this));
auto safe_move_callback = CreateSafeOnceCallback(std::move(move_callback));
drm_thread_->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&ProxyHelpersTest::MoveType, base::Unretained(this), 100,
std::move(safe_move_callback)));
// Test that passing a type that supports both move and value semantics
// defaults to value.
original_string_ = "This is a string";
auto string_callback = base::BindOnce(&ProxyHelpersTest::StringTypeCallback,
base::Unretained(this));
auto safe_string_callback =
CreateSafeOnceCallback(std::move(string_callback));
drm_thread_->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&ProxyHelpersTest::StringType, base::Unretained(this),
original_string_, std::move(safe_string_callback)));
// Shutdown the RunLoop.
drm_thread_->task_runner()->PostTask(
FROM_HERE,
base::Bind(&ProxyHelpersTest::QuitFunction, base::Unretained(this), 42));
run_loop_.Run();
EXPECT_EQ(value_type_, 102);
EXPECT_EQ(*move_type_, 102);
EXPECT_TRUE(original_string_ == "This is a string");
EXPECT_TRUE(derived_string_ == "This is a stringer");
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment