juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 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> |
juliatuttle | a35bbc8 | 2017-05-22 19:25:19 | [diff] [blame] | 9 | #include <utility> |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 10 | |
| 11 | #include "base/time/time.h" |
| 12 | #include "base/values.h" |
| 13 | #include "url/gurl.h" |
| 14 | |
| 15 | namespace net { |
| 16 | |
Lily Chen | 0938346 | 2020-04-09 21:39:06 | [diff] [blame] | 17 | ReportingReport::ReportingReport( |
Ian Clelland | e74db7e6 | 2021-07-22 18:29:37 | [diff] [blame] | 18 | const absl::optional<base::UnguessableToken>& reporting_source, |
Lily Chen | 0938346 | 2020-04-09 21:39:06 | [diff] [blame] | 19 | const NetworkIsolationKey& network_isolation_key, |
| 20 | const GURL& url, |
| 21 | const std::string& user_agent, |
| 22 | const std::string& group, |
| 23 | const std::string& type, |
| 24 | std::unique_ptr<const base::Value> body, |
| 25 | int depth, |
| 26 | base::TimeTicks queued, |
| 27 | int attempts) |
Ian Clelland | e74db7e6 | 2021-07-22 18:29:37 | [diff] [blame] | 28 | : reporting_source(reporting_source), |
| 29 | network_isolation_key(network_isolation_key), |
Wolfgang Beyer | 7afc1e6 | 2021-09-06 10:31:20 | [diff] [blame] | 30 | id(base::UnguessableToken::Create()), |
Lily Chen | 0938346 | 2020-04-09 21:39:06 | [diff] [blame] | 31 | url(url), |
Douglas Creager | f6cb49f7 | 2018-07-19 20:14:53 | [diff] [blame] | 32 | user_agent(user_agent), |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 33 | group(group), |
| 34 | type(type), |
| 35 | body(std::move(body)), |
Julia Tuttle | 107e3067 | 2018-03-29 18:48:42 | [diff] [blame] | 36 | depth(depth), |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 37 | queued(queued), |
Ian Clelland | e74db7e6 | 2021-07-22 18:29:37 | [diff] [blame] | 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 | } |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 42 | |
Wolfgang Beyer | e243369 | 2021-08-25 11:19:49 | [diff] [blame] | 43 | ReportingReport::ReportingReport() = default; |
| 44 | ReportingReport::ReportingReport(ReportingReport&& other) = default; |
| 45 | ReportingReport& ReportingReport::operator=(ReportingReport&& other) = default; |
Yutaka Hirano | 1515aed | 2021-07-09 07:38:43 | [diff] [blame] | 46 | ReportingReport::~ReportingReport() = default; |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 47 | |
Lily Chen | 606c940 | 2020-05-19 18:50:33 | [diff] [blame] | 48 | ReportingEndpointGroupKey ReportingReport::GetGroupKey() const { |
Ian Clelland | e74db7e6 | 2021-07-22 18:29:37 | [diff] [blame] | 49 | return ReportingEndpointGroupKey(network_isolation_key, reporting_source, |
Lily Chen | 606c940 | 2020-05-19 18:50:33 | [diff] [blame] | 50 | url::Origin::Create(url), group); |
| 51 | } |
| 52 | |
Lily Chen | d9ab4e5 | 2020-01-03 22:04:44 | [diff] [blame] | 53 | bool ReportingReport::IsUploadPending() const { |
Wolfgang Beyer | aa852b8 | 2021-09-07 05:21:26 | [diff] [blame] | 54 | return status == Status::PENDING || status == Status::DOOMED || |
| 55 | status == Status::SUCCESS; |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 56 | } |
juliatuttle | 58684333 | 2017-03-27 16:22:37 | [diff] [blame] | 57 | |
| 58 | } // namespace net |