Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / tools / quic / quic_simple_per_connection_packet_writer.h
blob1634e6b4a75afb99e4132cf84dfbad2b4729ae68
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_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
6 #define NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_packet_writer.h"
12 namespace net {
13 namespace tools {
15 class QuicSimpleServerPacketWriter;
17 // A connection-specific packet writer that notifies its connection when its
18 // writes to the shared QuicServerPacketWriter complete.
19 // This class is necessary because multiple connections can share the same
20 // QuicServerPacketWriter, so it has no way to know which connection to notify.
21 class QuicSimplePerConnectionPacketWriter : public QuicPacketWriter {
22 public:
23 // Does not take ownership of |shared_writer| or |connection|.
24 QuicSimplePerConnectionPacketWriter(
25 QuicSimpleServerPacketWriter* shared_writer,
26 QuicConnection* connection);
27 ~QuicSimplePerConnectionPacketWriter() override;
29 QuicPacketWriter* shared_writer() const;
30 QuicConnection* connection() const { return connection_; }
32 // Default implementation of the QuicPacketWriter interface: Passes everything
33 // to |shared_writer_|.
34 WriteResult WritePacket(const char* buffer,
35 size_t buf_len,
36 const IPAddressNumber& self_address,
37 const IPEndPoint& peer_address) override;
38 bool IsWriteBlockedDataBuffered() const override;
39 bool IsWriteBlocked() const override;
40 void SetWritable() override;
41 QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override;
43 private:
44 void OnWriteComplete(WriteResult result);
46 QuicSimpleServerPacketWriter* shared_writer_; // Not owned.
47 QuicConnection* connection_; // Not owned.
49 base::WeakPtrFactory<QuicSimplePerConnectionPacketWriter> weak_factory_;
51 DISALLOW_COPY_AND_ASSIGN(QuicSimplePerConnectionPacketWriter);
54 } // namespace tools
55 } // namespace net
57 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_