Implement keycode text conversion functions for Ozone.
[chromium-blink-merge.git] / net / quic / quic_sustained_bandwidth_recorder.h
blob11685d2817e417c81604e9390ccf9767053b48f6
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.
5 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_
6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_
8 #include "base/logging.h"
9 #include "net/quic/quic_bandwidth.h"
10 #include "net/quic/quic_time.h"
12 namespace net {
14 namespace test {
15 class QuicSustainedBandwidthRecorderPeer;
16 } // namespace test
18 // This class keeps track of a sustained bandwidth estimate to ultimately send
19 // to the client in a server config update message. A sustained bandwidth
20 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has
21 // been given uninterrupted reliable estimates over a certain period of time.
22 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder {
23 public:
24 QuicSustainedBandwidthRecorder();
26 // As long as |in_recovery| is consistently false, multiple calls to this
27 // method over a 3 * srtt period results in storage of a valid sustained
28 // bandwidth estimate.
29 // |time_now| is used as a max bandwidth timestamp if needed.
30 void RecordEstimate(bool in_recovery,
31 bool in_slow_start,
32 QuicBandwidth bandwidth,
33 QuicTime estimate_time,
34 QuicWallTime wall_time,
35 QuicTime::Delta srtt);
37 bool HasEstimate() const {
38 return has_estimate_;
41 QuicBandwidth BandwidthEstimate() const {
42 DCHECK(has_estimate_);
43 return bandwidth_estimate_;
46 QuicBandwidth MaxBandwidthEstimate() const {
47 DCHECK(has_estimate_);
48 return max_bandwidth_estimate_;
51 int64 MaxBandwidthTimestamp() const {
52 DCHECK(has_estimate_);
53 return max_bandwidth_timestamp_;
56 bool EstimateRecordedDuringSlowStart() const {
57 DCHECK(has_estimate_);
58 return bandwidth_estimate_recorded_during_slow_start_;
61 private:
62 friend class test::QuicSustainedBandwidthRecorderPeer;
64 // True if we have been able to calculate sustained bandwidth, over at least
65 // one recording period (3 * rtt).
66 bool has_estimate_;
68 // True if the last call to RecordEstimate had a reliable estimate.
69 bool is_recording_;
71 // True if the current sustained bandwidth estimate was generated while in
72 // slow start.
73 bool bandwidth_estimate_recorded_during_slow_start_;
75 // The latest sustained bandwidth estimate.
76 QuicBandwidth bandwidth_estimate_;
78 // The maximum sustained bandwidth seen over the lifetime of the connection.
79 QuicBandwidth max_bandwidth_estimate_;
81 // Timestamp indicating when the max_bandwidth_estimate_ was seen.
82 int64 max_bandwidth_timestamp_;
84 // Timestamp marking the beginning of the latest recording period.
85 QuicTime start_time_;
87 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder);
90 } // namespace net
92 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_