Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/scheduler/renderer/user_model.h" | 5 #include "components/scheduler/renderer/user_model.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/metrics/user_metrics.h" | |
| 9 #include "base/single_thread_task_runner.h" | |
| 8 | 10 |
| 9 namespace scheduler { | 11 namespace scheduler { |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 // This enum is used to back a histogram, and should therefore be treated as | 14 // This enum is used to back a histogram, and should therefore be treated as |
| 13 // append-only. | 15 // append-only. |
| 14 enum GesturePredictionResult { | 16 enum GesturePredictionResult { |
| 15 GESTURE_OCCURED_WAS_PREDICTED = 0, | 17 GESTURE_OCCURED_WAS_PREDICTED = 0, |
| 16 GESTURE_OCCURED_BUT_NOT_PREDICTED = 1, | 18 GESTURE_OCCURED_BUT_NOT_PREDICTED = 1, |
| 17 GESTURE_PREDICTED_BUT_DID_NOT_OCCUR = 2, | 19 GESTURE_PREDICTED_BUT_DID_NOT_OCCUR = 2, |
| 18 GESTURE_PREDICTION_RESULT_COUNT = 3 | 20 GESTURE_PREDICTION_RESULT_COUNT = 3 |
| 19 }; | 21 }; |
| 20 | 22 |
| 21 void RecordGesturePrediction(GesturePredictionResult result) { | 23 void RecordGesturePrediction(GesturePredictionResult result) { |
| 22 UMA_HISTOGRAM_ENUMERATION( | 24 UMA_HISTOGRAM_ENUMERATION( |
| 23 "RendererScheduler.UserModel.GesturePredictedCorrectly", result, | 25 "RendererScheduler.UserModel.GesturePredictedCorrectly", result, |
| 24 GESTURE_PREDICTION_RESULT_COUNT); | 26 GESTURE_PREDICTION_RESULT_COUNT); |
| 25 } | 27 } |
| 26 | 28 |
| 27 } // namespace | 29 } // namespace |
| 28 | 30 |
| 29 UserModel::UserModel() | 31 namespace features { |
| 30 : pending_input_event_count_(0), | 32 |
| 33 // Enables the recording of gesture as UMA user actions. | |
|
Ilya Sherman
2016/03/21 08:09:43
nit: s/gesture/gestures
beaudoin
2016/03/23 02:46:41
Done.
| |
| 34 // That feature is disabled by default and controlled from the server so as not | |
| 35 // to generate too many UMA user actions. | |
| 36 const base::Feature kRecordGestureAction {"RecordGestureActions", | |
| 37 base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 38 | |
| 39 } // namespace features | |
| 40 | |
| 41 UserModel::UserModel( | |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& default_task_runner) | |
| 43 : default_task_runner_(default_task_runner), | |
| 44 pending_input_event_count_(0), | |
| 31 is_gesture_active_(false), | 45 is_gesture_active_(false), |
| 32 is_gesture_expected_(false) {} | 46 is_gesture_expected_(false), |
| 47 record_gesture_action_( | |
|
Ilya Sherman
2016/03/21 08:09:43
Hmm, why do you need to cache this state? base::F
alex clarke (OOO till 29th)
2016/03/21 09:27:26
Because I asked him to:) The UserModel gets evalu
beaudoin
2016/03/23 02:46:41
Suggest leaving it like that for now. I've added a
Ilya Sherman
2016/03/24 05:02:35
the base::FeatureList::IsEnabled() call is basical
| |
| 48 base::FeatureList::IsEnabled(features::kRecordGestureAction)) {} | |
| 33 UserModel::~UserModel() {} | 49 UserModel::~UserModel() {} |
| 34 | 50 |
| 35 void UserModel::DidStartProcessingInputEvent(blink::WebInputEvent::Type type, | 51 void UserModel::DidStartProcessingInputEvent(blink::WebInputEvent::Type type, |
| 36 const base::TimeTicks now) { | 52 const base::TimeTicks now) { |
| 37 last_input_signal_time_ = now; | 53 last_input_signal_time_ = now; |
| 38 if (type == blink::WebInputEvent::TouchStart || | 54 if (type == blink::WebInputEvent::TouchStart || |
| 39 type == blink::WebInputEvent::GestureScrollBegin || | 55 type == blink::WebInputEvent::GestureScrollBegin || |
| 40 type == blink::WebInputEvent::GesturePinchBegin) { | 56 type == blink::WebInputEvent::GesturePinchBegin) { |
| 41 // Only update stats once per gesture. | 57 // Only update stats once per gesture. |
| 42 if (!is_gesture_active_) { | 58 if (!is_gesture_active_) { |
| 43 last_gesture_start_time_ = now; | 59 last_gesture_start_time_ = now; |
| 44 | 60 |
| 61 if (record_gesture_action_) { | |
| 62 default_task_runner_->PostTask( | |
| 63 FROM_HERE, | |
| 64 base::Bind(&base::RecordAction, | |
| 65 base::UserMetricsAction( | |
| 66 "RendererScheduler.UserModel.GestureStart"))); | |
| 67 } | |
| 68 | |
| 45 RecordGesturePrediction(is_gesture_expected_ | 69 RecordGesturePrediction(is_gesture_expected_ |
| 46 ? GESTURE_OCCURED_WAS_PREDICTED | 70 ? GESTURE_OCCURED_WAS_PREDICTED |
| 47 : GESTURE_OCCURED_BUT_NOT_PREDICTED); | 71 : GESTURE_OCCURED_BUT_NOT_PREDICTED); |
| 48 | 72 |
| 49 if (!last_reset_time_.is_null()) { | 73 if (!last_reset_time_.is_null()) { |
| 50 base::TimeDelta time_since_reset = now - last_reset_time_; | 74 base::TimeDelta time_since_reset = now - last_reset_time_; |
| 51 UMA_HISTOGRAM_MEDIUM_TIMES( | 75 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 52 "RendererScheduler.UserModel.GestureStartTimeSinceModelReset", | 76 "RendererScheduler.UserModel.GestureStartTimeSinceModelReset", |
| 53 time_since_reset); | 77 time_since_reset); |
| 54 } | 78 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 84 // metric that tracks its duration. | 108 // metric that tracks its duration. |
| 85 if (type == blink::WebInputEvent::GestureScrollEnd || | 109 if (type == blink::WebInputEvent::GestureScrollEnd || |
| 86 type == blink::WebInputEvent::GesturePinchEnd || | 110 type == blink::WebInputEvent::GesturePinchEnd || |
| 87 type == blink::WebInputEvent::GestureFlingStart || | 111 type == blink::WebInputEvent::GestureFlingStart || |
| 88 type == blink::WebInputEvent::TouchEnd) { | 112 type == blink::WebInputEvent::TouchEnd) { |
| 89 // Only update stats once per gesture. | 113 // Only update stats once per gesture. |
| 90 if (is_gesture_active_) { | 114 if (is_gesture_active_) { |
| 91 base::TimeDelta duration = now - last_gesture_start_time_; | 115 base::TimeDelta duration = now - last_gesture_start_time_; |
| 92 UMA_HISTOGRAM_TIMES("RendererScheduler.UserModel.GestureDuration", | 116 UMA_HISTOGRAM_TIMES("RendererScheduler.UserModel.GestureDuration", |
| 93 duration); | 117 duration); |
| 118 if (record_gesture_action_) { | |
| 119 default_task_runner_->PostTask( | |
| 120 FROM_HERE, | |
| 121 base::Bind(&base::RecordAction, | |
| 122 base::UserMetricsAction( | |
| 123 "RendererScheduler.UserModel.GestureEnd"))); | |
| 124 } | |
| 94 } | 125 } |
| 95 is_gesture_active_ = false; | 126 is_gesture_active_ = false; |
| 96 } | 127 } |
| 97 | 128 |
| 98 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 129 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 99 "is_gesture_active", is_gesture_active_); | 130 "is_gesture_active", is_gesture_active_); |
| 100 | 131 |
| 101 pending_input_event_count_++; | 132 pending_input_event_count_++; |
| 102 } | 133 } |
| 103 | 134 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 (last_gesture_expected_start_time_ - base::TimeTicks()) | 244 (last_gesture_expected_start_time_ - base::TimeTicks()) |
| 214 .InMillisecondsF()); | 245 .InMillisecondsF()); |
| 215 state->SetDouble("last_reset_time", | 246 state->SetDouble("last_reset_time", |
| 216 (last_reset_time_ - base::TimeTicks()).InMillisecondsF()); | 247 (last_reset_time_ - base::TimeTicks()).InMillisecondsF()); |
| 217 state->SetBoolean("is_gesture_expected", is_gesture_expected_); | 248 state->SetBoolean("is_gesture_expected", is_gesture_expected_); |
| 218 state->SetBoolean("is_gesture_active", is_gesture_active_); | 249 state->SetBoolean("is_gesture_active", is_gesture_active_); |
| 219 state->EndDictionary(); | 250 state->EndDictionary(); |
| 220 } | 251 } |
| 221 | 252 |
| 222 } // namespace scheduler | 253 } // namespace scheduler |
| OLD | NEW |