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 #include "net/quic/quic_ack_notifier.h" 6 7 #include <set> 8 9 #include "base/logging.h" 10 #include "base/stl_util.h" 11 12 namespace net { 13 14 QuicAckNotifier::DelegateInterface::DelegateInterface() {} 15 16 QuicAckNotifier::DelegateInterface::~DelegateInterface() {} 17 18 QuicAckNotifier::QuicAckNotifier(DelegateInterface* delegate) 19 : delegate_(delegate) { 20 DCHECK(delegate_); 21 } 22 23 QuicAckNotifier::~QuicAckNotifier() {} 24 25 void QuicAckNotifier::AddSequenceNumber( 26 const QuicPacketSequenceNumber& sequence_number) { 27 sequence_numbers_.insert(sequence_number); 28 } 29 30 void QuicAckNotifier::AddSequenceNumbers( 31 const SequenceNumberSet& sequence_numbers) { 32 for (SequenceNumberSet::const_iterator it = sequence_numbers.begin(); 33 it != sequence_numbers.end(); ++it) { 34 AddSequenceNumber(*it); 35 } 36 } 37 38 bool QuicAckNotifier::OnAck(QuicPacketSequenceNumber sequence_number) { 39 DCHECK(ContainsKey(sequence_numbers_, sequence_number)); 40 sequence_numbers_.erase(sequence_number); 41 if (IsEmpty()) { 42 // We have seen all the sequence numbers we were waiting for, trigger 43 // callback notification. 44 delegate_->OnAckNotification(); 45 return true; 46 } 47 return false; 48 } 49 50 void QuicAckNotifier::UpdateSequenceNumber( 51 QuicPacketSequenceNumber old_sequence_number, 52 QuicPacketSequenceNumber new_sequence_number) { 53 sequence_numbers_.erase(old_sequence_number); 54 sequence_numbers_.insert(new_sequence_number); 55 } 56 57 }; // namespace net 58