Commit 897be7a6 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate Serial to use GC mojo wrappers.

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

Bug: 1049056
Change-Id: Ica922d40136c54683d995e134cdc3df0ea6d8dd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135667Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756242}
parent ae813dd6
...@@ -42,7 +42,9 @@ String TokenToString(const base::UnguessableToken& token) { ...@@ -42,7 +42,9 @@ String TokenToString(const base::UnguessableToken& token) {
} // namespace } // namespace
Serial::Serial(ExecutionContext& execution_context) Serial::Serial(ExecutionContext& execution_context)
: ExecutionContextLifecycleObserver(&execution_context) {} : ExecutionContextLifecycleObserver(&execution_context),
service_(&execution_context),
receiver_(this, &execution_context) {}
ExecutionContext* Serial::GetExecutionContext() const { ExecutionContext* Serial::GetExecutionContext() const {
return ExecutionContextLifecycleObserver::GetExecutionContext(); return ExecutionContextLifecycleObserver::GetExecutionContext();
...@@ -155,10 +157,6 @@ ScriptPromise Serial::requestPort(ScriptState* script_state, ...@@ -155,10 +157,6 @@ ScriptPromise Serial::requestPort(ScriptState* script_state,
return resolver->Promise(); return resolver->Promise();
} }
void Serial::Dispose() {
receiver_.reset();
}
void Serial::GetPort( void Serial::GetPort(
const base::UnguessableToken& token, const base::UnguessableToken& token,
mojo::PendingReceiver<device::mojom::blink::SerialPort> receiver) { mojo::PendingReceiver<device::mojom::blink::SerialPort> receiver) {
...@@ -167,6 +165,8 @@ void Serial::GetPort( ...@@ -167,6 +165,8 @@ void Serial::GetPort(
} }
void Serial::Trace(Visitor* visitor) { void Serial::Trace(Visitor* visitor) {
visitor->Trace(service_);
visitor->Trace(receiver_);
visitor->Trace(get_ports_promises_); visitor->Trace(get_ports_promises_);
visitor->Trace(request_port_promises_); visitor->Trace(request_port_promises_);
visitor->Trace(port_cache_); visitor->Trace(port_cache_);
...@@ -196,7 +196,7 @@ void Serial::AddedEventListener(const AtomicString& event_type, ...@@ -196,7 +196,7 @@ void Serial::AddedEventListener(const AtomicString& event_type,
void Serial::EnsureServiceConnection() { void Serial::EnsureServiceConnection() {
DCHECK(GetExecutionContext()); DCHECK(GetExecutionContext());
if (service_) if (service_.is_bound())
return; return;
auto task_runner = auto task_runner =
...@@ -206,7 +206,7 @@ void Serial::EnsureServiceConnection() { ...@@ -206,7 +206,7 @@ void Serial::EnsureServiceConnection() {
service_.set_disconnect_handler( service_.set_disconnect_handler(
WTF::Bind(&Serial::OnServiceConnectionError, WrapWeakPersistent(this))); WTF::Bind(&Serial::OnServiceConnectionError, WrapWeakPersistent(this)));
service_->SetClient(receiver_.BindNewPipeAndPassRemote()); service_->SetClient(receiver_.BindNewPipeAndPassRemote(task_runner));
} }
void Serial::OnServiceConnectionError() { void Serial::OnServiceConnectionError() {
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/serial/serial.mojom-blink.h" #include "third_party/blink/public/mojom/serial/serial.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h" #include "third_party/blink/renderer/core/dom/events/event_target.h"
...@@ -14,6 +12,9 @@ ...@@ -14,6 +12,9 @@
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.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/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink { namespace blink {
...@@ -29,7 +30,6 @@ class Serial final : public EventTargetWithInlineData, ...@@ -29,7 +30,6 @@ class Serial final : public EventTargetWithInlineData,
public mojom::blink::SerialServiceClient { public mojom::blink::SerialServiceClient {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(Serial); USING_GARBAGE_COLLECTED_MIXIN(Serial);
USING_PRE_FINALIZER(Serial, Dispose);
public: public:
explicit Serial(ExecutionContext&); explicit Serial(ExecutionContext&);
...@@ -53,7 +53,6 @@ class Serial final : public EventTargetWithInlineData, ...@@ -53,7 +53,6 @@ class Serial final : public EventTargetWithInlineData,
const SerialPortRequestOptions*, const SerialPortRequestOptions*,
ExceptionState&); ExceptionState&);
void Dispose();
void GetPort( void GetPort(
const base::UnguessableToken& token, const base::UnguessableToken& token,
mojo::PendingReceiver<device::mojom::blink::SerialPort> receiver); mojo::PendingReceiver<device::mojom::blink::SerialPort> receiver);
...@@ -72,8 +71,12 @@ class Serial final : public EventTargetWithInlineData, ...@@ -72,8 +71,12 @@ class Serial final : public EventTargetWithInlineData,
Vector<mojom::blink::SerialPortInfoPtr>); Vector<mojom::blink::SerialPortInfoPtr>);
void OnRequestPort(ScriptPromiseResolver*, mojom::blink::SerialPortInfoPtr); void OnRequestPort(ScriptPromiseResolver*, mojom::blink::SerialPortInfoPtr);
mojo::Remote<mojom::blink::SerialService> service_; HeapMojoRemote<mojom::blink::SerialService,
mojo::Receiver<mojom::blink::SerialServiceClient> receiver_{this}; HeapMojoWrapperMode::kWithoutContextObserver>
service_;
HeapMojoReceiver<mojom::blink::SerialServiceClient,
HeapMojoWrapperMode::kWithoutContextObserver>
receiver_;
HeapHashSet<Member<ScriptPromiseResolver>> get_ports_promises_; HeapHashSet<Member<ScriptPromiseResolver>> get_ports_promises_;
HeapHashSet<Member<ScriptPromiseResolver>> request_port_promises_; HeapHashSet<Member<ScriptPromiseResolver>> request_port_promises_;
HeapHashMap<String, WeakMember<SerialPort>> port_cache_; HeapHashMap<String, WeakMember<SerialPort>> port_cache_;
......
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