xref: /aosp_15_r20/external/cronet/net/nqe/cached_network_quality.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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_CACHED_NETWORK_QUALITY_H_
6 #define NET_NQE_CACHED_NETWORK_QUALITY_H_
7 
8 #include "base/time/time.h"
9 #include "net/base/net_export.h"
10 #include "net/nqe/effective_connection_type.h"
11 #include "net/nqe/network_quality.h"
12 
13 namespace net::nqe::internal {
14 
15 // CachedNetworkQuality stores the quality of a previously seen network.
16 class NET_EXPORT_PRIVATE CachedNetworkQuality {
17  public:
18   CachedNetworkQuality();
19   explicit CachedNetworkQuality(
20       EffectiveConnectionType effective_connection_type);
21 
22   // |last_update_time| is the time when the |network_quality| was computed.
23   CachedNetworkQuality(base::TimeTicks last_update_time,
24                        const NetworkQuality& network_quality,
25                        EffectiveConnectionType effective_connection_type);
26   CachedNetworkQuality(const CachedNetworkQuality& other);
27   ~CachedNetworkQuality();
28 
29   // Returns the network quality associated with this cached entry.
network_quality()30   const NetworkQuality& network_quality() const { return network_quality_; }
31 
32   CachedNetworkQuality& operator=(const CachedNetworkQuality& other);
33 
34   // Returns true if this cache entry was updated before
35   // |cached_network_quality|.
36   bool OlderThan(const CachedNetworkQuality& cached_network_quality) const;
37 
last_update_time()38   base::TimeTicks last_update_time() { return last_update_time_; }
39 
effective_connection_type()40   EffectiveConnectionType effective_connection_type() const {
41     return effective_connection_type_;
42   }
43 
44  private:
45   // Time when this cache entry was last updated.
46   base::TimeTicks last_update_time_;
47 
48   // Quality of this cached network.
49   NetworkQuality network_quality_;
50 
51   // Effective connection type of the cached network.
52   EffectiveConnectionType effective_connection_type_;
53 };
54 
55 }  // namespace net::nqe::internal
56 
57 #endif  // NET_NQE_CACHED_NETWORK_QUALITY_H_
58