| 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 const base::TimeDelta time_min = base::TimeDelta::FromMilliseconds(10); | |
| 18 const base::TimeDelta time_max = base::TimeDelta::FromMinutes(3); | |
| 19 const int time_bucket_count = 50; | |
| 20 | |
| 21 std::string ErrorToString(ErrorScreen::ErrorState error) { | |
| 22 switch (error) { | |
| 23 case ErrorScreen::ERROR_STATE_PORTAL: | |
| 24 return ".Portal"; | |
| 25 case ErrorScreen::ERROR_STATE_OFFLINE: | |
| 26 return ".Offline"; | |
| 27 case ErrorScreen::ERROR_STATE_PROXY: | |
| 28 return ".Proxy"; | |
| 29 case ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT: | |
| 30 return ".AuthExtTimeout"; | |
| 31 default: | |
| 32 NOTREACHED() << "Invalid ErrorState " << error; | |
| 33 return std::string(); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void StoreErrorScreenToHistogram(const std::string& screen_name, | |
| 38 ErrorScreen::ErrorState error) { | |
| 39 if (error <= ErrorScreen::ERROR_STATE_UNKNOWN || | |
| 40 error > ErrorScreen::ERROR_STATE_NONE) | |
| 41 return; | |
| 42 std::string histogram_name = kOobeErrorScreensCounterPrefix + screen_name; | |
| 43 int boundary = ErrorScreen::ERROR_STATE_NONE + 1; | |
| 44 // This comes from UMA_HISTOGRAM_ENUMERATION macros. Can't use it because of | |
| 45 // non const histogram name. | |
| 46 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | |
| 47 histogram_name, | |
| 48 1, | |
| 49 boundary, | |
| 50 boundary + 1, | |
| 51 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 52 histogram->Add(error); | |
| 53 } | |
| 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 | |
| OLD | NEW |