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,9 +80,10 @@ void IdleManager::CreateService(blink::mojom::IdleManagerRequest request) {
bindings_.AddBinding(this, std::move(request));
}
void IdleManager::AddMonitor(base::TimeDelta threshold,
blink::mojom::IdleMonitorPtr monitor_ptr,
AddMonitorCallback callback) {
void IdleManager::AddMonitor(
base::TimeDelta threshold,
mojo::PendingRemote<blink::mojom::IdleMonitor> monitor_remote,
AddMonitorCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (threshold < kMinimumThreshold) {
bindings_.ReportBadMessage("Minimum threshold is 60 seconds.");
......@@ -90,7 +91,7 @@ void IdleManager::AddMonitor(base::TimeDelta threshold,
}
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
// instances.
......
......@@ -16,6 +16,7 @@
#include "base/timer/timer.h"
#include "content/browser/idle/idle_monitor.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 "ui/base/idle/idle.h"
#include "url/origin.h"
......@@ -54,7 +55,7 @@ class CONTENT_EXPORT IdleManager : public blink::mojom::IdleManager {
// blink.mojom.IdleManager:
void AddMonitor(base::TimeDelta threshold,
blink::mojom::IdleMonitorPtr monitor_ptr,
mojo::PendingRemote<blink::mojom::IdleMonitor> monitor_remote,
AddMonitorCallback callback) override;
// Testing helpers.
......
......@@ -15,7 +15,7 @@
namespace content {
IdleMonitor::IdleMonitor(blink::mojom::IdleMonitorPtr monitor,
IdleMonitor::IdleMonitor(mojo::PendingRemote<blink::mojom::IdleMonitor> monitor,
blink::mojom::IdleStatePtr last_state,
base::TimeDelta threshold)
: client_(std::move(monitor)),
......
......@@ -17,6 +17,7 @@
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/binding_set.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 "ui/base/idle/idle.h"
#include "url/origin.h"
......@@ -25,7 +26,7 @@ namespace content {
class CONTENT_EXPORT IdleMonitor : public base::LinkNode<IdleMonitor> {
public:
IdleMonitor(blink::mojom::IdleMonitorPtr monitor,
IdleMonitor(mojo::PendingRemote<blink::mojom::IdleMonitor> monitor,
blink::mojom::IdleStatePtr last_state,
base::TimeDelta threshold);
~IdleMonitor();
......
......@@ -34,6 +34,7 @@ interface IdleManager {
// initial state. It will be notified by calls to Update() per the threshold
// registered for this instance. It can be unregistered by simply closing
// the pipe.
AddMonitor(mojo_base.mojom.TimeDelta threshold, IdleMonitor monitor)
AddMonitor(mojo_base.mojom.TimeDelta threshold,
pending_remote<IdleMonitor> monitor)
=> (IdleState state);
};
......@@ -6,6 +6,7 @@
#include <utility>
#include "mojo/public/cpp/bindings/remote.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/renderer/core/dom/dom_exception.h"
......@@ -52,7 +53,7 @@ IdleDetector* IdleDetector::Create(ScriptState* script_state,
}
IdleDetector::IdleDetector(ExecutionContext* context, base::TimeDelta threshold)
: ContextClient(context), threshold_(threshold), binding_(this) {}
: ContextClient(context), threshold_(threshold), receiver_(this) {}
IdleDetector::~IdleDetector() = default;
......@@ -98,7 +99,7 @@ void IdleDetector::stop() {
}
void IdleDetector::StartMonitoring() {
if (binding_.is_bound()) {
if (receiver_.is_bound()) {
return;
}
......@@ -108,19 +109,20 @@ void IdleDetector::StartMonitoring() {
if (!service_) {
GetExecutionContext()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&service_, task_runner));
service_.BindNewPipeAndPassReceiver());
}
mojom::blink::IdleMonitorPtr monitor_ptr;
binding_.Bind(mojo::MakeRequest(&monitor_ptr, task_runner), task_runner);
mojo::PendingRemote<mojom::blink::IdleMonitor> idle_monitor_remote;
receiver_.Bind(idle_monitor_remote.InitWithNewPipeAndPassReceiver(),
task_runner);
service_->AddMonitor(
threshold_, std::move(monitor_ptr),
threshold_, std::move(idle_monitor_remote),
WTF::Bind(&IdleDetector::OnAddMonitor, WrapWeakPersistent(this)));
}
void IdleDetector::StopMonitoring() {
binding_.Close();
receiver_.reset();
}
void IdleDetector::OnAddMonitor(mojom::blink::IdleStatePtr state) {
......@@ -132,7 +134,7 @@ blink::IdleState* IdleDetector::state() const {
}
void IdleDetector::Update(mojom::blink::IdleStatePtr state) {
DCHECK(binding_.is_bound());
DCHECK(receiver_.is_bound());
if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed())
return;
......
......@@ -6,7 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_IDLE_IDLE_DETECTOR_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/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
......@@ -69,12 +70,12 @@ class IdleDetector final : public EventTargetWithInlineData,
// Holds a pipe which the service uses to notify this object
// when the idle state has changed.
mojo::Binding<mojom::blink::IdleMonitor> binding_;
mojo::Receiver<mojom::blink::IdleMonitor> receiver_;
void StartMonitoring();
void StopMonitoring();
mojom::blink::IdleManagerPtr service_;
mojo::Remote<mojom::blink::IdleManager> service_;
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