OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 | |
9 namespace chromeos { | |
10 | |
11 namespace { | |
12 | |
13 static const char kOobeErrorScreensCounterPrefix[] = "OOBE.NetworkErrorShown."; | |
14 static const char kOobeTimeSpentOnErrorScreensPrefix[] = | |
15 "OOBE.ErrorScreensTime."; | |
16 | |
17 std::string ErrorToString(ErrorScreen::ErrorState error) { | |
18 switch (error) { | |
19 case ErrorScreen::ERROR_STATE_PORTAL: | |
20 return ".Portal"; | |
21 case ErrorScreen::ERROR_STATE_OFFLINE: | |
22 return ".Offline"; | |
23 case ErrorScreen::ERROR_STATE_PROXY: | |
24 return ".Proxy"; | |
25 case ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT: | |
26 return ".AuthExtTimeout"; | |
27 default: | |
28 NOTREACHED() << "Invalid ErrorState " << error; | |
29 return std::string(); | |
30 } | |
31 } | |
32 | |
33 void StoreErrorScreenToHistogram(const std::string& screen_name, | |
34 ErrorScreen::ErrorState error) { | |
35 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN || | |
36 error > ErrorScreen::ERROR_STATE_NONE) | |
37 return; | |
38 std::string histogram_name = kOobeErrorScreensCounterPrefix + screen_name; | |
39 int boundary = ErrorScreen::ERROR_STATE_NONE + 1; | |
40 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | |
jwd
2014/09/10 15:58:18
Can you add a comment saying this corresponds to t
Roman Sorokin (ftl)
2014/09/11 15:05:32
Done.
| |
41 histogram_name, | |
42 1, | |
43 boundary, | |
44 boundary + 1, | |
45 base::HistogramBase::kUmaTargetedHistogramFlag); | |
46 histogram->Add(error); | |
47 } | |
48 | |
49 static const base::TimeDelta time_min = base::TimeDelta::FromMilliseconds(10); | |
50 static const base::TimeDelta time_max = base::TimeDelta::FromMinutes(3); | |
51 static const int time_bucket_count = 50; | |
52 | |
53 void StoreTimeOnErrorScreenToHistogram(const std::string& screen_name, | |
54 ErrorScreen::ErrorState error, | |
55 const base::TimeDelta& time_delta) { | |
56 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN || | |
57 error > ErrorScreen::ERROR_STATE_NONE) | |
58 return; | |
59 std::string histogram_name = | |
60 kOobeTimeSpentOnErrorScreensPrefix + screen_name + ErrorToString(error); | |
61 | |
62 base::HistogramBase* histogram = base::LinearHistogram::FactoryTimeGet( | |
jwd
2014/09/10 15:58:18
Having a linear histogram seems a bit odd for reco
Roman Sorokin (ftl)
2014/09/11 15:05:33
Done.
| |
63 histogram_name, | |
64 time_min, | |
65 time_max, | |
66 time_bucket_count, | |
67 base::HistogramBase::kUmaTargetedHistogramFlag); | |
68 | |
69 histogram->AddTime(time_delta); | |
70 } | |
71 | |
72 } // namespace | |
73 | |
74 ErrorScreensHistogramHelper::ErrorScreensHistogramHelper( | |
75 const std::string& screen_name) | |
76 : screen_name_(screen_name), | |
77 was_shown_(false), | |
78 last_error_shown_(ErrorScreen::ERROR_STATE_NONE) { | |
79 } | |
80 | |
81 void ErrorScreensHistogramHelper::OnScreenShow() { | |
82 was_shown_ = true; | |
83 } | |
84 | |
85 void ErrorScreensHistogramHelper::OnErrorShow(ErrorScreen::ErrorState error) { | |
86 OnErrorShowTime(error, base::Time::Now()); | |
87 } | |
88 | |
89 void ErrorScreensHistogramHelper::OnErrorShowTime(ErrorScreen::ErrorState error, | |
90 base::Time now) { | |
91 last_error_shown_ = error; | |
92 if (error_screen_start_time.is_null()) | |
93 error_screen_start_time = now; | |
94 StoreErrorScreenToHistogram(screen_name_, error); | |
95 } | |
96 | |
97 void ErrorScreensHistogramHelper::OnErrorHide() { | |
98 OnErrorHideTime(base::Time::Now()); | |
99 } | |
100 | |
101 void ErrorScreensHistogramHelper::OnErrorHideTime(base::Time now) { | |
102 DCHECK(!error_screen_start_time.is_null()); | |
103 time_on_error_screens += now - error_screen_start_time; | |
104 error_screen_start_time = base::Time(); | |
105 } | |
106 | |
107 ErrorScreensHistogramHelper::~ErrorScreensHistogramHelper() { | |
108 if (was_shown_) { | |
109 if (last_error_shown_ == ErrorScreen::ERROR_STATE_NONE) { | |
110 StoreErrorScreenToHistogram(screen_name_, ErrorScreen::ERROR_STATE_NONE); | |
111 } else { | |
112 if (!error_screen_start_time.is_null()) { | |
113 time_on_error_screens += base::Time::Now() - error_screen_start_time; | |
114 error_screen_start_time = base::Time(); | |
115 } | |
116 StoreTimeOnErrorScreenToHistogram( | |
117 screen_name_, last_error_shown_, time_on_error_screens); | |
118 } | |
119 } | |
120 } | |
121 | |
122 } // namespace chromeos | |
OLD | NEW |