Commit 11f4508e authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Cros: Reland "Add metrics for transitions in the hotseat"

Report animation smoothness for the transition into the hotseat in the
HomeLauncher.

The original change caused use-of-uninitialized-value flaky tests. These
were caused because the HotseatTransitionAnimator could outlive the
ShelfWidget in some tests.
This is a possible fix for the issue by avoiding the destruction of
|hotseat_transition_animator_| until the Shelf Widget is destroyed, thus
destroying the animator itself. Shelf Widget destruction occurs usually
after Shutdown().

Original CL: http://crrev.com/c/1917941

Bug: 1022178, 1022177, 1028255, 1030222
Change-Id: Ibf2030df7408704e8aa96ca863bcd55ba333174f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954355Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722641}
parent a398669c
......@@ -8,6 +8,7 @@
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/metrics/histogram_macros.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
......@@ -16,8 +17,37 @@
namespace ash {
class HotseatTransitionAnimator::TransitionAnimationMetricsReporter
: public ui::AnimationMetricsReporter {
public:
TransitionAnimationMetricsReporter() = default;
~TransitionAnimationMetricsReporter() override = default;
void set_animating_to_shown_hotseat(bool animating_to_shown_hotseat) {
animating_to_shown_hotseat_ = animating_to_shown_hotseat;
}
// ui::AnimationMetricsReporter:
void Report(int value) override {
if (animating_to_shown_hotseat_) {
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatTransition.AnimationSmoothness.TransitionToShownHotseat",
value);
} else {
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatTransition.AnimationSmoothness."
"TransitionFromShownHotseat",
value);
}
}
private:
// Whether the animation reported is transitioning state into a shown hotseat.
bool animating_to_shown_hotseat_ = false;
};
HotseatTransitionAnimator::HotseatTransitionAnimator(ShelfWidget* shelf_widget)
: shelf_widget_(shelf_widget) {
: shelf_widget_(shelf_widget),
animation_metrics_reporter_(
std::make_unique<TransitionAnimationMetricsReporter>()) {
Shell::Get()->tablet_mode_controller()->AddObserver(this);
}
......@@ -90,6 +120,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state,
const int y_offset = starting_y - target_bounds.y();
transform.Translate(0, y_offset);
shelf_widget_->GetAnimatingBackground()->SetTransform(transform);
animation_metrics_reporter_->set_animating_to_shown_hotseat(
animating_to_shown_hotseat);
{
ui::ScopedLayerAnimationSettings shelf_bg_animation_setter(
......@@ -99,6 +131,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state,
shelf_bg_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
shelf_bg_animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
shelf_bg_animation_setter.SetAnimationMetricsReporter(
animation_metrics_reporter_.get());
animation_complete_callback_ = base::BindOnce(
&HotseatTransitionAnimator::NotifyHotseatTransitionAnimationEnded,
weak_ptr_factory_.GetWeakPtr(), old_state, new_state);
......
......@@ -49,6 +49,7 @@ class HotseatTransitionAnimator : public TabletModeObserver,
void OnTabletModeEnded() override;
private:
class TransitionAnimationMetricsReporter;
// Starts the animation between |old_state| and |target_state|.
void DoAnimation(HotseatState old_state, HotseatState new_state);
......@@ -71,6 +72,10 @@ class HotseatTransitionAnimator : public TabletModeObserver,
base::ObserverList<Observer> observers_;
// Metric reporter for hotseat transitions.
std::unique_ptr<TransitionAnimationMetricsReporter>
animation_metrics_reporter_;
base::WeakPtrFactory<HotseatTransitionAnimator> weak_ptr_factory_{this};
};
......
......@@ -518,7 +518,6 @@ void ShelfWidget::Initialize(aura::Window* shelf_container) {
void ShelfWidget::Shutdown() {
hotseat_transition_animator_->RemoveObserver(delegate_view_);
hotseat_transition_animator_.reset();
// Shutting down the status area widget may cause some widgets (e.g. bubbles)
// to close, so uninstall the ShelfLayoutManager event filters first. Don't
// reset the pointer until later because other widgets (e.g. app list) may
......
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