Commit 6c45b9b3 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate IdleDetector to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I6d13ced16e45f608f044d783529003c700ab3ef1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131807
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757016}
parent 4fa6e1da
...@@ -57,14 +57,13 @@ IdleDetector* IdleDetector::Create(ScriptState* script_state, ...@@ -57,14 +57,13 @@ IdleDetector* IdleDetector::Create(ScriptState* script_state,
} }
IdleDetector::IdleDetector(ExecutionContext* context, base::TimeDelta threshold) IdleDetector::IdleDetector(ExecutionContext* context, base::TimeDelta threshold)
: ExecutionContextClient(context), threshold_(threshold), receiver_(this) {} : ExecutionContextClient(context),
threshold_(threshold),
receiver_(this, context),
service_(context) {}
IdleDetector::~IdleDetector() = default; IdleDetector::~IdleDetector() = default;
void IdleDetector::Dispose() {
StopMonitoring();
}
const AtomicString& IdleDetector::InterfaceName() const { const AtomicString& IdleDetector::InterfaceName() const {
return event_target_names::kIdleDetector; return event_target_names::kIdleDetector;
} }
...@@ -98,7 +97,7 @@ ScriptPromise IdleDetector::start(ScriptState* script_state, ...@@ -98,7 +97,7 @@ ScriptPromise IdleDetector::start(ScriptState* script_state,
} }
void IdleDetector::stop() { void IdleDetector::stop() {
StopMonitoring(); receiver_.reset();
} }
void IdleDetector::StartMonitoring() { void IdleDetector::StartMonitoring() {
...@@ -110,7 +109,7 @@ void IdleDetector::StartMonitoring() { ...@@ -110,7 +109,7 @@ void IdleDetector::StartMonitoring() {
scoped_refptr<base::SingleThreadTaskRunner> task_runner = scoped_refptr<base::SingleThreadTaskRunner> task_runner =
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI); GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI);
if (!service_) { if (!service_.is_bound()) {
GetExecutionContext()->GetBrowserInterfaceBroker().GetInterface( GetExecutionContext()->GetBrowserInterfaceBroker().GetInterface(
service_.BindNewPipeAndPassReceiver(task_runner)); service_.BindNewPipeAndPassReceiver(task_runner));
} }
...@@ -124,10 +123,6 @@ void IdleDetector::StartMonitoring() { ...@@ -124,10 +123,6 @@ void IdleDetector::StartMonitoring() {
WTF::Bind(&IdleDetector::OnAddMonitor, WrapWeakPersistent(this))); WTF::Bind(&IdleDetector::OnAddMonitor, WrapWeakPersistent(this)));
} }
void IdleDetector::StopMonitoring() {
receiver_.reset();
}
void IdleDetector::OnAddMonitor(mojom::blink::IdleStatePtr state) { void IdleDetector::OnAddMonitor(mojom::blink::IdleStatePtr state) {
Update(std::move(state)); Update(std::move(state));
} }
...@@ -151,6 +146,8 @@ void IdleDetector::Update(mojom::blink::IdleStatePtr state) { ...@@ -151,6 +146,8 @@ void IdleDetector::Update(mojom::blink::IdleStatePtr state) {
void IdleDetector::Trace(Visitor* visitor) { void IdleDetector::Trace(Visitor* visitor) {
visitor->Trace(state_); visitor->Trace(state_);
visitor->Trace(receiver_);
visitor->Trace(service_);
EventTargetWithInlineData::Trace(visitor); EventTargetWithInlineData::Trace(visitor);
ExecutionContextClient::Trace(visitor); ExecutionContextClient::Trace(visitor);
ActiveScriptWrappable::Trace(visitor); ActiveScriptWrappable::Trace(visitor);
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#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/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink-forward.h" #include "third_party/blink/public/mojom/idle/idle_manager.mojom-blink-forward.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"
...@@ -18,6 +16,8 @@ ...@@ -18,6 +16,8 @@
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/idle/idle_state.h" #include "third_party/blink/renderer/modules/idle/idle_state.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h" #include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink { namespace blink {
...@@ -30,7 +30,6 @@ class IdleDetector final : public EventTargetWithInlineData, ...@@ -30,7 +30,6 @@ class IdleDetector final : public EventTargetWithInlineData,
public mojom::blink::IdleMonitor { public mojom::blink::IdleMonitor {
USING_GARBAGE_COLLECTED_MIXIN(IdleDetector); USING_GARBAGE_COLLECTED_MIXIN(IdleDetector);
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_PRE_FINALIZER(IdleDetector, Dispose);
public: public:
static IdleDetector* Create(ScriptState*, static IdleDetector* Create(ScriptState*,
...@@ -42,8 +41,6 @@ class IdleDetector final : public EventTargetWithInlineData, ...@@ -42,8 +41,6 @@ class IdleDetector final : public EventTargetWithInlineData,
~IdleDetector() override; ~IdleDetector() override;
void Dispose();
// EventTarget implementation. // EventTarget implementation.
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override; ExecutionContext* GetExecutionContext() const override;
...@@ -72,12 +69,16 @@ class IdleDetector final : public EventTargetWithInlineData, ...@@ -72,12 +69,16 @@ 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::Receiver<mojom::blink::IdleMonitor> receiver_; HeapMojoReceiver<mojom::blink::IdleMonitor,
IdleDetector,
HeapMojoWrapperMode::kWithoutContextObserver>
receiver_;
void StartMonitoring(); void StartMonitoring();
void StopMonitoring();
mojo::Remote<mojom::blink::IdleManager> service_; HeapMojoRemote<mojom::blink::IdleManager,
HeapMojoWrapperMode::kWithoutContextObserver>
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