beacon.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef COMPONENTS_DOMAIN_RELIABILITY_BEACON_H_
  5. #define COMPONENTS_DOMAIN_RELIABILITY_BEACON_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/time/time.h"
  9. #include "components/domain_reliability/domain_reliability_export.h"
  10. #include "net/base/net_error_details.h"
  11. #include "net/base/network_isolation_key.h"
  12. #include "url/gurl.h"
  13. namespace base {
  14. class Value;
  15. } // namespace base
  16. namespace domain_reliability {
  17. // The per-request data that is uploaded to the Domain Reliability collector.
  18. struct DOMAIN_RELIABILITY_EXPORT DomainReliabilityBeacon {
  19. public:
  20. DomainReliabilityBeacon();
  21. DomainReliabilityBeacon(const DomainReliabilityBeacon& other);
  22. ~DomainReliabilityBeacon();
  23. // These values are persisted to logs. Entries should not be renumbered and
  24. // numeric values should never be reused.
  25. enum class Outcome {
  26. // Default value. This should not be recorded to the histogram.
  27. kUnknown = 0,
  28. // Successfully uploaded.
  29. kUploaded = 1,
  30. // Removed for being expired.
  31. kExpired = 2,
  32. // Evicted to make room for newer beacons.
  33. kEvicted = 3,
  34. // Deleted for user clearing browsing data.
  35. kCleared = 5,
  36. // Beacon was deleted upon context shutdown.
  37. kContextShutDown = 5,
  38. // Keep last.
  39. kMaxValue = kContextShutDown,
  40. };
  41. // Converts the Beacon to JSON format for uploading. Calculates the age
  42. // relative to an upload time of |upload_time|.
  43. //
  44. // |last_network_change_time| is used to determine which beacons are
  45. // labeled as from a previous network connection.
  46. // |collector_url| is compared to the URLs in the beacons to determine which
  47. // are being uploaded to a same-origin collector.
  48. // |path_prefixes| are used to include only a known-safe (not PII) prefix of
  49. // URLs when uploading to a non-same-origin collector.
  50. base::Value ToValue(
  51. base::TimeTicks upload_time,
  52. base::TimeTicks last_network_change_time,
  53. const GURL& collector_url,
  54. const std::vector<std::unique_ptr<std::string>>& path_prefixes) const;
  55. // The URL that the beacon is reporting on, if included.
  56. // The scheme can be non-secure.
  57. GURL url;
  58. // The NetworkIsolationKey associated with the request being reported on. Must
  59. // also be used to upload any report. This field does not appear in the
  60. // uploaded report.
  61. net::NetworkIsolationKey network_isolation_key;
  62. // Status string (e.g. "ok", "dns.nxdomain", "http.403").
  63. std::string status;
  64. // Granular QUIC error string (e.g. "quic.peer_going_away").
  65. std::string quic_error;
  66. // Net error code. Encoded as a string in the final JSON.
  67. int chrome_error;
  68. // IP address of the server the request went to.
  69. std::string server_ip;
  70. // Whether the request went through a proxy. If true, |server_ip| will be
  71. // empty.
  72. bool was_proxied;
  73. // Protocol used to make the request.
  74. std::string protocol;
  75. // Network error details for the request.
  76. net::NetErrorDetails details;
  77. // HTTP response code returned by the server, or -1 if none was received.
  78. int http_response_code;
  79. // Elapsed time between starting and completing the request.
  80. base::TimeDelta elapsed;
  81. // Start time of the request. Encoded as the request age in the final JSON.
  82. base::TimeTicks start_time;
  83. // Length of the chain of Domain Reliability uploads leading to this report.
  84. // Zero if the request was not caused by an upload, one if the request was
  85. // caused by an upload that itself contained no beacons caused by uploads,
  86. // et cetera.
  87. int upload_depth;
  88. // The probability that this request had of being reported ("sample rate").
  89. double sample_rate;
  90. // Records the ultimate outcome of this beacon, for metrics.
  91. Outcome outcome = Outcome::kUnknown;
  92. // Okay to copy and assign.
  93. };
  94. } // namespace domain_reliability
  95. #endif // COMPONENTS_DOMAIN_RELIABILITY_BEACON_H_