Chromium Code Reviews| Index: chrome/browser/chromeos/login/error_screens_histogram_helper.cc |
| diff --git a/chrome/browser/chromeos/login/error_screens_histogram_helper.cc b/chrome/browser/chromeos/login/error_screens_histogram_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e74337fe4fcb21306fdec669d27659e74ae73118 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/error_screens_histogram_helper.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" |
| + |
| +#include "base/metrics/histogram.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +static const char kOobeErrorScreensCounterPrefix[] = "OOBE.NetworkErrorShown."; |
| +static const char kOobeTimeSpentOnErrorScreensPrefix[] = |
| + "OOBE.ErrorScreensTime."; |
| + |
| +std::string ErrorToString(ErrorScreen::ErrorState error) { |
| + switch (error) { |
| + case ErrorScreen::ERROR_STATE_PORTAL: |
| + return ".Portal"; |
| + case ErrorScreen::ERROR_STATE_OFFLINE: |
| + return ".Offline"; |
| + case ErrorScreen::ERROR_STATE_PROXY: |
| + return ".Proxy"; |
| + case ErrorScreen::ERROR_STATE_AUTH_EXT_TIMEOUT: |
| + return ".AuthExtTimeout"; |
| + default: |
| + NOTREACHED() << "Invalid ErrorState " << error; |
| + return ""; |
|
ygorshenin1
2014/08/26 14:33:13
nit: replace "" by std::string().
Roman Sorokin (ftl)
2014/09/04 13:26:47
Done.
|
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +ErrorScreensHistogramHelper::ErrorScreensHistogramHelper( |
| + const char* screen_name) |
| + : screen_name_(screen_name), |
| + was_shown_(false), |
| + last_error_shown_(ErrorScreen::ERROR_STATE_NONE) { |
| +} |
| + |
| +void ErrorScreensHistogramHelper::OnScreenShow() { |
| + was_shown_ = true; |
| +} |
| + |
| +void ErrorScreensHistogramHelper::OnErrorShow(ErrorScreen::ErrorState error) { |
| + OnErrorShowTime(error, base::Time::Now()); |
| +} |
| + |
| +void ErrorScreensHistogramHelper::OnErrorShowTime(ErrorScreen::ErrorState error, |
| + base::Time now) { |
| + last_error_shown_ = error; |
| + if (error_screen_start_time.is_null()) |
| + error_screen_start_time = now; |
| + UMA_HISTOGRAM_ENUMERATION(kOobeErrorScreensCounterPrefix + screen_name_, |
| + error, |
| + ErrorScreen::kHistogramErrorStateNum); |
| +} |
| + |
| +void ErrorScreensHistogramHelper::OnErrorHide() { |
| + OnErrorHideTime(base::Time::Now()); |
| +} |
| + |
| +void ErrorScreensHistogramHelper::OnErrorHideTime(base::Time now) { |
| + DCHECK(!error_screen_start_time.is_null()); |
| + time_on_error_screens += now - error_screen_start_time; |
| + error_screen_start_time = base::Time(); |
| +} |
| + |
| +ErrorScreensHistogramHelper::~ErrorScreensHistogramHelper() { |
| + if (was_shown_) { |
| + if (last_error_shown_ == ErrorScreen::ERROR_STATE_NONE) { |
| + UMA_HISTOGRAM_ENUMERATION(kOobeErrorScreensCounterPrefix + screen_name_, |
| + ErrorScreen::ERROR_STATE_NONE, |
| + ErrorScreen::kHistogramErrorStateNum); |
| + } else { |
| + if (!error_screen_start_time.is_null()) { |
| + time_on_error_screens += base::Time::Now() - error_screen_start_time; |
| + error_screen_start_time = base::Time(); |
| + } |
| + UMA_HISTOGRAM_MEDIUM_TIMES(kOobeTimeSpentOnErrorScreensPrefix + |
|
ygorshenin1
2014/08/26 14:33:14
Am I right that if, for example, 30 seconds were s
Roman Sorokin (ftl)
2014/09/04 13:26:47
Yes, we decided with Nikita to report the last err
ygorshenin1
2014/09/04 15:13:03
OK, could you please add an clarification to the h
|
| + screen_name_ + |
| + ErrorToString(last_error_shown_), |
| + time_on_error_screens); |
| + } |
| + } |
| +} |
| + |
| +} // namespace chromeos |