• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_REPORTING_REPORTING_REPORT_H_
6 #define NET_REPORTING_REPORTING_REPORT_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/time/time.h"
12 #include "base/unguessable_token.h"
13 #include "base/values.h"
14 #include "net/base/net_export.h"
15 #include "net/base/network_anonymization_key.h"
16 #include "net/reporting/reporting_endpoint.h"
17 #include "third_party/abseil-cpp/absl/types/optional.h"
18 #include "url/gurl.h"
19 
20 namespace net {
21 
22 // An undelivered report.
23 struct NET_EXPORT ReportingReport {
24  public:
25   enum class Status {
26     // Report has been queued and no attempt has been made to deliver it yet,
27     // or attempted previous upload failed (impermanently).
28     QUEUED,
29 
30     // There is an ongoing attempt to upload this report.
31     PENDING,
32 
33     // Deletion of this report was requested while it was pending, so it should
34     // be removed after the attempted upload completes.
35     DOOMED,
36 
37     // Similar to DOOMED with the difference that the upload was already
38     // successful.
39     SUCCESS,
40   };
41 
42   // TODO(chlily): Remove |attempts| argument as it is (almost?) always 0.
43   ReportingReport(
44       const absl::optional<base::UnguessableToken>& reporting_source,
45       const NetworkAnonymizationKey& network_anonymization_key,
46       const GURL& url,
47       const std::string& user_agent,
48       const std::string& group,
49       const std::string& type,
50       base::Value::Dict body,
51       int depth,
52       base::TimeTicks queued,
53       int attempts);
54 
55   // Do NOT use this constructor outside of mojo deserialization context.
56   ReportingReport();
57   ReportingReport(const ReportingReport&) = delete;
58   ReportingReport(ReportingReport&& other);
59   ReportingReport& operator=(const ReportingReport&) = delete;
60   ReportingReport& operator=(ReportingReport&& other);
61   ~ReportingReport();
62 
63   // Bundles together the NIK, origin of the report URL, and group name.
64   // This is not exactly the same as the group key of the endpoint that the
65   // report will be delivered to. The origin may differ if the endpoint is
66   // configured for a superdomain of the report's origin. The NIK and group name
67   // will be the same.
68   ReportingEndpointGroupKey GetGroupKey() const;
69 
70   static void RecordReportDiscardedForNoURLRequestContext();
71   static void RecordReportDiscardedForNoReportingService();
72 
73   // Whether the report is part of an ongoing delivery attempt.
74   bool IsUploadPending() const;
75 
76   // The reporting source token for the document or worker which triggered this
77   // report, if it can be associated with one, or nullopt otherwise (Network
78   // reports, such as NEL, for instance, do not support such attribution.)
79   // This is used to identify appropriate endpoints to deliver this report to;
80   // reports with an attached source token may be delivered to a named endpoint
81   // with a matching source, but are also eligible to be delivered to an
82   // endpoint group without a source. Reports without a source token can only be
83   // delivered to endpoint groups without one.
84   // (Not included in the delivered report.)
85   absl::optional<base::UnguessableToken> reporting_source;
86 
87   // The NAK of the request that triggered this report. (Not included in the
88   // delivered report.)
89   NetworkAnonymizationKey network_anonymization_key;
90 
91   // The id of the report, used by DevTools to identify and tell apart
92   // individual reports.
93   base::UnguessableToken id;
94 
95   // The URL of the document that triggered the report. (Included in the
96   // delivered report.)
97   GURL url;
98 
99   // The User-Agent header that was used for the request.
100   std::string user_agent;
101 
102   // The endpoint group that should be used to deliver the report. (Not included
103   // in the delivered report.)
104   std::string group;
105 
106   // The type of the report. (Included in the delivered report.)
107   std::string type;
108 
109   // The body of the report. (Included in the delivered report.)
110   base::Value::Dict body;
111 
112   // How many uploads deep the related request was: 0 if the related request was
113   // not an upload (or there was no related request), or n+1 if it was an upload
114   // reporting on requests of at most depth n.
115   int depth;
116 
117   // When the report was queued. (Included in the delivered report as an age
118   // relative to the time of the delivery attempt.)
119   base::TimeTicks queued;
120 
121   // The number of delivery attempts made so far, not including an active
122   // attempt. (Not included in the delivered report.)
123   int attempts = 0;
124 
125   Status status = Status::QUEUED;
126 };
127 
128 }  // namespace net
129 
130 #endif  // NET_REPORTING_REPORTING_REPORT_H_
131