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) { ...@@ -80,9 +80,10 @@ 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,
AddMonitorCallback callback) { mojo::PendingRemote<blink::mojom::IdleMonitor> monitor_remote,
AddMonitorCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (threshold < kMinimumThreshold) { if (threshold < kMinimumThreshold) {
bindings_.ReportBadMessage("Minimum threshold is 60 seconds."); bindings_.ReportBadMessage("Minimum threshold is 60 seconds.");
...@@ -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.
......
...@@ -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