| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/reporting/reporting_report.h" | 5 #include "net/reporting/reporting_report.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 18 namespace { |
| 19 |
| 20 void RecordReportOutcome(ReportingReport::Outcome outcome) { |
| 21 UMA_HISTOGRAM_ENUMERATION("Reporting.ReportOutcome", outcome, |
| 22 ReportingReport::Outcome::MAX); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 17 ReportingReport::ReportingReport(const GURL& url, | 27 ReportingReport::ReportingReport(const GURL& url, |
| 18 const std::string& group, | 28 const std::string& group, |
| 19 const std::string& type, | 29 const std::string& type, |
| 20 std::unique_ptr<const base::Value> body, | 30 std::unique_ptr<const base::Value> body, |
| 21 base::TimeTicks queued, | 31 base::TimeTicks queued, |
| 22 int attempts) | 32 int attempts) |
| 23 : url(url), | 33 : url(url), |
| 24 group(group), | 34 group(group), |
| 25 type(type), | 35 type(type), |
| 26 body(std::move(body)), | 36 body(std::move(body)), |
| 27 queued(queued), | 37 queued(queued), |
| 28 attempts(attempts) {} | 38 attempts(attempts), |
| 39 outcome(Outcome::UNKNOWN), |
| 40 recorded_outcome(false) {} |
| 29 | 41 |
| 30 ReportingReport::~ReportingReport() {} | 42 ReportingReport::~ReportingReport() { |
| 43 DCHECK(recorded_outcome); |
| 44 } |
| 45 |
| 46 // static |
| 47 void ReportingReport::RecordReportDiscardedForNoURLRequestContext() { |
| 48 RecordReportOutcome(Outcome::DISCARDED_NO_URL_REQUEST_CONTEXT); |
| 49 } |
| 50 |
| 51 // static |
| 52 void ReportingReport::RecordReportDiscardedForNoReportingService() { |
| 53 RecordReportOutcome(Outcome::DISCARDED_NO_REPORTING_SERVICE); |
| 54 } |
| 55 |
| 56 void ReportingReport::RecordOutcome(base::TimeTicks now) { |
| 57 DCHECK(!recorded_outcome); |
| 58 |
| 59 RecordReportOutcome(outcome); |
| 60 |
| 61 if (outcome == Outcome::DELIVERED) { |
| 62 UMA_HISTOGRAM_LONG_TIMES_100("Reporting.ReportDeliveredLatency", |
| 63 now - queued); |
| 64 UMA_HISTOGRAM_COUNTS_100("Reporting.ReportDeliveredAttempts", attempts); |
| 65 } |
| 66 |
| 67 recorded_outcome = true; |
| 68 } |
| 31 | 69 |
| 32 } // namespace net | 70 } // namespace net |
| OLD | NEW |