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

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

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
« no previous file with comments | « net/tools/quic/test_tools/quic_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/tools/quic/test_tools/quic_test_utils.h" 5 #include "net/tools/quic/test_tools/quic_test_utils.h"
6 6
7 #include "net/quic/quic_connection.h" 7 #include "net/quic/quic_connection.h"
8 #include "net/quic/test_tools/quic_connection_peer.h" 8 #include "net/quic/test_tools/quic_connection_peer.h"
9 #include "net/quic/test_tools/quic_test_utils.h" 9 #include "net/quic/test_tools/quic_test_utils.h"
10 #include "net/tools/quic/quic_epoll_connection_helper.h" 10 #include "net/tools/quic/quic_epoll_connection_helper.h"
11 11
12 using base::StringPiece; 12 using base::StringPiece;
13 using net::test::MakeAckFrame; 13 using net::test::MakeAckFrame;
14 using net::test::MockHelper; 14 using net::test::MockHelper;
15 using net::test::QuicConnectionPeer; 15 using net::test::QuicConnectionPeer;
16 16
17 namespace net { 17 namespace net {
18 namespace tools { 18 namespace tools {
19 namespace test { 19 namespace test {
20 20
21 namespace {
22 class NiceMockPacketWriterFactory
23 : public QuicConnection::PacketWriterFactory {
24 public:
25 virtual ~NiceMockPacketWriterFactory() {}
26
27 virtual QuicPacketWriter* Create(
28 QuicConnection* /*connection*/) const override {
29 return new testing::NiceMock<MockPacketWriter>();
30 }
31 };
32 } // namespace
33
21 MockConnection::MockConnection(bool is_server) 34 MockConnection::MockConnection(bool is_server)
22 : QuicConnection(kTestConnectionId, 35 : QuicConnection(kTestConnectionId,
23 IPEndPoint(net::test::Loopback4(), kTestPort), 36 IPEndPoint(net::test::Loopback4(), kTestPort),
24 new testing::NiceMock<MockHelper>(), 37 new testing::NiceMock<MockHelper>(),
25 new testing::NiceMock<MockPacketWriter>(), 38 NiceMockPacketWriterFactory(),
26 true /* owns_writer */, 39 /* owns_writer= */ true,
27 is_server, QuicSupportedVersions()), 40 is_server, QuicSupportedVersions()),
28 helper_(helper()) { 41 helper_(helper()) {
29 } 42 }
30 43
31 MockConnection::MockConnection(IPEndPoint address, 44 MockConnection::MockConnection(IPEndPoint address,
32 bool is_server) 45 bool is_server)
33 : QuicConnection(kTestConnectionId, address, 46 : QuicConnection(kTestConnectionId, address,
34 new testing::NiceMock<MockHelper>(), 47 new testing::NiceMock<MockHelper>(),
35 new testing::NiceMock<MockPacketWriter>(), 48 NiceMockPacketWriterFactory(),
36 true /* owns_writer */, 49 /* owns_writer= */ true,
37 is_server, QuicSupportedVersions()), 50 is_server, QuicSupportedVersions()),
38 helper_(helper()) { 51 helper_(helper()) {
39 } 52 }
40 53
41 MockConnection::MockConnection(QuicConnectionId connection_id, 54 MockConnection::MockConnection(QuicConnectionId connection_id,
42 bool is_server) 55 bool is_server)
43 : QuicConnection(connection_id, 56 : QuicConnection(connection_id,
44 IPEndPoint(net::test::Loopback4(), kTestPort), 57 IPEndPoint(net::test::Loopback4(), kTestPort),
45 new testing::NiceMock<MockHelper>(), 58 new testing::NiceMock<MockHelper>(),
46 new testing::NiceMock<MockPacketWriter>(), 59 NiceMockPacketWriterFactory(),
47 true /* owns_writer */, 60 /* owns_writer= */ true,
48 is_server, QuicSupportedVersions()), 61 is_server, QuicSupportedVersions()),
49 helper_(helper()) { 62 helper_(helper()) {
50 } 63 }
51 64
52 MockConnection::MockConnection(bool is_server, 65 MockConnection::MockConnection(bool is_server,
53 const QuicVersionVector& supported_versions) 66 const QuicVersionVector& supported_versions)
54 : QuicConnection(kTestConnectionId, 67 : QuicConnection(kTestConnectionId,
55 IPEndPoint(net::test::Loopback4(), kTestPort), 68 IPEndPoint(net::test::Loopback4(), kTestPort),
56 new testing::NiceMock<MockHelper>(), 69 new testing::NiceMock<MockHelper>(),
57 new testing::NiceMock<MockPacketWriter>(), 70 NiceMockPacketWriterFactory(),
58 true /* owns_writer */, 71 /* owns_writer= */ true,
59 is_server, QuicSupportedVersions()), 72 is_server, QuicSupportedVersions()),
60 helper_(helper()) { 73 helper_(helper()) {
61 } 74 }
62 75
63 MockConnection::~MockConnection() { 76 MockConnection::~MockConnection() {
64 } 77 }
65 78
66 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 79 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
67 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 80 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
68 } 81 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 118
106 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() { 119 MockQuicServerSessionVisitor::~MockQuicServerSessionVisitor() {
107 } 120 }
108 121
109 MockAckNotifierDelegate::MockAckNotifierDelegate() { 122 MockAckNotifierDelegate::MockAckNotifierDelegate() {
110 } 123 }
111 124
112 MockAckNotifierDelegate::~MockAckNotifierDelegate() { 125 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
113 } 126 }
114 127
128 TestWriterFactory::TestWriterFactory() : current_writer_(NULL) {}
129 TestWriterFactory::~TestWriterFactory() {}
130
131 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer,
132 QuicConnection* connection) {
133 return new PerConnectionPacketWriter(this, writer, connection);
134 }
135
136 void TestWriterFactory::OnPacketSent(WriteResult result) {
137 if (current_writer_ != NULL) {
138 current_writer_->connection()->OnPacketSent(result);
139 current_writer_ = NULL;
140 }
141 }
142
143 void TestWriterFactory::Unregister(PerConnectionPacketWriter* writer) {
144 if (current_writer_ == writer) {
145 current_writer_ = NULL;
146 }
147 }
148
149 TestWriterFactory::PerConnectionPacketWriter::PerConnectionPacketWriter(
150 TestWriterFactory* factory,
151 QuicPacketWriter* writer,
152 QuicConnection* connection)
153 : QuicPerConnectionPacketWriter(writer, connection),
154 factory_(factory) {
155 }
156
157 TestWriterFactory::PerConnectionPacketWriter::~PerConnectionPacketWriter() {
158 factory_->Unregister(this);
159 }
160
161 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket(
162 const char* buffer,
163 size_t buf_len,
164 const IPAddressNumber& self_address,
165 const IPEndPoint& peer_address) {
166 // A DCHECK(factory_current_writer_ == NULL) would be wrong here -- this class
167 // may be used in a setting where connection()->OnPacketSent() is called in a
168 // different way, so TestWriterFactory::OnPacketSent might never be called.
169 factory_->current_writer_ = this;
170 return QuicPerConnectionPacketWriter::WritePacket(buffer,
171 buf_len,
172 self_address,
173 peer_address);
174 }
175
115 } // namespace test 176 } // namespace test
116 } // namespace tools 177 } // namespace tools
117 } // namespace net 178 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698