Commit 56b7145e authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

capture_mode: fix crash happens when cancel recording during countdown.

Bug: 1144767
Change-Id: I8e4b613fbed55cc7336a0bf4ac144d7dd4834dae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521572
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825446}
parent c1fa385e
......@@ -335,6 +335,11 @@ void CaptureLabelView::ScheduleCountDownAnimation() {
bool CaptureLabelView::OnCountDownAnimationCompleted(
const ui::CallbackLayerAnimationObserver& observer) {
// If animation was aborted, return directly to avoid crash as |this| may
// no longer be valid.
if (observer.aborted_count())
return false;
if (timeout_count_down_ == kCountDownEndSeconds) {
std::move(countdown_finished_callback_).Run(); // |this| is destroyed here.
} else {
......
......@@ -19,7 +19,6 @@
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/widget/unique_widget_ptr.h"
#include "ui/views/widget/widget.h"
namespace gfx {
......@@ -199,7 +198,7 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
CaptureModeBarView* capture_mode_bar_view_ = nullptr;
// Widget which displays capture region size during a region capture session.
views::UniqueWidgetPtr dimensions_label_widget_;
std::unique_ptr<views::Widget> dimensions_label_widget_;
// Widget that shows an optional icon and a message in the middle of the
// screen or in the middle of the capture region and prompts the user what to
......@@ -207,7 +206,7 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// and source and can be empty in some cases. And in video capture mode, when
// starting capturing, the widget will transform into a 3-second countdown
// timer.
views::UniqueWidgetPtr capture_label_widget_;
std::unique_ptr<views::Widget> capture_label_widget_;
// Magnifier glass used during a region capture session.
MagnifierGlass magnifier_glass_;
......
......@@ -25,6 +25,7 @@
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
......@@ -1278,4 +1279,21 @@ TEST_F(CaptureModeTest, CaptureModeBarButtonTypeHistograms) {
CaptureModeBarButtonType::kWindow, 1);
}
// Test that cancel recording during countdown won't cause crash.
TEST_F(CaptureModeTest, CancelCaptureDuringCountDown) {
ui::ScopedAnimationDurationScaleMode animatin_scale(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
StartCaptureSession(CaptureModeSource::kFullscreen, CaptureModeType::kVideo);
// Hit Enter to begin recording, Wait for 1 second, then press ESC while count
// down is in progress.
auto* event_generator = GetEventGenerator();
SendKey(ui::VKEY_RETURN, event_generator);
base::RunLoop loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::BindLambdaForTesting([&]() { loop.Quit(); }),
base::TimeDelta::FromSeconds(1));
loop.Run();
SendKey(ui::VKEY_ESCAPE, event_generator);
}
} // namespace ash
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