[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 1 | // Copyright 2014 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 "components/domain_reliability/beacon.h" |
| 6 | |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 7 | #include <memory> |
dcheng | 5160635 | 2015-12-26 21:16:23 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 10 | #include "base/values.h" |
ttuttle | ccdd6cc5 | 2015-11-22 06:09:40 | [diff] [blame] | 11 | #include "components/domain_reliability/util.h" |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 12 | #include "net/base/net_errors.h" |
| 13 | |
| 14 | namespace domain_reliability { |
| 15 | |
| 16 | using base::Value; |
| 17 | using base::DictionaryValue; |
| 18 | |
| 19 | DomainReliabilityBeacon::DomainReliabilityBeacon() {} |
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 20 | DomainReliabilityBeacon::DomainReliabilityBeacon( |
| 21 | const DomainReliabilityBeacon& other) = default; |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 22 | DomainReliabilityBeacon::~DomainReliabilityBeacon() {} |
| 23 | |
dcheng | 04a35cd | 2016-04-22 15:07:24 | [diff] [blame] | 24 | std::unique_ptr<Value> DomainReliabilityBeacon::ToValue( |
ttuttle | 743f4ae | 2014-11-04 20:22:32 | [diff] [blame] | 25 | base::TimeTicks upload_time, |
ttuttle | ccdd6cc5 | 2015-11-22 06:09:40 | [diff] [blame] | 26 | base::TimeTicks last_network_change_time, |
| 27 | const GURL& collector_url, |
leon.han | cf889c7 | 2017-01-14 02:31:22 | [diff] [blame] | 28 | const std::vector<std::unique_ptr<std::string>>& path_prefixes) const { |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 29 | auto beacon_value = std::make_unique<DictionaryValue>(); |
ttuttle | ccdd6cc5 | 2015-11-22 06:09:40 | [diff] [blame] | 30 | DCHECK(url.is_valid()); |
| 31 | GURL sanitized_url = SanitizeURLForReport(url, collector_url, path_prefixes); |
| 32 | beacon_value->SetString("url", sanitized_url.spec()); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 33 | beacon_value->SetString("status", status); |
zhongyi | 291d030 | 2015-12-14 07:06:25 | [diff] [blame] | 34 | if (!quic_error.empty()) |
| 35 | beacon_value->SetString("quic_error", quic_error); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 36 | if (chrome_error != net::OK) { |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 37 | auto failure_value = std::make_unique<DictionaryValue>(); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 38 | failure_value->SetString("custom_error", |
| 39 | net::ErrorToString(chrome_error)); |
jdoerrie | c1a515d | 2017-06-02 09:44:38 | [diff] [blame] | 40 | beacon_value->Set("failure_data", std::move(failure_value)); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 41 | } |
| 42 | beacon_value->SetString("server_ip", server_ip); |
ttuttle | 50ff1a27 | 2015-04-24 04:16:45 | [diff] [blame] | 43 | beacon_value->SetBoolean("was_proxied", was_proxied); |
[email protected] | 414617b | 2014-06-30 16:49:13 | [diff] [blame] | 44 | beacon_value->SetString("protocol", protocol); |
zhongyi | c51f4ed | 2015-12-08 00:41:13 | [diff] [blame] | 45 | if (details.quic_broken) |
| 46 | beacon_value->SetBoolean("quic_broken", details.quic_broken); |
zhongyi | 93fa5a9 | 2016-03-14 18:10:57 | [diff] [blame] | 47 | if (details.quic_port_migration_detected) |
| 48 | beacon_value->SetBoolean("quic_port_migration_detected", |
| 49 | details.quic_port_migration_detected); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 50 | if (http_response_code >= 0) |
| 51 | beacon_value->SetInteger("http_response_code", http_response_code); |
ttuttle | ccdd6cc5 | 2015-11-22 06:09:40 | [diff] [blame] | 52 | beacon_value->SetInteger("request_elapsed_ms", elapsed.InMilliseconds()); |
| 53 | base::TimeDelta request_age = upload_time - start_time; |
| 54 | beacon_value->SetInteger("request_age_ms", request_age.InMilliseconds()); |
ttuttle | 9f4c7b0 | 2014-11-06 22:56:52 | [diff] [blame] | 55 | bool network_changed = last_network_change_time > start_time; |
| 56 | beacon_value->SetBoolean("network_changed", network_changed); |
ttuttle | ccc4ffa | 2015-12-10 20:08:46 | [diff] [blame] | 57 | beacon_value->SetDouble("sample_rate", sample_rate); |
dcheng | 5160635 | 2015-12-26 21:16:23 | [diff] [blame] | 58 | return std::move(beacon_value); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } // namespace domain_reliability |