beacon.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "components/domain_reliability/beacon.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/metrics/histogram_functions.h"
  8. #include "base/values.h"
  9. #include "components/domain_reliability/util.h"
  10. #include "net/base/net_errors.h"
  11. namespace domain_reliability {
  12. DomainReliabilityBeacon::DomainReliabilityBeacon() = default;
  13. DomainReliabilityBeacon::DomainReliabilityBeacon(
  14. const DomainReliabilityBeacon& other) = default;
  15. DomainReliabilityBeacon::~DomainReliabilityBeacon() {
  16. if (outcome != Outcome::kUnknown) {
  17. base::UmaHistogramEnumeration("Net.DomainReliability.BeaconOutcome",
  18. outcome);
  19. }
  20. }
  21. base::Value DomainReliabilityBeacon::ToValue(
  22. base::TimeTicks upload_time,
  23. base::TimeTicks last_network_change_time,
  24. const GURL& collector_url,
  25. const std::vector<std::unique_ptr<std::string>>& path_prefixes) const {
  26. base::Value beacon_value(base::Value::Type::DICTIONARY);
  27. DCHECK(url.is_valid());
  28. GURL sanitized_url = SanitizeURLForReport(url, collector_url, path_prefixes);
  29. beacon_value.SetStringKey("url", sanitized_url.spec());
  30. beacon_value.SetStringKey("status", status);
  31. if (!quic_error.empty())
  32. beacon_value.SetStringKey("quic_error", quic_error);
  33. if (chrome_error != net::OK) {
  34. base::Value failure_value(base::Value::Type::DICTIONARY);
  35. failure_value.SetStringKey("custom_error",
  36. net::ErrorToString(chrome_error));
  37. beacon_value.SetKey("failure_data", std::move(failure_value));
  38. }
  39. beacon_value.SetStringKey("server_ip", server_ip);
  40. beacon_value.SetBoolKey("was_proxied", was_proxied);
  41. beacon_value.SetStringKey("protocol", protocol);
  42. if (details.quic_broken)
  43. beacon_value.SetBoolKey("quic_broken", details.quic_broken);
  44. if (details.quic_port_migration_detected)
  45. beacon_value.SetBoolKey("quic_port_migration_detected",
  46. details.quic_port_migration_detected);
  47. if (http_response_code >= 0)
  48. beacon_value.SetIntKey("http_response_code", http_response_code);
  49. beacon_value.SetIntKey("request_elapsed_ms", elapsed.InMilliseconds());
  50. base::TimeDelta request_age = upload_time - start_time;
  51. beacon_value.SetIntKey("request_age_ms", request_age.InMilliseconds());
  52. bool network_changed = last_network_change_time > start_time;
  53. beacon_value.SetBoolKey("network_changed", network_changed);
  54. beacon_value.SetDoubleKey("sample_rate", sample_rate);
  55. return beacon_value;
  56. }
  57. } // namespace domain_reliability