/
cherry-pick-913247c378d5.patch
61 lines (53 loc) · 2.74 KB
/
cherry-pick-913247c378d5.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From 913247c378d54e0378ffd09524e0aa7503035fc4 Mon Sep 17 00:00:00 2001
From: Hongchan Choi <hongchan@chromium.org>
Date: Wed, 4 Mar 2020 00:45:41 +0000
Subject: [PATCH] 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: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746613}
---
.../renderer/modules/webaudio/audio_scheduled_source_node.cc | 2 +-
.../renderer/modules/webaudio/audio_scheduled_source_node.h | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.cc b/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.cc
index 9594f5fe1c278..8e9c4c60163e0 100644
--- a/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.cc
+++ b/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.cc
@@ -250,7 +250,7 @@ void AudioScheduledSourceHandler::Finish() {
PostCrossThreadTask(
*task_runner_, FROM_HERE,
CrossThreadBindOnce(&AudioScheduledSourceHandler::NotifyEnded,
- WrapRefCounted(this)));
+ AsWeakPtr()));
}
void AudioScheduledSourceHandler::NotifyEnded() {
diff --git a/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.h b/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.h
index 2bf257ceabb3e..3cd126a3333d7 100644
--- a/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.h
+++ b/third_party/blink/renderer/modules/webaudio/audio_scheduled_source_node.h
@@ -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:
//