1 // Copyright 2016 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 #ifndef NET_NQE_NETWORK_QUALITY_OBSERVATION_H_ 6 #define NET_NQE_NETWORK_QUALITY_OBSERVATION_H_ 7 8 #include <stdint.h> 9 10 #include <optional> 11 #include <vector> 12 13 #include "base/time/time.h" 14 #include "net/base/net_export.h" 15 #include "net/nqe/network_quality_estimator_util.h" 16 #include "net/nqe/network_quality_observation_source.h" 17 18 namespace net::nqe::internal { 19 20 // Records observations of network quality metrics (such as round trip time 21 // or throughput), along with the time the observation was made. Observations 22 // can be made at several places in the network stack, thus the observation 23 // source is provided as well. 24 class NET_EXPORT_PRIVATE Observation { 25 public: 26 Observation(int32_t value, 27 base::TimeTicks timestamp, 28 int32_t signal_strength, 29 NetworkQualityObservationSource source); 30 31 Observation(int32_t value, 32 base::TimeTicks timestamp, 33 int32_t signal_strength, 34 NetworkQualityObservationSource source, 35 const std::optional<IPHash>& host); 36 37 Observation(const Observation& other); 38 Observation& operator=(const Observation& other); 39 40 ~Observation(); 41 42 // Value of the observation. value()43 int32_t value() const { return value_; } 44 45 // Time when the observation was taken. timestamp()46 base::TimeTicks timestamp() const { return timestamp_; } 47 48 // Signal strength when the observation was taken. Set to INT32_MIN when the 49 // value is unavailable. Otherwise, must be between 0 and 4 (both inclusive). signal_strength()50 int32_t signal_strength() const { return signal_strength_; } 51 52 // The source of the observation. source()53 NetworkQualityObservationSource source() const { return source_; } 54 55 // A unique identifier for the remote host which was used for the measurement. host()56 std::optional<IPHash> host() const { return host_; } 57 58 // Returns the observation categories to which this observation belongs to. 59 std::vector<ObservationCategory> GetObservationCategories() const; 60 61 private: 62 int32_t value_; 63 64 base::TimeTicks timestamp_; 65 66 // Signal strength of the network when the observation was taken. Set to 67 // INT32_MIN when the value is unavailable. Otherwise, must be between 0 and 4 68 // (both inclusive). 69 int32_t signal_strength_; 70 71 NetworkQualityObservationSource source_; 72 73 std::optional<IPHash> host_; 74 }; 75 76 } // namespace net::nqe::internal 77 78 #endif // NET_NQE_NETWORK_QUALITY_OBSERVATION_H_ 79