Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: net/quic/test_tools/quic_test_utils.h

Issue 468373002: Patch set 2 of Daniel Ziegler's CL Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Suggested changes. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/test_tools/quic_test_utils.h
diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h
index 350bc379151521513d1774da1d342ac24897d796..94367b8f4668fd141ea72886e136cbcd5652fbb6 100644
--- a/net/quic/test_tools/quic_test_utils.h
+++ b/net/quic/test_tools/quic_test_utils.h
@@ -16,7 +16,9 @@
#include "net/quic/quic_ack_notifier.h"
#include "net/quic/quic_client_session_base.h"
#include "net/quic/quic_connection.h"
+#include "net/quic/quic_dispatcher.h"
#include "net/quic/quic_framer.h"
+#include "net/quic/quic_per_connection_packet_writer.h"
#include "net/quic/quic_sent_packet_manager.h"
#include "net/quic/quic_session.h"
#include "net/quic/test_tools/mock_clock.h"
@@ -542,6 +544,46 @@ class MockNetworkChangeVisitor :
DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor);
};
+// Creates per-connection packet writers that register themselves with the
+// TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
+// be routed to the appropriate QuicConnection.
+class TestWriterFactory : public QuicDispatcher::PacketWriterFactory {
+ public:
+ TestWriterFactory();
+ virtual ~TestWriterFactory();
+
+ virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer,
+ QuicConnection* connection) OVERRIDE;
+
+ // Calls OnPacketSent on the last QuicConnection to write through one of the
+ // packet writers created by this factory.
+ void OnPacketSent(WriteResult result);
+
+ private:
+ class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter {
+ public:
+ PerConnectionPacketWriter(TestWriterFactory* factory,
+ QuicServerPacketWriter* writer,
+ QuicConnection* connection);
+ virtual ~PerConnectionPacketWriter();
+
+ virtual WriteResult WritePacket(
+ const char* buffer,
+ size_t buf_len,
+ const IPAddressNumber& self_address,
+ const IPEndPoint& peer_address) OVERRIDE;
+
+ private:
+ TestWriterFactory* factory_;
+ };
+
+ // If an asynchronous write is happening and |writer| gets deleted, this
+ // clears the pointer to it to prevent use-after-free.
+ void Unregister(PerConnectionPacketWriter* writer);
+
+ PerConnectionPacketWriter* current_writer_;
+};
+
} // namespace test
} // namespace net
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698