Commit 913247c3 authored by Hongchan Choi's avatar Hongchan Choi Committed by Commit Bot

Use SupportsWeakPtr for messaging from rendering thread to main thread

In cross-thread messaging, the associated execution context can be
already gone when a posted task is performed sometime later in the task
runner's queue.

By using WeakPtr, the task runner will not perform a scheduled task
in the queue when the target object is invalid.

Test: Locally confirmed that the repro does not crash.
Bug: 1057627
Change-Id: I51737594c918f6a4924c9a7ffe30db3e8de9a683
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082897
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746613}
parent 00e5ef77
......@@ -250,7 +250,7 @@ void AudioScheduledSourceHandler::Finish() {
PostCrossThreadTask(
*task_runner_, FROM_HERE,
CrossThreadBindOnce(&AudioScheduledSourceHandler::NotifyEnded,
WrapRefCounted(this)));
AsWeakPtr()));
}
void AudioScheduledSourceHandler::NotifyEnded() {
......
......@@ -30,6 +30,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_SCHEDULED_SOURCE_NODE_H_
#include <atomic>
#include "base/memory/weak_ptr.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/modules/webaudio/audio_node.h"
......@@ -38,7 +39,9 @@ namespace blink {
class BaseAudioContext;
class AudioBus;
class AudioScheduledSourceHandler : public AudioHandler {
class AudioScheduledSourceHandler
: public AudioHandler,
public base::SupportsWeakPtr<AudioScheduledSourceHandler> {
public:
// These are the possible states an AudioScheduledSourceNode can be in:
//
......
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