Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / net / quic / quic_flow_controller.h
blobafa022b1cf2c8812905fbfe8756289326aab0665
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_FLOW_CONTROLLER_H_
6 #define NET_QUIC_QUIC_FLOW_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "net/base/net_export.h"
10 #include "net/quic/quic_protocol.h"
12 namespace net {
14 namespace test {
15 class QuicFlowControllerPeer;
16 } // namespace test
18 class QuicConnection;
20 const QuicStreamId kConnectionLevelId = 0;
22 // QuicFlowController allows a QUIC stream or connection to perform flow
23 // control. The stream/connection owns a QuicFlowController which keeps track of
24 // bytes sent/received, can tell the owner if it is flow control blocked, and
25 // can send WINDOW_UPDATE or BLOCKED frames when needed.
26 class NET_EXPORT_PRIVATE QuicFlowController {
27 public:
28 QuicFlowController(QuicConnection* connection,
29 QuicStreamId id,
30 Perspective perspective,
31 QuicStreamOffset send_window_offset,
32 QuicStreamOffset receive_window_offset,
33 QuicByteCount max_receive_window);
34 ~QuicFlowController() {}
36 // Called when we see a new highest received byte offset from the peer, either
37 // via a data frame or a RST.
38 // Returns true if this call changes highest_received_byte_offset_, and false
39 // in the case where |new_offset| is <= highest_received_byte_offset_.
40 bool UpdateHighestReceivedOffset(QuicStreamOffset new_offset);
42 // Called when bytes received from the peer are consumed locally. This may
43 // trigger the sending of a WINDOW_UPDATE frame using |connection|.
44 void AddBytesConsumed(QuicByteCount bytes_consumed);
46 // Called when bytes are sent to the peer.
47 void AddBytesSent(QuicByteCount bytes_sent);
49 // Set a new send window offset.
50 // Returns true if this increases send_window_offset_ and is now blocked.
51 bool UpdateSendWindowOffset(QuicStreamOffset new_send_window_offset);
53 // Returns the current available send window.
54 QuicByteCount SendWindowSize() const;
56 // Send a BLOCKED frame if appropriate.
57 void MaybeSendBlocked();
59 // Returns true if flow control send limits have been reached.
60 bool IsBlocked() const;
62 // Returns true if flow control receive limits have been violated by the peer.
63 bool FlowControlViolation();
65 QuicByteCount bytes_consumed() const { return bytes_consumed_; }
67 QuicStreamOffset highest_received_byte_offset() const {
68 return highest_received_byte_offset_;
71 private:
72 friend class test::QuicFlowControllerPeer;
74 // Send a WINDOW_UPDATE frame if appropriate.
75 void MaybeSendWindowUpdate();
77 // The parent connection, used to send connection close on flow control
78 // violation, and WINDOW_UPDATE and BLOCKED frames when appropriate.
79 // Not owned.
80 QuicConnection* connection_;
82 // ID of stream this flow controller belongs to. This can be 0 if this is a
83 // connection level flow controller.
84 QuicStreamId id_;
86 // Tracks if this is owned by a server or a client.
87 Perspective perspective_;
89 // Track number of bytes received from the peer, which have been consumed
90 // locally.
91 QuicByteCount bytes_consumed_;
93 // The highest byte offset we have seen from the peer. This could be the
94 // highest offset in a data frame, or a final value in a RST.
95 QuicStreamOffset highest_received_byte_offset_;
97 // Tracks number of bytes sent to the peer.
98 QuicByteCount bytes_sent_;
100 // The absolute offset in the outgoing byte stream. If this offset is reached
101 // then we become flow control blocked until we receive a WINDOW_UPDATE.
102 QuicStreamOffset send_window_offset_;
104 // The absolute offset in the incoming byte stream. The peer should never send
105 // us bytes which are beyond this offset.
106 QuicStreamOffset receive_window_offset_;
108 // Largest size the receive window can grow to.
109 QuicByteCount max_receive_window_;
111 // Keep track of the last time we sent a BLOCKED frame. We should only send
112 // another when the number of bytes we have sent has changed.
113 QuicStreamOffset last_blocked_send_window_offset_;
115 DISALLOW_COPY_AND_ASSIGN(QuicFlowController);
118 } // namespace net
120 #endif // NET_QUIC_QUIC_FLOW_CONTROLLER_H_