Home | History | Annotate | Download | only in quic
      1 // Copyright 2013 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.
      4 
      5 #ifndef NET_QUIC_QUIC_ACK_NOTIFIER_H_
      6 #define NET_QUIC_QUIC_ACK_NOTIFIER_H_
      7 
      8 #include "net/quic/quic_protocol.h"
      9 
     10 namespace net {
     11 
     12 // Used to register with a QuicConnection for notification once a set of packets
     13 // have all been ACKed.
     14 // The connection informs this class of newly ACKed sequence numbers, and once
     15 // we have seen ACKs for all the sequence numbers we are interested in, we
     16 // trigger a call to a provided Closure.
     17 class NET_EXPORT_PRIVATE QuicAckNotifier {
     18  public:
     19   class NET_EXPORT_PRIVATE DelegateInterface {
     20    public:
     21     DelegateInterface();
     22     virtual ~DelegateInterface();
     23     virtual void OnAckNotification() = 0;
     24   };
     25 
     26   explicit QuicAckNotifier(DelegateInterface* delegate);
     27   virtual ~QuicAckNotifier();
     28 
     29   // Register a sequence number that this AckNotifier should be interested in.
     30   void AddSequenceNumber(const QuicPacketSequenceNumber& sequence_number);
     31 
     32   // Register a set of sequence numbers that this AckNotifier should be
     33   // interested in.
     34   void AddSequenceNumbers(const SequenceNumberSet& sequence_numbers);
     35 
     36   // Called by the QuicConnection on receipt of new ACK frame, with the sequence
     37   // number referenced by the ACK frame.
     38   // Deletes the matching sequence number from the stored set of sequence
     39   // numbers. If this set is now empty, call the stored delegate's
     40   // OnAckNotification method.
     41   //
     42   // Returns true if the provided sequence_number caused the delegate to be
     43   // called, false otherwise.
     44   bool OnAck(QuicPacketSequenceNumber sequence_number);
     45 
     46   bool IsEmpty() { return sequence_numbers_.empty(); }
     47 
     48   // If a packet is retransmitted by the connection it will be sent with a
     49   // different sequence number. Updates our internal set of sequence_numbers to
     50   // track the latest number.
     51   void UpdateSequenceNumber(QuicPacketSequenceNumber old_sequence_number,
     52                             QuicPacketSequenceNumber new_sequence_number);
     53 
     54  private:
     55   // The delegate's OnAckNotification() method will be called once we have been
     56   // notified of ACKs for all the sequence numbers we are tracking.
     57   // This is not owned by OnAckNotifier and must outlive it.
     58   DelegateInterface* delegate_;
     59 
     60   // Set of sequence numbers this notifier is waiting to hear about. The
     61   // delegate will not be called until this is an empty set.
     62   SequenceNumberSet sequence_numbers_;
     63 };
     64 
     65 };  // namespace net
     66 
     67 #endif  // NET_QUIC_QUIC_ACK_NOTIFIER_H_
     68