Commit 61668118 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. This
is a possible fix for the issue by explicitly resetting the
|animation_metrics_reporter_|

Bug: 1022178, 1022177, 1028255
Change-Id: I9abe9532e4f8b8cbc8c3700b21db48144f76f767
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1940562Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720619}
parent d661c0dd
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.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.h"
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
...@@ -16,8 +17,37 @@ ...@@ -16,8 +17,37 @@
namespace ash { namespace ash {
class HotseatTransitionAnimator::TransitionAnimationMetricsReporter
: public ui::AnimationMetricsReporter {
public:
TransitionAnimationMetricsReporter() {}
~TransitionAnimationMetricsReporter() override = default;
void 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) 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); Shell::Get()->tablet_mode_controller()->AddObserver(this);
} }
...@@ -25,6 +55,10 @@ HotseatTransitionAnimator::~HotseatTransitionAnimator() { ...@@ -25,6 +55,10 @@ HotseatTransitionAnimator::~HotseatTransitionAnimator() {
StopObservingImplicitAnimations(); StopObservingImplicitAnimations();
if (Shell::Get()->tablet_mode_controller()) if (Shell::Get()->tablet_mode_controller())
Shell::Get()->tablet_mode_controller()->RemoveObserver(this); Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
// Reset the pointer for |animation_metrics_reporter| to delete the reference
// to the TransitionAnimationMetricsReporter object that might cause a
// use-of-uninitialized-value. (See crbug.com/1028255)
animation_metrics_reporter_.reset();
} }
void HotseatTransitionAnimator::OnHotseatStateChanged(HotseatState old_state, void HotseatTransitionAnimator::OnHotseatStateChanged(HotseatState old_state,
...@@ -90,6 +124,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state, ...@@ -90,6 +124,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state,
const int y_offset = starting_y - target_bounds.y(); const int y_offset = starting_y - target_bounds.y();
transform.Translate(0, y_offset); transform.Translate(0, y_offset);
shelf_widget_->GetAnimatingBackground()->SetTransform(transform); shelf_widget_->GetAnimatingBackground()->SetTransform(transform);
animation_metrics_reporter_->animating_to_shown_hotseat(
animating_to_shown_hotseat);
{ {
ui::ScopedLayerAnimationSettings shelf_bg_animation_setter( ui::ScopedLayerAnimationSettings shelf_bg_animation_setter(
...@@ -99,6 +135,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state, ...@@ -99,6 +135,8 @@ void HotseatTransitionAnimator::DoAnimation(HotseatState old_state,
shelf_bg_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); shelf_bg_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
shelf_bg_animation_setter.SetPreemptionStrategy( shelf_bg_animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
shelf_bg_animation_setter.SetAnimationMetricsReporter(
animation_metrics_reporter_.get());
animation_complete_callback_ = base::BindOnce( animation_complete_callback_ = base::BindOnce(
&HotseatTransitionAnimator::NotifyHotseatTransitionAnimationEnded, &HotseatTransitionAnimator::NotifyHotseatTransitionAnimationEnded,
weak_ptr_factory_.GetWeakPtr(), old_state, new_state); weak_ptr_factory_.GetWeakPtr(), old_state, new_state);
......
...@@ -49,6 +49,8 @@ class HotseatTransitionAnimator : public TabletModeObserver, ...@@ -49,6 +49,8 @@ class HotseatTransitionAnimator : public TabletModeObserver,
void OnTabletModeEnded() override; void OnTabletModeEnded() override;
private: private:
class TransitionAnimationMetricsReporter;
// Starts the animation between |old_state| and |target_state|. // Starts the animation between |old_state| and |target_state|.
void DoAnimation(HotseatState old_state, HotseatState new_state); void DoAnimation(HotseatState old_state, HotseatState new_state);
...@@ -71,6 +73,10 @@ class HotseatTransitionAnimator : public TabletModeObserver, ...@@ -71,6 +73,10 @@ class HotseatTransitionAnimator : public TabletModeObserver,
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
// Metric reporter for hotseat transitions.
std::unique_ptr<TransitionAnimationMetricsReporter>
animation_metrics_reporter_;
base::WeakPtrFactory<HotseatTransitionAnimator> weak_ptr_factory_{this}; base::WeakPtrFactory<HotseatTransitionAnimator> weak_ptr_factory_{this};
}; };
......
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