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

Side by Side Diff: net/tools/quic/test_tools/quic_test_utils.h

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto ToT 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 unified diff | Download patch
OLDNEW
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 // Common utilities for Quic tests 5 // Common utilities for Quic tests
6 6
7 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 7 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 8 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "net/quic/quic_connection.h" 13 #include "net/quic/quic_connection.h"
14 #include "net/quic/quic_packet_writer.h" 14 #include "net/quic/quic_packet_writer.h"
15 #include "net/quic/quic_session.h" 15 #include "net/quic/quic_session.h"
16 #include "net/spdy/spdy_framer.h" 16 #include "net/spdy/spdy_framer.h"
17 #include "net/tools/quic/quic_dispatcher.h"
18 #include "net/tools/quic/quic_per_connection_packet_writer.h"
17 #include "net/tools/quic/quic_server_session.h" 19 #include "net/tools/quic/quic_server_session.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 21
20 namespace net { 22 namespace net {
21 23
22 class EpollServer; 24 class EpollServer;
23 class IPEndPoint; 25 class IPEndPoint;
24 26
25 namespace tools { 27 namespace tools {
26 namespace test { 28 namespace test {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int num_retransmitted_bytes, 153 int num_retransmitted_bytes,
152 QuicTime::Delta delta_largest_observed)); 154 QuicTime::Delta delta_largest_observed));
153 155
154 protected: 156 protected:
155 // Object is ref counted. 157 // Object is ref counted.
156 virtual ~MockAckNotifierDelegate(); 158 virtual ~MockAckNotifierDelegate();
157 159
158 DISALLOW_COPY_AND_ASSIGN(MockAckNotifierDelegate); 160 DISALLOW_COPY_AND_ASSIGN(MockAckNotifierDelegate);
159 }; 161 };
160 162
163 // Creates per-connection packet writers that register themselves with the
164 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
165 // be routed to the appropriate QuicConnection.
166 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory {
167 public:
168 TestWriterFactory();
169 virtual ~TestWriterFactory();
170
171 virtual QuicPacketWriter* Create(QuicPacketWriter* writer,
172 QuicConnection* connection) override;
173
174 // Calls OnPacketSent on the last QuicConnection to write through one of the
175 // packet writers created by this factory.
176 void OnPacketSent(WriteResult result);
177
178 private:
179 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter {
180 public:
181 PerConnectionPacketWriter(TestWriterFactory* factory,
182 QuicPacketWriter* writer,
183 QuicConnection* connection);
184 virtual ~PerConnectionPacketWriter();
185
186 virtual WriteResult WritePacket(
187 const char* buffer,
188 size_t buf_len,
189 const IPAddressNumber& self_address,
190 const IPEndPoint& peer_address) OVERRIDE;
191
192 private:
193 TestWriterFactory* factory_;
194 };
195
196 // If an asynchronous write is happening and |writer| gets deleted, this
197 // clears the pointer to it to prevent use-after-free.
198 void Unregister(PerConnectionPacketWriter* writer);
199
200 PerConnectionPacketWriter* current_writer_;
201 };
202
161 } // namespace test 203 } // namespace test
162 } // namespace tools 204 } // namespace tools
163 } // namespace net 205 } // namespace net
164 206
165 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 207 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_dispatcher_peer.cc ('k') | net/tools/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698