Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use WeakPtr to detect deletion to avoid crash on application menu #19561

Merged
merged 1 commit into from Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion patches/common/chromium/.patches
Expand Up @@ -78,4 +78,5 @@ video_capturer_dirty_rect.patch
unsandboxed_ppapi_processes_skip_zygote.patch
autofill_size_calculation.patch
disable_detach_webview_frame.patch
chore_add_debounce_on_the_updatewebcontentsvisibility_method_to.patch
chore_add_debounce_on_the_updatewebcontentsvisibility_method_to.patch
fix_use_weakptr_to_detect_deletion.patch
@@ -0,0 +1,76 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: John Kleinschmidt <kleinschmidtorama@gmail.com>
Date: Wed, 31 Jul 2019 14:36:27 -0400
Subject: fix: use WeakPtr to detect deletion


diff --git a/ui/compositor/callback_layer_animation_observer.cc b/ui/compositor/callback_layer_animation_observer.cc
index 639caf4d1411b867a31ce29e6c6ec4ae846359a8..6296afa55e38494cf0232f8bcd05811bfd4ebe38 100644
--- a/ui/compositor/callback_layer_animation_observer.cc
+++ b/ui/compositor/callback_layer_animation_observer.cc
@@ -38,22 +38,18 @@ CallbackLayerAnimationObserver::CallbackLayerAnimationObserver(
&CallbackLayerAnimationObserver::DummyAnimationStartedCallback)),
animation_ended_callback_(animation_ended_callback) {}

-CallbackLayerAnimationObserver::~CallbackLayerAnimationObserver() {
- if (destroyed_)
- *destroyed_ = true;
-}
+CallbackLayerAnimationObserver::~CallbackLayerAnimationObserver() {}

void CallbackLayerAnimationObserver::SetActive() {
active_ = true;

- bool destroyed = false;
- destroyed_ = &destroyed;
+ base::WeakPtr<CallbackLayerAnimationObserver> weak_this =
+ weak_factory_.GetWeakPtr();

CheckAllSequencesStarted();

- if (destroyed)
+ if (!weak_this)
return;
- destroyed_ = nullptr;

CheckAllSequencesCompleted();
}
@@ -110,19 +106,17 @@ void CallbackLayerAnimationObserver::CheckAllSequencesStarted() {
void CallbackLayerAnimationObserver::CheckAllSequencesCompleted() {
if (active_ && GetNumSequencesCompleted() == attached_sequence_count_) {
active_ = false;
- bool destroyed = false;
- destroyed_ = &destroyed;
-
+ base::WeakPtr<CallbackLayerAnimationObserver> weak_this =
+ weak_factory_.GetWeakPtr();
bool should_delete = animation_ended_callback_.Run(*this);

- if (destroyed) {
+ if (!weak_this) {
if (should_delete)
LOG(WARNING) << "CallbackLayerAnimationObserver was explicitly "
"destroyed AND was requested to be destroyed via the "
"AnimationEndedCallback's return value.";
return;
}
- destroyed_ = nullptr;

if (should_delete)
delete this;
diff --git a/ui/compositor/callback_layer_animation_observer.h b/ui/compositor/callback_layer_animation_observer.h
index fc631cc21ccc83a74955cd1af8bf43b879b6bc80..9b3448eecbc6a9bc75719c8df08586fe8870fa96 100644
--- a/ui/compositor/callback_layer_animation_observer.h
+++ b/ui/compositor/callback_layer_animation_observer.h
@@ -167,9 +167,8 @@ class COMPOSITOR_EXPORT CallbackLayerAnimationObserver
// The callback to invoke once all the animation sequences have finished.
AnimationEndedCallback animation_ended_callback_;

- // Set to true in the destructor (if non-NULL). Used to detect deletion while
- // calling out.
- bool* destroyed_ = nullptr;
+ // Used to detect deletion while calling out.
+ base::WeakPtrFactory<CallbackLayerAnimationObserver> weak_factory_{this};

DISALLOW_COPY_AND_ASSIGN(CallbackLayerAnimationObserver);
};