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 "url/gurl.h"
14 
15 namespace net {
16 
ReportingReport(const absl::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)17 ReportingReport::ReportingReport(
18     const absl::optional<base::UnguessableToken>& reporting_source,
19     const NetworkAnonymizationKey& network_anonymization_key,
20     const GURL& url,
21     const std::string& user_agent,
22     const std::string& group,
23     const std::string& type,
24     base::Value::Dict body,
25     int depth,
26     base::TimeTicks queued,
27     int attempts)
28     : reporting_source(reporting_source),
29       network_anonymization_key(network_anonymization_key),
30       id(base::UnguessableToken::Create()),
31       url(url),
32       user_agent(user_agent),
33       group(group),
34       type(type),
35       body(std::move(body)),
36       depth(depth),
37       queued(queued),
38       attempts(attempts) {
39   // If |reporting_source| is present, it must not be empty.
40   DCHECK(!(reporting_source.has_value() && reporting_source->is_empty()));
41 }
42 
43 ReportingReport::ReportingReport() = default;
44 ReportingReport::ReportingReport(ReportingReport&& other) = default;
45 ReportingReport& ReportingReport::operator=(ReportingReport&& other) = default;
46 ReportingReport::~ReportingReport() = default;
47 
GetGroupKey() const48 ReportingEndpointGroupKey ReportingReport::GetGroupKey() const {
49   return ReportingEndpointGroupKey(network_anonymization_key, reporting_source,
50                                    url::Origin::Create(url), group);
51 }
52 
IsUploadPending() const53 bool ReportingReport::IsUploadPending() const {
54   return status == Status::PENDING || status == Status::DOOMED ||
55          status == Status::SUCCESS;
56 }
57 
58 }  // namespace net
59