Index: ash/rotator/screen_rotation_animator.cc |
diff --git a/ash/rotator/screen_rotation_animator.cc b/ash/rotator/screen_rotation_animator.cc |
index c0dbe2058d6f7a4c33314ed1f07650cde2446195..510ea52c16fdd5ebd8bf43f89d57479de1f4b251 100644 |
--- a/ash/rotator/screen_rotation_animator.cc |
+++ b/ash/rotator/screen_rotation_animator.cc |
@@ -14,6 +14,7 @@ |
#include "ash/shell.h" |
#include "base/command_line.h" |
#include "base/memory/ptr_util.h" |
+#include "base/metrics/histogram_macros.h" |
#include "base/time/time.h" |
#include "ui/aura/window.h" |
#include "ui/compositor/layer.h" |
@@ -143,7 +144,7 @@ LayerCleanupObserver::~LayerCleanupObserver() { |
void LayerCleanupObserver::OnLayerAnimationEnded( |
ui::LayerAnimationSequence* sequence) { |
if (animator_) |
- animator_->OnLayerAnimationEnded(); |
+ animator_->ProcessAnimationQueue(); |
delete this; |
} |
@@ -151,7 +152,7 @@ void LayerCleanupObserver::OnLayerAnimationEnded( |
void LayerCleanupObserver::OnLayerAnimationAborted( |
ui::LayerAnimationSequence* sequence) { |
if (animator_) |
- animator_->OnLayerAnimationAborted(); |
+ animator_->ProcessAnimationQueue(); |
delete this; |
} |
@@ -177,13 +178,32 @@ struct ScreenRotationAnimator::ScreenRotationRequest { |
display::Display::RotationSource source; |
}; |
+class ScreenRotationAnimator::ScreenRotationAnimationMetricsReporter |
+ : public ui::AnimationMetricsReporter { |
+ void Report(int value) override { |
oshima
2017/03/24 22:46:00
nit: define public ctor/dtor, then DISALLOW_COPY_A
wutao
2017/03/24 23:50:55
Done.
|
+ UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value); |
+ } |
+}; |
+ |
ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) |
: display_id_(display_id), |
is_rotating_(false), |
+ metrics_reporter_( |
+ base::MakeUnique<ScreenRotationAnimationMetricsReporter>()), |
disable_animation_timers_for_test_(false), |
weak_factory_(this) {} |
-ScreenRotationAnimator::~ScreenRotationAnimator() {} |
+ScreenRotationAnimator::~ScreenRotationAnimator() { |
+ // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from |
+ // calling a method on the |animator_|. |
+ weak_factory_.InvalidateWeakPtrs(); |
+ |
+ // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in |
+ // order to make sure |metrics_reporter_| outlives the attached animation |
+ // sequence. |
+ old_layer_tree_owner_.reset(); |
+ metrics_reporter_.reset(); |
+} |
void ScreenRotationAnimator::AnimateRotation( |
std::unique_ptr<ScreenRotationRequest> rotation_request) { |
@@ -278,6 +298,7 @@ void ScreenRotationAnimator::AnimateRotation( |
// control the animation. |
if (disable_animation_timers_for_test_) |
animator->set_disable_timer_for_test(true); |
+ animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get()); |
animator->StartAnimation(animation_sequence.release()); |
rotation_request.reset(); |
@@ -313,15 +334,6 @@ void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( |
screen_rotation_animator_observers_.RemoveObserver(observer); |
} |
-void ScreenRotationAnimator::OnLayerAnimationEnded() { |
- ProcessAnimationQueue(); |
-} |
- |
-void ScreenRotationAnimator::OnLayerAnimationAborted() { |
- AbortAnimations(old_layer_tree_owner_->root()); |
- ProcessAnimationQueue(); |
-} |
- |
void ScreenRotationAnimator::ProcessAnimationQueue() { |
is_rotating_ = false; |
old_layer_tree_owner_.reset(); |