OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Responsible for generating packets on behalf of a QuicConnection. | 5 // Responsible for generating packets on behalf of a QuicConnection. |
6 // Packets are serialized just-in-time. Control frames are queued. | 6 // Packets are serialized just-in-time. Control frames are queued. |
7 // Ack and Feedback frames will be requested from the Connection | 7 // Ack and Feedback frames will be requested from the Connection |
8 // just-in-time. When a packet needs to be sent, the Generator | 8 // just-in-time. When a packet needs to be sent, the Generator |
9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() | 9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() |
10 // | 10 // |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 public: | 63 public: |
64 virtual ~DelegateInterface() {} | 64 virtual ~DelegateInterface() {} |
65 virtual bool CanWrite(Retransmission retransmission, | 65 virtual bool CanWrite(Retransmission retransmission, |
66 HasRetransmittableData retransmittable) = 0; | 66 HasRetransmittableData retransmittable) = 0; |
67 virtual QuicAckFrame* CreateAckFrame() = 0; | 67 virtual QuicAckFrame* CreateAckFrame() = 0; |
68 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; | 68 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; |
69 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. | 69 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. |
70 virtual bool OnSerializedPacket(const SerializedPacket& packet) = 0; | 70 virtual bool OnSerializedPacket(const SerializedPacket& packet) = 0; |
71 }; | 71 }; |
72 | 72 |
| 73 // Interface which gets callbacks from the QuicPacketGenerator at interesting |
| 74 // points. Implementations must not mutate the state of the generator |
| 75 // as a result of these callbacks. |
| 76 class NET_EXPORT_PRIVATE DebugDelegateInterface { |
| 77 public: |
| 78 virtual ~DebugDelegateInterface() {} |
| 79 |
| 80 // Called when a frame has been added to the current packet. |
| 81 virtual void OnFrameAddedToPacket(const QuicFrame& frame) = 0; |
| 82 }; |
| 83 |
73 QuicPacketGenerator(DelegateInterface* delegate, | 84 QuicPacketGenerator(DelegateInterface* delegate, |
| 85 DebugDelegateInterface* debug_delegate, |
74 QuicPacketCreator* creator); | 86 QuicPacketCreator* creator); |
75 | 87 |
76 virtual ~QuicPacketGenerator(); | 88 virtual ~QuicPacketGenerator(); |
77 | 89 |
78 void SetShouldSendAck(bool also_send_feedback); | 90 void SetShouldSendAck(bool also_send_feedback); |
79 void AddControlFrame(const QuicFrame& frame); | 91 void AddControlFrame(const QuicFrame& frame); |
80 QuicConsumedData ConsumeData(QuicStreamId id, | 92 QuicConsumedData ConsumeData(QuicStreamId id, |
81 base::StringPiece data, | 93 base::StringPiece data, |
82 QuicStreamOffset offset, | 94 QuicStreamOffset offset, |
83 bool fin); | 95 bool fin); |
84 | 96 |
85 // Disables flushing. | 97 // Disables flushing. |
86 void StartBatchOperations(); | 98 void StartBatchOperations(); |
87 // Enables flushing and flushes queued data. | 99 // Enables flushing and flushes queued data. |
88 void FinishBatchOperations(); | 100 void FinishBatchOperations(); |
89 | 101 |
90 bool HasQueuedFrames() const; | 102 bool HasQueuedFrames() const; |
91 | 103 |
| 104 void set_debug_delegate(DebugDelegateInterface* debug_delegate) { |
| 105 debug_delegate_ = debug_delegate; |
| 106 } |
| 107 |
92 private: | 108 private: |
93 void SendQueuedFrames(); | 109 void SendQueuedFrames(); |
94 | 110 |
95 bool HasPendingFrames() const; | 111 bool HasPendingFrames() const; |
96 bool AddNextPendingFrame(); | 112 bool AddNextPendingFrame(); |
| 113 |
| 114 bool AddFrame(const QuicFrame& frame); |
97 void SerializeAndSendPacket(); | 115 void SerializeAndSendPacket(); |
98 | 116 |
99 DelegateInterface* delegate_; | 117 DelegateInterface* delegate_; |
| 118 DebugDelegateInterface* debug_delegate_; |
100 | 119 |
101 QuicPacketCreator* packet_creator_; | 120 QuicPacketCreator* packet_creator_; |
102 QuicFrames queued_control_frames_; | 121 QuicFrames queued_control_frames_; |
103 bool should_flush_; | 122 bool should_flush_; |
104 bool should_send_ack_; | 123 bool should_send_ack_; |
105 scoped_ptr<QuicAckFrame> pending_ack_frame_; | 124 scoped_ptr<QuicAckFrame> pending_ack_frame_; |
106 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; | 125 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; |
107 bool should_send_feedback_; | 126 bool should_send_feedback_; |
108 | 127 |
109 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); | 128 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); |
110 }; | 129 }; |
111 | 130 |
112 } // namespace net | 131 } // namespace net |
113 | 132 |
114 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 133 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
OLD | NEW |