forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporting_report.cc
74 lines (58 loc) · 2.06 KB
/
reporting_report.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 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.
#include "net/reporting/reporting_report.h"
#include <memory>
#include <string>
#include <utility>
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "base/values.h"
#include "url/gurl.h"
namespace net {
namespace {
void RecordReportOutcome(ReportingReport::Outcome outcome) {
UMA_HISTOGRAM_ENUMERATION("Net.Reporting.ReportOutcome", outcome,
ReportingReport::Outcome::MAX);
}
} // namespace
ReportingReport::ReportingReport(const GURL& url,
const std::string& user_agent,
const std::string& group,
const std::string& type,
std::unique_ptr<const base::Value> body,
int depth,
base::TimeTicks queued,
int attempts)
: url(url),
user_agent(user_agent),
group(group),
type(type),
body(std::move(body)),
depth(depth),
queued(queued),
attempts(attempts),
outcome(Outcome::UNKNOWN),
recorded_outcome(false) {}
ReportingReport::~ReportingReport() {
DCHECK(recorded_outcome);
}
// static
void ReportingReport::RecordReportDiscardedForNoURLRequestContext() {
RecordReportOutcome(Outcome::DISCARDED_NO_URL_REQUEST_CONTEXT);
}
// static
void ReportingReport::RecordReportDiscardedForNoReportingService() {
RecordReportOutcome(Outcome::DISCARDED_NO_REPORTING_SERVICE);
}
void ReportingReport::RecordOutcome(base::TimeTicks now) {
DCHECK(!recorded_outcome);
RecordReportOutcome(outcome);
if (outcome == Outcome::DELIVERED) {
UMA_HISTOGRAM_LONG_TIMES_100("Net.Reporting.ReportDeliveredLatency",
now - queued);
UMA_HISTOGRAM_COUNTS_100("Net.Reporting.ReportDeliveredAttempts", attempts);
}
recorded_outcome = true;
}
} // namespace net