Chromium Code Reviews| Index: chromecast/net/connectivity_checker_impl.cc |
| diff --git a/chromecast/net/connectivity_checker_impl.cc b/chromecast/net/connectivity_checker_impl.cc |
| index 392ca8addaf5330b6128ded46b01c211e534d5c6..0d4ce39984b91372b4041ac8d1be560174af5403 100644 |
| --- a/chromecast/net/connectivity_checker_impl.cc |
| +++ b/chromecast/net/connectivity_checker_impl.cc |
| @@ -8,6 +8,9 @@ |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/values.h" |
| +#include "chromecast/base/metrics/cast_metrics_helper.h" |
| +#include "chromecast/base/serializers.h" |
| #include "chromecast/net/net_switches.h" |
| #include "net/base/request_priority.h" |
| #include "net/http/http_response_headers.h" |
| @@ -42,6 +45,9 @@ const char kDefaultConnectivityCheckUrl[] = |
| // downtime is less than 3 seconds. |
| const char kNetworkChangedDelayInSeconds = 3; |
| +const char kMetricNameNetworkConnectivityErrorType[] = |
| + "Network.Connectivity.ErrorType"; |
| + |
| } // namespace |
| ConnectivityCheckerImpl::ConnectivityCheckerImpl( |
| @@ -174,7 +180,7 @@ void ConnectivityCheckerImpl::OnResponseStarted(net::URLRequest* request) { |
| return; |
| } |
| VLOG(1) << "Connectivity check failed: " << http_response_code; |
| - OnUrlRequestError(); |
| + OnUrlRequestError(ErrorType::BAD_HTTP_STATUS); |
| timeout_.Cancel(); |
| } |
| @@ -189,11 +195,15 @@ void ConnectivityCheckerImpl::OnSSLCertificateError( |
| bool fatal) { |
| LOG(ERROR) << "OnSSLCertificateError: cert_status=" << ssl_info.cert_status; |
| net::SSLClientSocket::ClearSessionCache(); |
| - OnUrlRequestError(); |
| + OnUrlRequestError(ErrorType::SSL_CERTIFICATE_ERROR); |
| timeout_.Cancel(); |
| } |
| -void ConnectivityCheckerImpl::OnUrlRequestError() { |
| +void ConnectivityCheckerImpl::OnUrlRequestError(ErrorType type) { |
| + // Only record a metric for the initial disconnect event |
| + if (check_errors_ == 0) |
| + RecordNetworkConnectivityErrorType(type); |
| + |
| ++check_errors_; |
| if (check_errors_ > kNumErrorsToNotifyOffline) { |
| check_errors_ = kNumErrorsToNotifyOffline; |
| @@ -208,7 +218,7 @@ void ConnectivityCheckerImpl::OnUrlRequestError() { |
| void ConnectivityCheckerImpl::OnUrlRequestTimeout() { |
| LOG(ERROR) << "time out"; |
| - OnUrlRequestError(); |
| + OnUrlRequestError(ErrorType::REQUEST_TIMEOUT); |
| } |
| void ConnectivityCheckerImpl::Cancel() { |
| @@ -219,4 +229,16 @@ void ConnectivityCheckerImpl::Cancel() { |
| timeout_.Cancel(); |
| } |
| +void ConnectivityCheckerImpl::RecordNetworkConnectivityErrorType( |
| + ConnectivityCheckerImpl::ErrorType type) { |
| + std::unique_ptr<base::DictionaryValue> cast_event( |
|
bcf
2016/05/12 07:35:56
Is there a better way of constructing metrics in c
halliwell
2016/05/12 13:46:19
CastMetricsHelper::RecordApplicationEventWIthValue
bcf
2016/05/12 17:04:10
I saw this, but I wasn't sure we wanted to add the
|
| + new base::DictionaryValue()); |
| + cast_event->SetString("name", kMetricNameNetworkConnectivityErrorType); |
| + cast_event->SetDouble("time", base::TimeTicks::Now().ToInternalValue()); |
| + cast_event->SetInteger("value", static_cast<int>(type)); |
| + std::unique_ptr<std::string> message = SerializeToJson(*cast_event); |
| + DCHECK(message != nullptr); |
| + metrics::CastMetricsHelper::GetInstance()->RecordSimpleAction(*message); |
| +} |
| + |
| } // namespace chromecast |