xref: /aosp_15_r20/external/cronet/net/reporting/reporting_report.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #include "net/reporting/reporting_report.h"
6 
7 #include <memory>
8 #include <string>
9 #include <utility>
10 
11 #include "base/time/time.h"
12 #include "base/values.h"
13 #include "net/base/network_isolation_key.h"
14 #include "url/gurl.h"
15 
16 namespace net {
17 
ReportingReport(const std::optional<base::UnguessableToken> & reporting_source,const NetworkAnonymizationKey & network_anonymization_key,const GURL & url,const std::string & user_agent,const std::string & group,const std::string & type,base::Value::Dict body,int depth,base::TimeTicks queued,int attempts)18 ReportingReport::ReportingReport(
19     const std::optional<base::UnguessableToken>& reporting_source,
20     const NetworkAnonymizationKey& network_anonymization_key,
21     const GURL& url,
22     const std::string& user_agent,
23     const std::string& group,
24     const std::string& type,
25     base::Value::Dict body,
26     int depth,
27     base::TimeTicks queued,
28     int attempts)
29     : reporting_source(reporting_source),
30       network_anonymization_key(network_anonymization_key),
31       id(base::UnguessableToken::Create()),
32       url(url),
33       user_agent(user_agent),
34       group(group),
35       type(type),
36       body(std::move(body)),
37       depth(depth),
38       queued(queued),
39       attempts(attempts) {
40   // If |reporting_source| is present, it must not be empty.
41   DCHECK(!(reporting_source.has_value() && reporting_source->is_empty()));
42 }
43 
44 ReportingReport::ReportingReport() = default;
45 ReportingReport::ReportingReport(ReportingReport&& other) = default;
46 ReportingReport& ReportingReport::operator=(ReportingReport&& other) = default;
47 ReportingReport::~ReportingReport() = default;
48 
GetGroupKey() const49 ReportingEndpointGroupKey ReportingReport::GetGroupKey() const {
50   return ReportingEndpointGroupKey(network_anonymization_key, reporting_source,
51                                    url::Origin::Create(url), group);
52 }
53 
IsUploadPending() const54 bool ReportingReport::IsUploadPending() const {
55   return status == Status::PENDING || status == Status::DOOMED ||
56          status == Status::SUCCESS;
57 }
58 
59 }  // namespace net
60