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