Commit 5164b1bd authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Migrate idle_manager.mojom to the new Mojo types

This CL converts implementations of idle_manager.mojom
both the browser process(IdleMonitor) and the renderer process
(IdleDetector) in idle_manager.mojom.

 - Change mojo::Binding with mojo::Receiver
 - Change IdleManagerPtr with mojo::Remote<IdleManager>

Bug: 955171
Change-Id: I5e5b33cef0ee01b86e44e0778dbb2cd5ab9ac45d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1750508
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#686691}
parent 70036542
...@@ -80,8 +80,9 @@ void IdleManager::CreateService(blink::mojom::IdleManagerRequest request) { ...@@ -80,8 +80,9 @@ void IdleManager::CreateService(blink::mojom::IdleManagerRequest request) {
bindings_.AddBinding(this, std::move(request)); bindings_.AddBinding(this, std::move(request));
} }
void IdleManager::AddMonitor(base::TimeDelta threshold, void IdleManager::AddMonitor(
blink::mojom::IdleMonitorPtr monitor_ptr, base::TimeDelta threshold,
mojo::PendingRemote<blink::mojom::IdleMonitor> monitor_remote,
AddMonitorCallback callback) { AddMonitorCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (threshold < kMinimumThreshold) { if (threshold < kMinimumThreshold) {
...@@ -90,7 +91,7 @@ void IdleManager::AddMonitor(base::TimeDelta threshold, ...@@ -90,7 +91,7 @@ void IdleManager::AddMonitor(base::TimeDelta threshold,
} }
auto monitor = std::make_unique<IdleMonitor>( auto monitor = std::make_unique<IdleMonitor>(
std::move(monitor_ptr), CheckIdleState(threshold), threshold); std::move(monitor_remote), CheckIdleState(threshold), threshold);
// This unretained reference is safe because IdleManager owns all IdleMonitor // This unretained reference is safe because IdleManager owns all IdleMonitor
// instances. // instances.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "content/browser/idle/idle_monitor.h" #include "content/browser/idle/idle_monitor.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/mojom/idle/idle_manager.mojom.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom.h"
#include "ui/base/idle/idle.h" #include "ui/base/idle/idle.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -54,7 +55,7 @@ class CONTENT_EXPORT IdleManager : public blink::mojom::IdleManager { ...@@ -54,7 +55,7 @@ class CONTENT_EXPORT IdleManager : public blink::mojom::IdleManager {
// blink.mojom.IdleManager: // blink.mojom.IdleManager:
void AddMonitor(base::TimeDelta threshold, void AddMonitor(base::TimeDelta threshold,
blink::mojom::IdleMonitorPtr monitor_ptr, mojo::PendingRemote<blink::mojom::IdleMonitor> monitor_remote,
AddMonitorCallback callback) override; AddMonitorCallback callback) override;
// Testing helpers. // Testing helpers.
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/public/test/test_service_manager_context.h" #include "content/public/test/test_service_manager_context.h"
#include "content/test/test_render_frame_host.h" #include "content/test/test_render_frame_host.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/cpp/test_support/test_utils.h"
#include "services/service_manager/public/cpp/bind_source_info.h" #include "services/service_manager/public/cpp/bind_source_info.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
...@@ -76,16 +77,15 @@ TEST_F(IdleManagerTest, AddMonitor) { ...@@ -76,16 +77,15 @@ TEST_F(IdleManagerTest, AddMonitor) {
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr; MockIdleMonitor monitor;
blink::mojom::IdleMonitorRequest monitor_request = mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
mojo::MakeRequest(&monitor_ptr);
base::RunLoop loop; base::RunLoop loop;
service_ptr.set_connection_error_handler(base::BindLambdaForTesting([&]() { service_remote.set_disconnect_handler(base::BindLambdaForTesting([&]() {
ADD_FAILURE() << "Unexpected connection error"; ADD_FAILURE() << "Unexpected connection error";
loop.Quit(); loop.Quit();
...@@ -97,8 +97,8 @@ TEST_F(IdleManagerTest, AddMonitor) { ...@@ -97,8 +97,8 @@ TEST_F(IdleManagerTest, AddMonitor) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindOnce( base::BindOnce(
[](base::OnceClosure callback, blink::mojom::IdleStatePtr state) { [](base::OnceClosure callback, blink::mojom::IdleStatePtr state) {
// The initial state of the status of the user is to be active. // The initial state of the status of the user is to be active.
...@@ -112,18 +112,15 @@ TEST_F(IdleManagerTest, AddMonitor) { ...@@ -112,18 +112,15 @@ TEST_F(IdleManagerTest, AddMonitor) {
} }
TEST_F(IdleManagerTest, Idle) { TEST_F(IdleManagerTest, Idle) {
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr;
auto monitor_request = mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor; MockIdleMonitor monitor;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding( mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
&monitor, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -131,8 +128,8 @@ TEST_F(IdleManagerTest, Idle) { ...@@ -131,8 +128,8 @@ TEST_F(IdleManagerTest, Idle) {
EXPECT_CALL(*mock, CalculateIdleTime()) EXPECT_CALL(*mock, CalculateIdleTime())
.WillRepeatedly(testing::Return(base::TimeDelta::FromSeconds(0))); .WillRepeatedly(testing::Return(base::TimeDelta::FromSeconds(0)));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user); EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user);
loop.Quit(); loop.Quit();
...@@ -175,18 +172,15 @@ TEST_F(IdleManagerTest, Idle) { ...@@ -175,18 +172,15 @@ TEST_F(IdleManagerTest, Idle) {
} }
TEST_F(IdleManagerTest, UnlockingScreen) { TEST_F(IdleManagerTest, UnlockingScreen) {
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr;
auto monitor_request = mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor; MockIdleMonitor monitor;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding( mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
&monitor, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -195,8 +189,8 @@ TEST_F(IdleManagerTest, UnlockingScreen) { ...@@ -195,8 +189,8 @@ TEST_F(IdleManagerTest, UnlockingScreen) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(true)); .WillRepeatedly(testing::Return(true));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::ScreenIdleState::kLocked, state->screen); EXPECT_EQ(blink::mojom::ScreenIdleState::kLocked, state->screen);
loop.Quit(); loop.Quit();
...@@ -224,18 +218,15 @@ TEST_F(IdleManagerTest, UnlockingScreen) { ...@@ -224,18 +218,15 @@ TEST_F(IdleManagerTest, UnlockingScreen) {
} }
TEST_F(IdleManagerTest, LockingScreen) { TEST_F(IdleManagerTest, LockingScreen) {
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr;
auto monitor_request = mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor; MockIdleMonitor monitor;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding( mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
&monitor, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -244,8 +235,8 @@ TEST_F(IdleManagerTest, LockingScreen) { ...@@ -244,8 +235,8 @@ TEST_F(IdleManagerTest, LockingScreen) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen); EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen);
loop.Quit(); loop.Quit();
...@@ -273,18 +264,15 @@ TEST_F(IdleManagerTest, LockingScreen) { ...@@ -273,18 +264,15 @@ TEST_F(IdleManagerTest, LockingScreen) {
} }
TEST_F(IdleManagerTest, LockingScreenThenIdle) { TEST_F(IdleManagerTest, LockingScreenThenIdle) {
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr;
auto monitor_request = mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor; MockIdleMonitor monitor;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding( mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
&monitor, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -293,8 +281,8 @@ TEST_F(IdleManagerTest, LockingScreenThenIdle) { ...@@ -293,8 +281,8 @@ TEST_F(IdleManagerTest, LockingScreenThenIdle) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user); EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user);
EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen); EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen);
...@@ -345,18 +333,15 @@ TEST_F(IdleManagerTest, LockingScreenThenIdle) { ...@@ -345,18 +333,15 @@ TEST_F(IdleManagerTest, LockingScreenThenIdle) {
} }
TEST_F(IdleManagerTest, LockingScreenAfterIdle) { TEST_F(IdleManagerTest, LockingScreenAfterIdle) {
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr;
auto monitor_request = mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor; MockIdleMonitor monitor;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding( mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
&monitor, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
...@@ -367,8 +352,8 @@ TEST_F(IdleManagerTest, LockingScreenAfterIdle) { ...@@ -367,8 +352,8 @@ TEST_F(IdleManagerTest, LockingScreenAfterIdle) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user); EXPECT_EQ(blink::mojom::UserIdleState::kActive, state->user);
EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen); EXPECT_EQ(blink::mojom::ScreenIdleState::kUnlocked, state->screen);
...@@ -427,21 +412,17 @@ TEST_F(IdleManagerTest, RemoveMonitorStopsPolling) { ...@@ -427,21 +412,17 @@ TEST_F(IdleManagerTest, RemoveMonitorStopsPolling) {
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr; MockIdleMonitor monitor;
blink::mojom::IdleMonitorRequest monitor_request = mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
mojo::MakeRequest(&monitor_ptr);
MockIdleMonitor monitor_impl;
mojo::Binding<blink::mojom::IdleMonitor> monitor_binding(
&monitor_impl, std::move(monitor_request));
{ {
base::RunLoop loop; base::RunLoop loop;
service_ptr->AddMonitor( service_remote->AddMonitor(
kThreshold, std::move(monitor_ptr), kThreshold, monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](blink::mojom::IdleStatePtr state) { loop.Quit(); })); [&](blink::mojom::IdleStatePtr state) { loop.Quit(); }));
...@@ -454,7 +435,7 @@ TEST_F(IdleManagerTest, RemoveMonitorStopsPolling) { ...@@ -454,7 +435,7 @@ TEST_F(IdleManagerTest, RemoveMonitorStopsPolling) {
base::RunLoop loop; base::RunLoop loop;
// Simulates the renderer disconnecting. // Simulates the renderer disconnecting.
monitor_binding.Close(); monitor_receiver.reset();
// Wait for the IdleManager to observe the pipe close. // Wait for the IdleManager to observe the pipe close.
loop.RunUntilIdle(); loop.RunUntilIdle();
...@@ -467,12 +448,11 @@ TEST_F(IdleManagerTest, Threshold) { ...@@ -467,12 +448,11 @@ TEST_F(IdleManagerTest, Threshold) {
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr; MockIdleMonitor monitor;
blink::mojom::IdleMonitorRequest monitor_request = mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
mojo::MakeRequest(&monitor_ptr);
base::RunLoop loop; base::RunLoop loop;
...@@ -482,8 +462,9 @@ TEST_F(IdleManagerTest, Threshold) { ...@@ -482,8 +462,9 @@ TEST_F(IdleManagerTest, Threshold) {
EXPECT_CALL(*mock, CheckIdleStateIsLocked()) EXPECT_CALL(*mock, CheckIdleStateIsLocked())
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
service_ptr->AddMonitor( service_remote->AddMonitor(
base::TimeDelta::FromSeconds(90), std::move(monitor_ptr), base::TimeDelta::FromSeconds(90),
monitor_receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) { base::BindLambdaForTesting([&](blink::mojom::IdleStatePtr state) {
EXPECT_EQ(blink::mojom::UserIdleState::kIdle, state->user); EXPECT_EQ(blink::mojom::UserIdleState::kIdle, state->user);
loop.Quit(); loop.Quit();
...@@ -497,19 +478,19 @@ TEST_F(IdleManagerTest, BadThreshold) { ...@@ -497,19 +478,19 @@ TEST_F(IdleManagerTest, BadThreshold) {
auto impl = std::make_unique<IdleManager>(); auto impl = std::make_unique<IdleManager>();
auto* mock = new NiceMock<MockIdleTimeProvider>(); auto* mock = new NiceMock<MockIdleTimeProvider>();
impl->SetIdleTimeProviderForTest(base::WrapUnique(mock)); impl->SetIdleTimeProviderForTest(base::WrapUnique(mock));
blink::mojom::IdleManagerPtr service_ptr; mojo::Remote<blink::mojom::IdleManager> service_remote;
impl->CreateService(mojo::MakeRequest(&service_ptr)); impl->CreateService(service_remote.BindNewPipeAndPassReceiver());
blink::mojom::IdleMonitorPtr monitor_ptr; MockIdleMonitor monitor;
blink::mojom::IdleMonitorRequest monitor_request = mojo::Receiver<blink::mojom::IdleMonitor> monitor_receiver(&monitor);
mojo::MakeRequest(&monitor_ptr);
// Should not start initial state of the system. // Should not start initial state of the system.
EXPECT_CALL(*mock, CalculateIdleTime()).Times(0); EXPECT_CALL(*mock, CalculateIdleTime()).Times(0);
EXPECT_CALL(*mock, CheckIdleStateIsLocked()).Times(0); EXPECT_CALL(*mock, CheckIdleStateIsLocked()).Times(0);
service_ptr->AddMonitor(base::TimeDelta::FromSeconds(50), service_remote->AddMonitor(base::TimeDelta::FromSeconds(50),
std::move(monitor_ptr), base::NullCallback()); monitor_receiver.BindNewPipeAndPassRemote(),
base::NullCallback());
EXPECT_EQ("Minimum threshold is 60 seconds.", EXPECT_EQ("Minimum threshold is 60 seconds.",
bad_message_observer.WaitForBadMessage()); bad_message_observer.WaitForBadMessage());
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace content { namespace content {
IdleMonitor::IdleMonitor(blink::mojom::IdleMonitorPtr monitor, IdleMonitor::IdleMonitor(mojo::PendingRemote<blink::mojom::IdleMonitor> monitor,
blink::mojom::IdleStatePtr last_state, blink::mojom::IdleStatePtr last_state,
base::TimeDelta threshold) base::TimeDelta threshold)
: client_(std::move(monitor)), : client_(std::move(monitor)),
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/connection_error_callback.h" #include "mojo/public/cpp/bindings/connection_error_callback.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/mojom/idle/idle_manager.mojom.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom.h"
#include "ui/base/idle/idle.h" #include "ui/base/idle/idle.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -25,7 +26,7 @@ namespace content { ...@@ -25,7 +26,7 @@ namespace content {
class CONTENT_EXPORT IdleMonitor : public base::LinkNode<IdleMonitor> { class CONTENT_EXPORT IdleMonitor : public base::LinkNode<IdleMonitor> {
public: public:
IdleMonitor(blink::mojom::IdleMonitorPtr monitor, IdleMonitor(mojo::PendingRemote<blink::mojom::IdleMonitor> monitor,
blink::mojom::IdleStatePtr last_state, blink::mojom::IdleStatePtr last_state,
base::TimeDelta threshold); base::TimeDelta threshold);
~IdleMonitor(); ~IdleMonitor();
......
...@@ -34,6 +34,7 @@ interface IdleManager { ...@@ -34,6 +34,7 @@ interface IdleManager {
// initial state. It will be notified by calls to Update() per the threshold // initial state. It will be notified by calls to Update() per the threshold
// registered for this instance. It can be unregistered by simply closing // registered for this instance. It can be unregistered by simply closing
// the pipe. // the pipe.
AddMonitor(mojo_base.mojom.TimeDelta threshold, IdleMonitor monitor) AddMonitor(mojo_base.mojom.TimeDelta threshold,
pending_remote<IdleMonitor> monitor)
=> (IdleState state); => (IdleState state);
}; };
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
...@@ -52,7 +53,7 @@ IdleDetector* IdleDetector::Create(ScriptState* script_state, ...@@ -52,7 +53,7 @@ IdleDetector* IdleDetector::Create(ScriptState* script_state,
} }
IdleDetector::IdleDetector(ExecutionContext* context, base::TimeDelta threshold) IdleDetector::IdleDetector(ExecutionContext* context, base::TimeDelta threshold)
: ContextClient(context), threshold_(threshold), binding_(this) {} : ContextClient(context), threshold_(threshold), receiver_(this) {}
IdleDetector::~IdleDetector() = default; IdleDetector::~IdleDetector() = default;
...@@ -98,7 +99,7 @@ void IdleDetector::stop() { ...@@ -98,7 +99,7 @@ void IdleDetector::stop() {
} }
void IdleDetector::StartMonitoring() { void IdleDetector::StartMonitoring() {
if (binding_.is_bound()) { if (receiver_.is_bound()) {
return; return;
} }
...@@ -108,19 +109,20 @@ void IdleDetector::StartMonitoring() { ...@@ -108,19 +109,20 @@ void IdleDetector::StartMonitoring() {
if (!service_) { if (!service_) {
GetExecutionContext()->GetInterfaceProvider()->GetInterface( GetExecutionContext()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&service_, task_runner)); service_.BindNewPipeAndPassReceiver());
} }
mojom::blink::IdleMonitorPtr monitor_ptr; mojo::PendingRemote<mojom::blink::IdleMonitor> idle_monitor_remote;
binding_.Bind(mojo::MakeRequest(&monitor_ptr, task_runner), task_runner); receiver_.Bind(idle_monitor_remote.InitWithNewPipeAndPassReceiver(),
task_runner);
service_->AddMonitor( service_->AddMonitor(
threshold_, std::move(monitor_ptr), threshold_, std::move(idle_monitor_remote),
WTF::Bind(&IdleDetector::OnAddMonitor, WrapWeakPersistent(this))); WTF::Bind(&IdleDetector::OnAddMonitor, WrapWeakPersistent(this)));
} }
void IdleDetector::StopMonitoring() { void IdleDetector::StopMonitoring() {
binding_.Close(); receiver_.reset();
} }
void IdleDetector::OnAddMonitor(mojom::blink::IdleStatePtr state) { void IdleDetector::OnAddMonitor(mojom::blink::IdleStatePtr state) {
...@@ -132,7 +134,7 @@ blink::IdleState* IdleDetector::state() const { ...@@ -132,7 +134,7 @@ blink::IdleState* IdleDetector::state() const {
} }
void IdleDetector::Update(mojom::blink::IdleStatePtr state) { void IdleDetector::Update(mojom::blink::IdleStatePtr state) {
DCHECK(binding_.is_bound()); DCHECK(receiver_.is_bound());
if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed())
return; return;
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_IDLE_IDLE_DETECTOR_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_IDLE_IDLE_DETECTOR_H_
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
...@@ -69,12 +70,12 @@ class IdleDetector final : public EventTargetWithInlineData, ...@@ -69,12 +70,12 @@ class IdleDetector final : public EventTargetWithInlineData,
// Holds a pipe which the service uses to notify this object // Holds a pipe which the service uses to notify this object
// when the idle state has changed. // when the idle state has changed.
mojo::Binding<mojom::blink::IdleMonitor> binding_; mojo::Receiver<mojom::blink::IdleMonitor> receiver_;
void StartMonitoring(); void StartMonitoring();
void StopMonitoring(); void StopMonitoring();
mojom::blink::IdleManagerPtr service_; mojo::Remote<mojom::blink::IdleManager> service_;
DISALLOW_COPY_AND_ASSIGN(IdleDetector); DISALLOW_COPY_AND_ASSIGN(IdleDetector);
}; };
......
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