Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: ui/events/fraction_of_time_without_user_input_recorder.cc

Issue 2751403002: Record the fraction of the time without user input - Aura only (Closed)
Patch Set: Update test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/fraction_of_time_without_user_input_recorder.h"
6
7 #include <algorithm>
8
9 #include "base/metrics/histogram_macros.h"
10
11 namespace {
12
13 const base::TimeDelta DEFAULT_WINDOW_SIZE = base::TimeDelta::FromSecondsD(10);
14 const base::TimeDelta DEFAULT_IDLE_TIMEOUT =
sadrul 2017/03/19 00:38:51 constexpr
tdresser 2017/03/24 14:56:30 From https://chromium-cpp.appspot.com/ "Prefer to
sadrul 2017/03/24 17:29:33 I read that as 'Prefer constexpr to const'. Withou
tdresser 2017/03/27 18:59:26 Whoops, yeah, I repeatedly misread that. Thanks.
15 base::TimeDelta::FromSecondsD(0.05);
16
17 } // namespace
18
19 namespace ui {
20
21 FractionOfTimeWithoutUserInputRecorder::FractionOfTimeWithoutUserInputRecorder()
22 : window_size_(DEFAULT_WINDOW_SIZE), idle_timeout_(DEFAULT_IDLE_TIMEOUT) {}
23
24 void FractionOfTimeWithoutUserInputRecorder::RecordEventAtTime(
25 base::TimeTicks start_time) {
26 base::TimeTicks event_end_time = start_time + idle_timeout_;
27
28 if (active_duration_start_time_.is_null())
29 active_duration_start_time_ = start_time;
30 if (previous_event_end_time_.is_null())
31 previous_event_end_time_ = start_time;
32
33 // The user is no longer interacting with the page. Report the previous active
34 // duration.
sadrul 2017/03/19 00:38:51 s/with the page/<something more generic, like inte
tdresser 2017/03/24 14:56:30 Went with "browser".
35 if (previous_event_end_time_ < start_time) {
36 RecordActiveInterval(active_duration_start_time_, previous_event_end_time_);
37 active_duration_start_time_ = start_time;
38 }
39
40 previous_event_end_time_ = event_end_time;
41 }
42
43 void FractionOfTimeWithoutUserInputRecorder::RecordActiveInterval(
44 base::TimeTicks start_time,
45 base::TimeTicks end_time) {
46 if (window_start_time_.is_null())
47 window_start_time_ = start_time;
48
49 base::TimeTicks window_end_time;
50
51 while (true) {
52 window_end_time = window_start_time_ + window_size_;
53 base::TimeDelta interval_in_window_duration =
54 std::min(end_time, window_end_time) -
55 std::max(start_time, window_start_time_);
56 interval_in_window_duration =
57 std::max(interval_in_window_duration, base::TimeDelta());
sadrul 2017/03/19 00:38:51 Is this needed? (i.e. can interval_in_window_durat
tdresser 2017/03/24 14:56:30 We're computing how much of the task is inside the
58
59 current_window_active_time_ += interval_in_window_duration;
60
61 // If we haven't exceeded the window bounds, we're done.
62 if (end_time < window_end_time)
63 break;
64
65 RecordToUma(current_window_active_time_.InMillisecondsF() /
66 window_size_.InMillisecondsF());
67
68 current_window_active_time_ = base::TimeDelta();
69 window_start_time_ = window_end_time;
70 }
71 }
72
73 void FractionOfTimeWithoutUserInputRecorder::RecordToUma(
74 float fraction_active) {
75 UMA_HISTOGRAM_PERCENTAGE("Event.FractionOfTimeWithoutUserInput",
76 (1 - fraction_active) * 100);
77 }
78
79 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698