Commit 6280e33c authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate power_monitor_test.mojom to the new Mojo types

Convert the implementation and all users of the
content::mojom::PowerMonitorTest interface.

Bug: 955171
Change-Id: If6fd5af9f155de275ba3ed1a136f4605605faf63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1800753
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698894}
parent 901361f1
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -47,13 +49,14 @@ void VerifyPowerStateInChildProcess(mojom::PowerMonitorTest* power_monitor_test, ...@@ -47,13 +49,14 @@ void VerifyPowerStateInChildProcess(mojom::PowerMonitorTest* power_monitor_test,
run_loop.Run(); run_loop.Run();
} }
void StartUtilityProcessOnIOThread(mojom::PowerMonitorTestRequest request) { void StartUtilityProcessOnIOThread(
mojo::PendingReceiver<mojom::PowerMonitorTest> receiver) {
UtilityProcessHost* host = new UtilityProcessHost(); UtilityProcessHost* host = new UtilityProcessHost();
host->SetMetricsName("test_process"); host->SetMetricsName("test_process");
host->SetName(base::ASCIIToUTF16("TestProcess")); host->SetName(base::ASCIIToUTF16("TestProcess"));
EXPECT_TRUE(host->Start()); EXPECT_TRUE(host->Start());
BindInterface(host, std::move(request)); BindInterface(host, std::move(receiver));
} }
void BindInterfaceForGpuOnIOThread( void BindInterfaceForGpuOnIOThread(
...@@ -149,12 +152,14 @@ class PowerMonitorTest : public ContentBrowserTest { ...@@ -149,12 +152,14 @@ class PowerMonitorTest : public ContentBrowserTest {
} }
protected: protected:
void StartUtilityProcess(mojom::PowerMonitorTestPtr* power_monitor_test, void StartUtilityProcess(
base::Closure utility_bound_closure) { mojo::Remote<mojom::PowerMonitorTest>* power_monitor_test,
base::Closure utility_bound_closure) {
utility_bound_closure_ = std::move(utility_bound_closure); utility_bound_closure_ = std::move(utility_bound_closure);
base::PostTask(FROM_HERE, {BrowserThread::IO}, base::PostTask(
base::BindOnce(&StartUtilityProcessOnIOThread, FROM_HERE, {BrowserThread::IO},
mojo::MakeRequest(power_monitor_test))); base::BindOnce(&StartUtilityProcessOnIOThread,
power_monitor_test->BindNewPipeAndPassReceiver()));
} }
void set_renderer_bound_closure(base::Closure closure) { void set_renderer_bound_closure(base::Closure closure) {
...@@ -194,14 +199,16 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestRendererProcess) { ...@@ -194,14 +199,16 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestRendererProcess) {
run_loop.Run(); run_loop.Run();
EXPECT_EQ(1, request_count_from_renderer()); EXPECT_EQ(1, request_count_from_renderer());
mojom::PowerMonitorTestPtr power_monitor_renderer; mojo::PendingRemote<mojom::PowerMonitorTest> pending_power_monitor_renderer;
RenderProcessHost* rph = RenderProcessHost* rph =
shell()->web_contents()->GetMainFrame()->GetProcess(); shell()->web_contents()->GetMainFrame()->GetProcess();
BindInterface(rph, &power_monitor_renderer); BindInterface(rph, &pending_power_monitor_renderer);
// Ensure that the PowerMonitorTestImpl instance has been created and is // Ensure that the PowerMonitorTestImpl instance has been created and is
// observing power state changes in the child process before simulating a // observing power state changes in the child process before simulating a
// power state change. // power state change.
mojo::Remote<mojom::PowerMonitorTest> power_monitor_renderer(
std::move(pending_power_monitor_renderer));
power_monitor_renderer.FlushForTesting(); power_monitor_renderer.FlushForTesting();
SimulatePowerStateChange(true); SimulatePowerStateChange(true);
...@@ -214,7 +221,7 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestRendererProcess) { ...@@ -214,7 +221,7 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestRendererProcess) {
} }
IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestUtilityProcess) { IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestUtilityProcess) {
mojom::PowerMonitorTestPtr power_monitor_utility; mojo::Remote<mojom::PowerMonitorTest> power_monitor_utility;
ASSERT_EQ(0, request_count_from_utility()); ASSERT_EQ(0, request_count_from_utility());
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -250,10 +257,11 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestGpuProcess) { ...@@ -250,10 +257,11 @@ IN_PROC_BROWSER_TEST_F(PowerMonitorTest, TestGpuProcess) {
} }
EXPECT_EQ(1, request_count_from_gpu()); EXPECT_EQ(1, request_count_from_gpu());
mojom::PowerMonitorTestPtr power_monitor_gpu; mojo::Remote<mojom::PowerMonitorTest> power_monitor_gpu;
base::PostTask(FROM_HERE, {BrowserThread::IO}, base::PostTask(
base::BindOnce(&BindInterfaceForGpuOnIOThread, FROM_HERE, {BrowserThread::IO},
mojo::MakeRequest(&power_monitor_gpu))); base::BindOnce(&BindInterfaceForGpuOnIOThread,
power_monitor_gpu.BindNewPipeAndPassReceiver()));
// Ensure that the PowerMonitorTestImpl instance has been created and is // Ensure that the PowerMonitorTestImpl instance has been created and is
// observing power state changes in the child process before simulating a // observing power state changes in the child process before simulating a
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_GPU_INTERFACE_REGISTRY_H_ #ifndef CONTENT_PUBLIC_BROWSER_GPU_SERVICE_REGISTRY_H_
#define CONTENT_PUBLIC_BROWSER_GPU_INTERFACE_REGISTRY_H_ #define CONTENT_PUBLIC_BROWSER_GPU_SERVICE_REGISTRY_H_
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -26,4 +26,4 @@ void BindInterfaceInGpuProcess(mojo::PendingReceiver<Interface> receiver) { ...@@ -26,4 +26,4 @@ void BindInterfaceInGpuProcess(mojo::PendingReceiver<Interface> receiver) {
} // namespace content } // namespace content
#endif // CONTENT_PUBLIC_BROWSER_GPU_INTERFACE_REGISTRY_H_ #endif // CONTENT_PUBLIC_BROWSER_GPU_SERVICE_REGISTRY_H_
...@@ -4,15 +4,20 @@ ...@@ -4,15 +4,20 @@
#include "content/shell/common/power_monitor_test_impl.h" #include "content/shell/common/power_monitor_test_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include <memory>
#include <utility>
#include "content/shell/common/power_monitor_test.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace content { namespace content {
// static // static
void PowerMonitorTestImpl::MakeStrongBinding( void PowerMonitorTestImpl::MakeSelfOwnedReceiver(
mojom::PowerMonitorTestRequest request) { mojo::PendingReceiver<mojom::PowerMonitorTest> receiver) {
mojo::MakeStrongBinding(std::make_unique<PowerMonitorTestImpl>(), mojo::MakeSelfOwnedReceiver(std::make_unique<PowerMonitorTestImpl>(),
std::move(request)); std::move(receiver));
} }
PowerMonitorTestImpl::PowerMonitorTestImpl() { PowerMonitorTestImpl::PowerMonitorTestImpl() {
......
...@@ -5,19 +5,18 @@ ...@@ -5,19 +5,18 @@
#ifndef CONTENT_SHELL_COMMON_POWER_MONITOR_TEST_IMPL_H_ #ifndef CONTENT_SHELL_COMMON_POWER_MONITOR_TEST_IMPL_H_
#define CONTENT_SHELL_COMMON_POWER_MONITOR_TEST_IMPL_H_ #define CONTENT_SHELL_COMMON_POWER_MONITOR_TEST_IMPL_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/power_monitor/power_monitor.h" #include "base/power_monitor/power_monitor.h"
#include "content/shell/common/power_monitor_test.mojom.h" #include "content/shell/common/power_monitor_test.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace content { namespace content {
class PowerMonitorTestImpl : public base::PowerObserver, class PowerMonitorTestImpl : public base::PowerObserver,
public mojom::PowerMonitorTest { public mojom::PowerMonitorTest {
public: public:
static void MakeStrongBinding( static void MakeSelfOwnedReceiver(
mojom::PowerMonitorTestRequest request); mojo::PendingReceiver<mojom::PowerMonitorTest> receiver);
PowerMonitorTestImpl(); PowerMonitorTestImpl();
~PowerMonitorTestImpl() override; ~PowerMonitorTestImpl() override;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "content/shell/gpu/shell_content_gpu_client.h" #include "content/shell/gpu/shell_content_gpu_client.h"
#include "base/bind.h" #include "base/bind.h"
#include "content/shell/common/power_monitor_test.mojom.h"
#include "content/shell/common/power_monitor_test_impl.h" #include "content/shell/common/power_monitor_test_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
...@@ -18,7 +19,7 @@ ShellContentGpuClient::~ShellContentGpuClient() = default; ...@@ -18,7 +19,7 @@ ShellContentGpuClient::~ShellContentGpuClient() = default;
void ShellContentGpuClient::InitializeRegistry( void ShellContentGpuClient::InitializeRegistry(
service_manager::BinderRegistry* registry) { service_manager::BinderRegistry* registry) {
registry->AddInterface<mojom::PowerMonitorTest>( registry->AddInterface<mojom::PowerMonitorTest>(
base::BindRepeating(&PowerMonitorTestImpl::MakeStrongBinding), base::BindRepeating(&PowerMonitorTestImpl::MakeSelfOwnedReceiver),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/common/simple_connection_filter.h" #include "content/public/common/simple_connection_filter.h"
#include "content/public/test/test_service.mojom.h" #include "content/public/test/test_service.mojom.h"
#include "content/shell/common/power_monitor_test.mojom.h"
#include "content/shell/common/power_monitor_test_impl.h" #include "content/shell/common/power_monitor_test_impl.h"
#include "content/shell/common/shell_switches.h" #include "content/shell/common/shell_switches.h"
#include "content/shell/renderer/shell_render_view_observer.h" #include "content/shell/renderer/shell_render_view_observer.h"
...@@ -119,7 +120,7 @@ void ShellContentRendererClient::RenderThreadStarted() { ...@@ -119,7 +120,7 @@ void ShellContentRendererClient::RenderThreadStarted() {
base::BindRepeating(&CreateRendererTestService), base::BindRepeating(&CreateRendererTestService),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
registry->AddInterface<mojom::PowerMonitorTest>( registry->AddInterface<mojom::PowerMonitorTest>(
base::BindRepeating(&PowerMonitorTestImpl::MakeStrongBinding), base::BindRepeating(&PowerMonitorTestImpl::MakeSelfOwnedReceiver),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
content::ChildThread::Get() content::ChildThread::Get()
->GetServiceManagerConnection() ->GetServiceManagerConnection()
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "content/public/test/test_service.h" #include "content/public/test/test_service.h"
#include "content/public/test/test_service.mojom.h" #include "content/public/test/test_service.mojom.h"
#include "content/public/utility/utility_thread.h" #include "content/public/utility/utility_thread.h"
#include "content/shell/common/power_monitor_test.mojom.h"
#include "content/shell/common/power_monitor_test_impl.h" #include "content/shell/common/power_monitor_test_impl.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
...@@ -105,7 +106,7 @@ void ShellContentUtilityClient::UtilityThreadStarted() { ...@@ -105,7 +106,7 @@ void ShellContentUtilityClient::UtilityThreadStarted() {
registry->AddInterface(base::BindRepeating(&TestUtilityServiceImpl::Create), registry->AddInterface(base::BindRepeating(&TestUtilityServiceImpl::Create),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
registry->AddInterface<mojom::PowerMonitorTest>( registry->AddInterface<mojom::PowerMonitorTest>(
base::BindRepeating(&PowerMonitorTestImpl::MakeStrongBinding), base::BindRepeating(&PowerMonitorTestImpl::MakeSelfOwnedReceiver),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
content::ChildThread::Get() content::ChildThread::Get()
->GetServiceManagerConnection() ->GetServiceManagerConnection()
......
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