Commit a4430e12 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate USBDevice to use GC mojo wrappers.

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

Bug: 1049056
Change-Id: I88f42b8d68640e0d239adaa6bd09633be1295809
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142887Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758480}
parent e4cf1297
......@@ -186,11 +186,13 @@ USBDevice::USBDevice(UsbDeviceInfoPtr device_info,
ExecutionContext* context)
: ExecutionContextLifecycleObserver(context),
device_info_(std::move(device_info)),
device_(std::move(device)),
device_(context),
opened_(false),
device_state_change_in_progress_(false),
configuration_index_(kNotFound) {
if (device_) {
device_.Bind(std::move(device),
context->GetTaskRunner(TaskType::kMiscPlatformAPI));
if (device_.is_bound()) {
device_.set_disconnect_handler(
WTF::Bind(&USBDevice::OnConnectionError, WrapWeakPersistent(this)));
}
......@@ -591,11 +593,11 @@ ScriptPromise USBDevice::reset(ScriptState* script_state) {
}
void USBDevice::ContextDestroyed() {
device_.reset();
device_requests_.clear();
}
void USBDevice::Trace(Visitor* visitor) {
visitor->Trace(device_);
visitor->Trace(device_requests_);
ScriptWrappable::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
......@@ -676,7 +678,7 @@ bool USBDevice::IsProtectedInterfaceClass(wtf_size_t interface_index) const {
bool USBDevice::EnsureNoDeviceChangeInProgress(
ScriptPromiseResolver* resolver) const {
if (!device_) {
if (!device_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotFoundError, kDeviceDisconnected));
return false;
......
......@@ -7,13 +7,13 @@
#include <bitset>
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/usb_device.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/array_buffer_or_array_buffer_view.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
......@@ -168,7 +168,7 @@ class USBDevice : public ScriptWrappable,
bool MarkRequestComplete(ScriptPromiseResolver*);
device::mojom::blink::UsbDeviceInfoPtr device_info_;
mojo::Remote<device::mojom::blink::UsbDevice> device_;
HeapMojoRemote<device::mojom::blink::UsbDevice> device_;
HeapHashSet<Member<ScriptPromiseResolver>> device_requests_;
bool opened_;
bool device_state_change_in_progress_;
......
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