• 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 #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 "net/reporting/reporting_target_type.h"
15 #include "url/gurl.h"
16 
17 namespace net {
18 
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,ReportingTargetType target_type)19 ReportingReport::ReportingReport(
20     const std::optional<base::UnguessableToken>& reporting_source,
21     const NetworkAnonymizationKey& network_anonymization_key,
22     const GURL& url,
23     const std::string& user_agent,
24     const std::string& group,
25     const std::string& type,
26     base::Value::Dict body,
27     int depth,
28     base::TimeTicks queued,
29     int attempts,
30     ReportingTargetType target_type)
31     : reporting_source(reporting_source),
32       network_anonymization_key(network_anonymization_key),
33       id(base::UnguessableToken::Create()),
34       url(url),
35       user_agent(user_agent),
36       group(group),
37       type(type),
38       body(std::move(body)),
39       depth(depth),
40       queued(queued),
41       attempts(attempts),
42       target_type(target_type) {
43   // If |reporting_source| is present, it must not be empty.
44   DCHECK(!(reporting_source.has_value() && reporting_source->is_empty()));
45 }
46 
47 ReportingReport::ReportingReport() = default;
48 ReportingReport::ReportingReport(ReportingReport&& other) = default;
49 ReportingReport& ReportingReport::operator=(ReportingReport&& other) = default;
50 ReportingReport::~ReportingReport() = default;
51 
GetGroupKey() const52 ReportingEndpointGroupKey ReportingReport::GetGroupKey() const {
53   // Enterprise reports do not have an origin.
54   if (target_type == ReportingTargetType::kEnterprise) {
55     return ReportingEndpointGroupKey(
56         network_anonymization_key, /*origin=*/std::nullopt, group, target_type);
57   } else {
58     return ReportingEndpointGroupKey(network_anonymization_key,
59                                      reporting_source, url::Origin::Create(url),
60                                      group, target_type);
61   }
62 }
63 
IsUploadPending() const64 bool ReportingReport::IsUploadPending() const {
65   return status == Status::PENDING || status == Status::DOOMED ||
66          status == Status::SUCCESS;
67 }
68 
69 }  // namespace net
70