Skip to content

Commit

Permalink
heap mojo: migrate BluetoothRemoteGATTCharacteristic
Browse files Browse the repository at this point in the history
Use HeapMojo wrappers so that Oilpan will GC the objects.

BUG=chromium:1049056

Change-Id: I9fb715baaab8fe6c14c759390ace4b10a02221ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2192541
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Johann Koenig <johannkoenig@google.com>
Cr-Commit-Position: refs/heads/master@{#767580}
  • Loading branch information
Johann authored and Commit Bot committed May 12, 2020
1 parent 15cef81 commit dbe5871
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
: ExecutionContextLifecycleObserver(context),
characteristic_(std::move(characteristic)),
service_(service),
device_(device) {
device_(device),
receivers_(this, context) {
properties_ = MakeGarbageCollected<BluetoothCharacteristicProperties>(
characteristic_->properties);
}
Expand All @@ -53,14 +54,6 @@ void BluetoothRemoteGATTCharacteristic::RemoteCharacteristicValueChanged(
DispatchEvent(*Event::Create(event_type_names::kCharacteristicvaluechanged));
}

void BluetoothRemoteGATTCharacteristic::ContextDestroyed() {
Dispose();
}

void BluetoothRemoteGATTCharacteristic::Dispose() {
receivers_.Clear();
}

const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::InterfaceName()
const {
return event_target_names::kBluetoothRemoteGATTCharacteristic;
Expand Down Expand Up @@ -277,7 +270,7 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(
client;
// See https://bit.ly/2S0zRAS for task types.
receivers_.Add(
this, client.InitWithNewEndpointAndPassReceiver(),
client.InitWithNewEndpointAndPassReceiver(),
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI));

service->RemoteCharacteristicStartNotifications(
Expand Down Expand Up @@ -458,6 +451,7 @@ void BluetoothRemoteGATTCharacteristic::Trace(Visitor* visitor) {
visitor->Trace(properties_);
visitor->Trace(value_);
visitor->Trace(device_);
visitor->Trace(receivers_);
EventTargetWithInlineData::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_H_

#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
Expand All @@ -15,6 +14,7 @@
#include "third_party/blink/renderer/modules/event_target_modules.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_associated_receiver_set.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {
Expand All @@ -39,7 +39,6 @@ class BluetoothRemoteGATTCharacteristic final
public ActiveScriptWrappable<BluetoothRemoteGATTCharacteristic>,
public ExecutionContextLifecycleObserver,
public mojom::blink::WebBluetoothCharacteristicClient {
USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, Dispose);
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic);

Expand All @@ -58,11 +57,7 @@ class BluetoothRemoteGATTCharacteristic final
const WTF::Vector<uint8_t>& value) override;

// ExecutionContextLifecycleObserver interface.
void ContextDestroyed() override;

// USING_PRE_FINALIZER interface.
// Called before the object gets garbage collected.
void Dispose();
void ContextDestroyed() override {}

// EventTarget methods:
const AtomicString& InterfaceName() const override;
Expand Down Expand Up @@ -134,7 +129,8 @@ class BluetoothRemoteGATTCharacteristic final
Member<BluetoothCharacteristicProperties> properties_;
Member<DOMDataView> value_;
Member<BluetoothDevice> device_;
mojo::AssociatedReceiverSet<mojom::blink::WebBluetoothCharacteristicClient>
HeapMojoAssociatedReceiverSet<mojom::blink::WebBluetoothCharacteristicClient,
BluetoothRemoteGATTCharacteristic>
receivers_;
};

Expand Down

0 comments on commit dbe5871

Please sign in to comment.