| Index: components/metrics/metrics_reporting_service.cc
|
| diff --git a/components/metrics/metrics_reporting_service.cc b/components/metrics/metrics_reporting_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..116a67f190a4ebc1d04146386e750c3447e633eb
|
| --- /dev/null
|
| +++ b/components/metrics/metrics_reporting_service.cc
|
| @@ -0,0 +1,108 @@
|
| +// Copyright 2017 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.
|
| +
|
| +// ReportingService specialized to report UMA metrics.
|
| +
|
| +#include "components/metrics/metrics_reporting_service.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| +#include "components/metrics/metrics_pref_names.h"
|
| +#include "components/metrics/persisted_logs_metrics_impl.h"
|
| +#include "components/metrics/url_constants.h"
|
| +#include "components/prefs/pref_registry_simple.h"
|
| +
|
| +namespace metrics {
|
| +
|
| +namespace {
|
| +
|
| +// If an upload fails, and the transmission was over this byte count, then we
|
| +// will discard the log, and not try to retransmit it. We also don't persist
|
| +// the log to the prefs for transmission during the next chrome session if this
|
| +// limit is exceeded.
|
| +const size_t kUploadLogAvoidRetransmitSize = 100 * 1024;
|
| +
|
| +enum ResponseStatus {
|
| + UNKNOWN_FAILURE,
|
| + SUCCESS,
|
| + BAD_REQUEST, // Invalid syntax or log too large.
|
| + NO_RESPONSE,
|
| + NUM_RESPONSE_STATUSES
|
| +};
|
| +
|
| +ResponseStatus ResponseCodeToStatus(int response_code) {
|
| + switch (response_code) {
|
| + case -1:
|
| + return NO_RESPONSE;
|
| + case 200:
|
| + return SUCCESS;
|
| + case 400:
|
| + return BAD_REQUEST;
|
| + default:
|
| + return UNKNOWN_FAILURE;
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +void MetricsReportingService::RegisterPrefs(PrefRegistrySimple* registry) {
|
| + ReportingService::RegisterPrefs(registry);
|
| + MetricsLogStore::RegisterPrefs(registry);
|
| +}
|
| +
|
| +MetricsReportingService::MetricsReportingService(MetricsServiceClient* client,
|
| + PrefService* local_state)
|
| + : ReportingService(client, local_state, kUploadLogAvoidRetransmitSize),
|
| + metrics_log_store_(local_state, kUploadLogAvoidRetransmitSize) {}
|
| +
|
| +MetricsReportingService::~MetricsReportingService() {}
|
| +
|
| +LogStore* MetricsReportingService::log_store() {
|
| + return &metrics_log_store_;
|
| +}
|
| +
|
| +std::string MetricsReportingService::GetUploadUrl() const {
|
| + return client()->GetMetricsServerUrl();
|
| +}
|
| +
|
| +base::StringPiece MetricsReportingService::upload_mime_type() const {
|
| + return kDefaultMetricsMimeType;
|
| +}
|
| +
|
| +MetricsLogUploader::MetricServiceType MetricsReportingService::service_type()
|
| + const {
|
| + return MetricsLogUploader::UMA;
|
| +}
|
| +
|
| +void MetricsReportingService::LogActualUploadInterval(
|
| + base::TimeDelta interval) {
|
| + UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval",
|
| + interval.InMinutes(), 1,
|
| + base::TimeDelta::FromHours(12).InMinutes(), 50);
|
| +}
|
| +
|
| +void MetricsReportingService::LogCellularConstraint(bool upload_canceled) {
|
| + UMA_HISTOGRAM_BOOLEAN("UMA.LogUpload.Canceled.CellularConstraint",
|
| + upload_canceled);
|
| +}
|
| +
|
| +void MetricsReportingService::LogResponseCode(int response_code) {
|
| + // Log a histogram to track response success vs. failure rates.
|
| + UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf",
|
| + ResponseCodeToStatus(response_code),
|
| + NUM_RESPONSE_STATUSES);
|
| +}
|
| +
|
| +void MetricsReportingService::LogSuccess(size_t log_size) {
|
| + UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024);
|
| +}
|
| +
|
| +void MetricsReportingService::LogLargeRejection(size_t log_size) {
|
| + UMA_HISTOGRAM_COUNTS_1M("UMA.Large Rejected Log was Discarded",
|
| + static_cast<int>(log_size));
|
| +}
|
| +
|
| +} // namespace metrics
|
|
|