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

Side by Side Diff: chrome/browser/chromeos/login/error_screens_histogram_helper.cc

Issue 494633003: UMA: How often are different network error screens encountered during OOBE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review Created 6 years, 3 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 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 // This comes from UMA_HISTOGRAM_ENUMERATION macros. Can't use it because of
41 // non const histogram name.
42 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet(
43 histogram_name,
44 1,
45 boundary,
46 boundary + 1,
47 base::HistogramBase::kUmaTargetedHistogramFlag);
48 histogram->Add(error);
49 }
50
51 static const base::TimeDelta time_min = base::TimeDelta::FromMilliseconds(10);
ygorshenin1 2014/09/22 11:36:40 nit: TimeDelta's and int are lightweight enough, s
ygorshenin1 2014/09/22 11:36:40 nit: could you please move variable declarations b
Roman Sorokin (ftl) 2014/09/26 10:46:20 Done.
Roman Sorokin (ftl) 2014/09/26 10:46:20 Done.
52 static const base::TimeDelta time_max = base::TimeDelta::FromMinutes(3);
53 static const int time_bucket_count = 50;
54
55 void StoreTimeOnErrorScreenToHistogram(const std::string& screen_name,
56 ErrorScreen::ErrorState error,
57 const base::TimeDelta& time_delta) {
58 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN ||
59 error > ErrorScreen::ERROR_STATE_NONE)
60 return;
61 std::string histogram_name =
62 kOobeTimeSpentOnErrorScreensPrefix + screen_name + ErrorToString(error);
63
64 // This comes from UMA_HISTOGRAM_MEDIUM_TIMES macros. Can't use it because of
65 // non const histogram name.
66 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
67 histogram_name,
68 time_min,
69 time_max,
70 time_bucket_count,
71 base::HistogramBase::kUmaTargetedHistogramFlag);
72
73 histogram->AddTime(time_delta);
74 }
75
76 } // namespace
77
78 ErrorScreensHistogramHelper::ErrorScreensHistogramHelper(
79 const std::string& screen_name)
80 : screen_name_(screen_name),
81 was_shown_(false),
82 last_error_shown_(ErrorScreen::ERROR_STATE_NONE) {
83 }
84
85 void ErrorScreensHistogramHelper::OnScreenShow() {
86 was_shown_ = true;
87 }
88
89 void ErrorScreensHistogramHelper::OnErrorShow(ErrorScreen::ErrorState error) {
90 OnErrorShowTime(error, base::Time::Now());
91 }
92
93 void ErrorScreensHistogramHelper::OnErrorShowTime(ErrorScreen::ErrorState error,
94 base::Time now) {
95 last_error_shown_ = error;
96 if (error_screen_start_time.is_null())
97 error_screen_start_time = now;
98 StoreErrorScreenToHistogram(screen_name_, error);
99 }
100
101 void ErrorScreensHistogramHelper::OnErrorHide() {
102 OnErrorHideTime(base::Time::Now());
103 }
104
105 void ErrorScreensHistogramHelper::OnErrorHideTime(base::Time now) {
106 DCHECK(!error_screen_start_time.is_null());
107 time_on_error_screens += now - error_screen_start_time;
108 error_screen_start_time = base::Time();
109 }
110
111 ErrorScreensHistogramHelper::~ErrorScreensHistogramHelper() {
112 if (was_shown_) {
113 if (last_error_shown_ == ErrorScreen::ERROR_STATE_NONE) {
114 StoreErrorScreenToHistogram(screen_name_, ErrorScreen::ERROR_STATE_NONE);
115 } else {
116 if (!error_screen_start_time.is_null()) {
117 time_on_error_screens += base::Time::Now() - error_screen_start_time;
118 error_screen_start_time = base::Time();
119 }
120 StoreTimeOnErrorScreenToHistogram(
121 screen_name_, last_error_shown_, time_on_error_screens);
122 }
123 }
124 }
125
126 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698