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

Side by Side Diff: components/metrics/metrics_reporting_service.cc

Issue 2608833002: Move logic for uploading logs into a ReportingService object. (Closed)
Patch Set: Incorporate feedback Created 3 years, 9 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
(Empty)
1 // Copyright 2017 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 // ReportingService specialized to report UMA metrics.
6
7 #include "components/metrics/metrics_reporting_service.h"
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "components/metrics/metrics_pref_names.h"
13 #include "components/metrics/persisted_logs_metrics_impl.h"
14 #include "components/metrics/url_constants.h"
15 #include "components/prefs/pref_registry_simple.h"
16
17 namespace metrics {
18
19 namespace {
20
21 // If an upload fails, and the transmission was over this byte count, then we
22 // will discard the log, and not try to retransmit it. We also don't persist
23 // the log to the prefs for transmission during the next chrome session if this
24 // limit is exceeded.
25 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024;
26
27 enum ResponseStatus {
28 UNKNOWN_FAILURE,
29 SUCCESS,
30 BAD_REQUEST, // Invalid syntax or log too large.
31 NO_RESPONSE,
32 NUM_RESPONSE_STATUSES
33 };
34
35 ResponseStatus ResponseCodeToStatus(int response_code) {
36 switch (response_code) {
37 case -1:
38 return NO_RESPONSE;
39 case 200:
40 return SUCCESS;
41 case 400:
42 return BAD_REQUEST;
43 default:
44 return UNKNOWN_FAILURE;
45 }
46 }
47
48 } // namespace
49
50 // static
51 void MetricsReportingService::RegisterPrefs(PrefRegistrySimple* registry) {
52 ReportingService::RegisterPrefs(registry);
53 MetricsLogStore::RegisterPrefs(registry);
54 }
55
56 MetricsReportingService::MetricsReportingService(MetricsServiceClient* client,
57 PrefService* local_state)
58 : ReportingService(client, local_state, kUploadLogAvoidRetransmitSize),
59 metrics_log_store_(local_state, kUploadLogAvoidRetransmitSize) {}
60
61 MetricsReportingService::~MetricsReportingService() {}
62
63 LogStore* MetricsReportingService::log_store() {
64 return &metrics_log_store_;
65 }
66
67 const std::string MetricsReportingService::upload_url() {
68 return client()->GetMetricsServerUrl();
69 }
70
71 const std::string MetricsReportingService::upload_mime_type() {
72 return metrics::kDefaultMetricsMimeType;
73 }
74
75 MetricsLogUploader::MetricServiceType MetricsReportingService::service_type() {
76 return metrics::MetricsLogUploader::UMA;
77 }
78
79 void MetricsReportingService::LogActualUploadInterval(
80 base::TimeDelta interval) {
81 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval",
82 interval.InMinutes(), 1,
83 base::TimeDelta::FromHours(12).InMinutes(), 50);
84 }
85
86 void MetricsReportingService::LogCellularConstraint(bool upload_canceled) {
87 UMA_HISTOGRAM_BOOLEAN("UMA.LogUpload.Canceled.CellularConstraint",
88 upload_canceled);
89 }
90
91 void MetricsReportingService::LogResponseCode(int response_code) {
92 // Log a histogram to track response success vs. failure rates.
93 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf",
94 ResponseCodeToStatus(response_code),
95 NUM_RESPONSE_STATUSES);
96 }
97
98 void MetricsReportingService::LogSuccess(size_t log_size) {
99 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024);
100 }
101
102 void MetricsReportingService::LogLargeRejection(size_t log_size) {
103 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded",
Alexei Svitkine (slow) 2017/03/01 16:06:29 Nit: We now prefer the COUNTS_1M macro which has s
Steven Holte 2017/03/04 01:35:51 Done.
104 static_cast<int>(log_size));
105 }
106
107 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698