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

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

Issue 872633008: Migrate (Network)ErrorScreen to ScreenContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/chromeos/login/error_screens_histogram_helper.h" 5 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 8
9 namespace chromeos { 9 namespace chromeos {
10 10
11 namespace { 11 namespace {
12 12
13 static const char kOobeErrorScreensCounterPrefix[] = "OOBE.NetworkErrorShown."; 13 static const char kOobeErrorScreensCounterPrefix[] = "OOBE.NetworkErrorShown.";
14 static const char kOobeTimeSpentOnErrorScreensPrefix[] = 14 static const char kOobeTimeSpentOnErrorScreensPrefix[] =
15 "OOBE.ErrorScreensTime."; 15 "OOBE.ErrorScreensTime.";
16 16
17 const base::TimeDelta time_min = base::TimeDelta::FromMilliseconds(10); 17 const base::TimeDelta time_min = base::TimeDelta::FromMilliseconds(10);
18 const base::TimeDelta time_max = base::TimeDelta::FromMinutes(3); 18 const base::TimeDelta time_max = base::TimeDelta::FromMinutes(3);
19 const int time_bucket_count = 50; 19 const int time_bucket_count = 50;
20 20
21 std::string ErrorToString(ErrorScreen::ErrorState error) { 21 std::string ErrorToString(NetworkError::ErrorState error) {
22 switch (error) { 22 switch (error) {
23 case ErrorScreen::ERROR_STATE_PORTAL: 23 case NetworkError::ERROR_STATE_PORTAL:
24 return ".Portal"; 24 return ".Portal";
25 case ErrorScreen::ERROR_STATE_OFFLINE: 25 case NetworkError::ERROR_STATE_OFFLINE:
26 return ".Offline"; 26 return ".Offline";
27 case ErrorScreen::ERROR_STATE_PROXY: 27 case NetworkError::ERROR_STATE_PROXY:
28 return ".Proxy"; 28 return ".Proxy";
29 case ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT: 29 case NetworkError::ERROR_STATE_AUTH_EXT_TIMEOUT:
30 return ".AuthExtTimeout"; 30 return ".AuthExtTimeout";
31 default: 31 default:
32 NOTREACHED() << "Invalid ErrorState " << error; 32 NOTREACHED() << "Invalid ErrorState " << error;
33 return std::string(); 33 return std::string();
34 } 34 }
35 } 35 }
36 36
37 void StoreErrorScreenToHistogram(const std::string& screen_name, 37 void StoreErrorScreenToHistogram(const std::string& screen_name,
38 ErrorScreen::ErrorState error) { 38 NetworkError::ErrorState error) {
39 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN || 39 if (error <= NetworkError::ERROR_STATE_UNKNOWN ||
40 error > ErrorScreen::ERROR_STATE_NONE) 40 error > NetworkError::ERROR_STATE_NONE)
41 return; 41 return;
42 std::string histogram_name = kOobeErrorScreensCounterPrefix + screen_name; 42 std::string histogram_name = kOobeErrorScreensCounterPrefix + screen_name;
43 int boundary = ErrorScreen::ERROR_STATE_NONE + 1; 43 int boundary = NetworkError::ERROR_STATE_NONE + 1;
44 // This comes from UMA_HISTOGRAM_ENUMERATION macros. Can't use it because of 44 // This comes from UMA_HISTOGRAM_ENUMERATION macros. Can't use it because of
45 // non const histogram name. 45 // non const histogram name.
46 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( 46 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet(
47 histogram_name, 47 histogram_name,
48 1, 48 1,
49 boundary, 49 boundary,
50 boundary + 1, 50 boundary + 1,
51 base::HistogramBase::kUmaTargetedHistogramFlag); 51 base::HistogramBase::kUmaTargetedHistogramFlag);
52 histogram->Add(error); 52 histogram->Add(error);
53 } 53 }
54 54
55 void StoreTimeOnErrorScreenToHistogram(const std::string& screen_name, 55 void StoreTimeOnErrorScreenToHistogram(const std::string& screen_name,
56 ErrorScreen::ErrorState error, 56 NetworkError::ErrorState error,
57 const base::TimeDelta& time_delta) { 57 const base::TimeDelta& time_delta) {
58 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN || 58 if (error <= NetworkError::ERROR_STATE_UNKNOWN ||
59 error > ErrorScreen::ERROR_STATE_NONE) 59 error > NetworkError::ERROR_STATE_NONE)
60 return; 60 return;
61 std::string histogram_name = 61 std::string histogram_name =
62 kOobeTimeSpentOnErrorScreensPrefix + screen_name + ErrorToString(error); 62 kOobeTimeSpentOnErrorScreensPrefix + screen_name + ErrorToString(error);
63 63
64 // This comes from UMA_HISTOGRAM_MEDIUM_TIMES macros. Can't use it because of 64 // This comes from UMA_HISTOGRAM_MEDIUM_TIMES macros. Can't use it because of
65 // non const histogram name. 65 // non const histogram name.
66 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( 66 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
67 histogram_name, 67 histogram_name,
68 time_min, 68 time_min,
69 time_max, 69 time_max,
70 time_bucket_count, 70 time_bucket_count,
71 base::HistogramBase::kUmaTargetedHistogramFlag); 71 base::HistogramBase::kUmaTargetedHistogramFlag);
72 72
73 histogram->AddTime(time_delta); 73 histogram->AddTime(time_delta);
74 } 74 }
75 75
76 } // namespace 76 } // namespace
77 77
78 ErrorScreensHistogramHelper::ErrorScreensHistogramHelper( 78 ErrorScreensHistogramHelper::ErrorScreensHistogramHelper(
79 const std::string& screen_name) 79 const std::string& screen_name)
80 : screen_name_(screen_name), 80 : screen_name_(screen_name),
81 was_shown_(false), 81 was_shown_(false),
82 last_error_shown_(ErrorScreen::ERROR_STATE_NONE) { 82 last_error_shown_(NetworkError::ERROR_STATE_NONE) {
83 } 83 }
84 84
85 void ErrorScreensHistogramHelper::OnScreenShow() { 85 void ErrorScreensHistogramHelper::OnScreenShow() {
86 was_shown_ = true; 86 was_shown_ = true;
87 } 87 }
88 88
89 void ErrorScreensHistogramHelper::OnErrorShow(ErrorScreen::ErrorState error) { 89 void ErrorScreensHistogramHelper::OnErrorShow(NetworkError::ErrorState error) {
90 OnErrorShowTime(error, base::Time::Now()); 90 OnErrorShowTime(error, base::Time::Now());
91 } 91 }
92 92
93 void ErrorScreensHistogramHelper::OnErrorShowTime(ErrorScreen::ErrorState error, 93 void ErrorScreensHistogramHelper::OnErrorShowTime(
94 base::Time now) { 94 NetworkError::ErrorState error,
95 base::Time now) {
95 last_error_shown_ = error; 96 last_error_shown_ = error;
96 if (error_screen_start_time_.is_null()) 97 if (error_screen_start_time_.is_null())
97 error_screen_start_time_ = now; 98 error_screen_start_time_ = now;
98 StoreErrorScreenToHistogram(screen_name_, error); 99 StoreErrorScreenToHistogram(screen_name_, error);
99 } 100 }
100 101
101 void ErrorScreensHistogramHelper::OnErrorHide() { 102 void ErrorScreensHistogramHelper::OnErrorHide() {
102 OnErrorHideTime(base::Time::Now()); 103 OnErrorHideTime(base::Time::Now());
103 } 104 }
104 105
105 void ErrorScreensHistogramHelper::OnErrorHideTime(base::Time now) { 106 void ErrorScreensHistogramHelper::OnErrorHideTime(base::Time now) {
106 if (error_screen_start_time_.is_null()) 107 if (error_screen_start_time_.is_null())
107 return; 108 return;
108 time_on_error_screens_ += now - error_screen_start_time_; 109 time_on_error_screens_ += now - error_screen_start_time_;
109 error_screen_start_time_ = base::Time(); 110 error_screen_start_time_ = base::Time();
110 } 111 }
111 112
112 ErrorScreensHistogramHelper::~ErrorScreensHistogramHelper() { 113 ErrorScreensHistogramHelper::~ErrorScreensHistogramHelper() {
113 if (was_shown_) { 114 if (was_shown_) {
114 if (last_error_shown_ == ErrorScreen::ERROR_STATE_NONE) { 115 if (last_error_shown_ == NetworkError::ERROR_STATE_NONE) {
115 StoreErrorScreenToHistogram(screen_name_, ErrorScreen::ERROR_STATE_NONE); 116 StoreErrorScreenToHistogram(screen_name_, NetworkError::ERROR_STATE_NONE);
116 } else { 117 } else {
117 if (!error_screen_start_time_.is_null()) { 118 if (!error_screen_start_time_.is_null()) {
118 time_on_error_screens_ += base::Time::Now() - error_screen_start_time_; 119 time_on_error_screens_ += base::Time::Now() - error_screen_start_time_;
119 error_screen_start_time_ = base::Time(); 120 error_screen_start_time_ = base::Time();
120 } 121 }
121 StoreTimeOnErrorScreenToHistogram( 122 StoreTimeOnErrorScreenToHistogram(
122 screen_name_, last_error_shown_, time_on_error_screens_); 123 screen_name_, last_error_shown_, time_on_error_screens_);
123 } 124 }
124 } 125 }
125 } 126 }
126 127
127 } // namespace chromeos 128 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698