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

Side by Side Diff: net/socket/transport_client_socket_pool_test_util.cc

Issue 451383002: Plumbing for TCP FastOpen for SSL sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing linker error for Windows. Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 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 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/socket/transport_client_socket_pool_test_util.h" 5 #include "net/socket/transport_client_socket_pool_test_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 16 matching lines...) Expand all
27 CHECK(ParseIPLiteralToNumber(ip, &number)); 27 CHECK(ParseIPLiteralToNumber(ip, &number));
28 return number; 28 return number;
29 } 29 }
30 30
31 // A StreamSocket which connects synchronously and successfully. 31 // A StreamSocket which connects synchronously and successfully.
32 class MockConnectClientSocket : public StreamSocket { 32 class MockConnectClientSocket : public StreamSocket {
33 public: 33 public:
34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) 34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log)
35 : connected_(false), 35 : connected_(false),
36 addrlist_(addrlist), 36 addrlist_(addrlist),
37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} 37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
38 use_tcp_fastopen_(false) {}
38 39
39 // StreamSocket implementation. 40 // StreamSocket implementation.
40 virtual int Connect(const CompletionCallback& callback) OVERRIDE { 41 virtual int Connect(const CompletionCallback& callback) OVERRIDE {
41 connected_ = true; 42 connected_ = true;
42 return OK; 43 return OK;
43 } 44 }
44 virtual void Disconnect() OVERRIDE { connected_ = false; } 45 virtual void Disconnect() OVERRIDE { connected_ = false; }
45 virtual bool IsConnected() const OVERRIDE { return connected_; } 46 virtual bool IsConnected() const OVERRIDE { return connected_; }
46 virtual bool IsConnectedAndIdle() const OVERRIDE { return connected_; } 47 virtual bool IsConnectedAndIdle() const OVERRIDE { return connected_; }
47 48
48 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { 49 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE {
49 *address = addrlist_.front(); 50 *address = addrlist_.front();
50 return OK; 51 return OK;
51 } 52 }
52 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { 53 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE {
53 if (!connected_) 54 if (!connected_)
54 return ERR_SOCKET_NOT_CONNECTED; 55 return ERR_SOCKET_NOT_CONNECTED;
55 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) 56 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4)
56 SetIPv4Address(address); 57 SetIPv4Address(address);
57 else 58 else
58 SetIPv6Address(address); 59 SetIPv6Address(address);
59 return OK; 60 return OK;
60 } 61 }
61 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 62 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
62 63
63 virtual void SetSubresourceSpeculation() OVERRIDE {} 64 virtual void SetSubresourceSpeculation() OVERRIDE {}
64 virtual void SetOmniboxSpeculation() OVERRIDE {} 65 virtual void SetOmniboxSpeculation() OVERRIDE {}
65 virtual bool WasEverUsed() const OVERRIDE { return false; } 66 virtual bool WasEverUsed() const OVERRIDE { return false; }
66 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 67 virtual void EnableTCPFastOpenIfSupported() OVERRIDE {
68 use_tcp_fastopen_ = true;
69 }
70 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
67 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 71 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
68 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 72 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
69 return kProtoUnknown; 73 return kProtoUnknown;
70 } 74 }
71 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 75 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
72 76
73 // Socket implementation. 77 // Socket implementation.
74 virtual int Read(IOBuffer* buf, 78 virtual int Read(IOBuffer* buf,
75 int buf_len, 79 int buf_len,
76 const CompletionCallback& callback) OVERRIDE { 80 const CompletionCallback& callback) OVERRIDE {
77 return ERR_FAILED; 81 return ERR_FAILED;
78 } 82 }
79 virtual int Write(IOBuffer* buf, 83 virtual int Write(IOBuffer* buf,
80 int buf_len, 84 int buf_len,
81 const CompletionCallback& callback) OVERRIDE { 85 const CompletionCallback& callback) OVERRIDE {
82 return ERR_FAILED; 86 return ERR_FAILED;
83 } 87 }
84 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } 88 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; }
85 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } 89 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; }
86 90
87 private: 91 private:
88 bool connected_; 92 bool connected_;
89 const AddressList addrlist_; 93 const AddressList addrlist_;
90 BoundNetLog net_log_; 94 BoundNetLog net_log_;
95 bool use_tcp_fastopen_;
91 96
92 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); 97 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket);
93 }; 98 };
94 99
95 class MockFailingClientSocket : public StreamSocket { 100 class MockFailingClientSocket : public StreamSocket {
96 public: 101 public:
97 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) 102 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log)
98 : addrlist_(addrlist), 103 : addrlist_(addrlist),
99 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} 104 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
105 use_tcp_fastopen_(false) {}
100 106
101 // StreamSocket implementation. 107 // StreamSocket implementation.
102 virtual int Connect(const CompletionCallback& callback) OVERRIDE { 108 virtual int Connect(const CompletionCallback& callback) OVERRIDE {
103 return ERR_CONNECTION_FAILED; 109 return ERR_CONNECTION_FAILED;
104 } 110 }
105 111
106 virtual void Disconnect() OVERRIDE {} 112 virtual void Disconnect() OVERRIDE {}
107 113
108 virtual bool IsConnected() const OVERRIDE { return false; } 114 virtual bool IsConnected() const OVERRIDE { return false; }
109 virtual bool IsConnectedAndIdle() const OVERRIDE { return false; } 115 virtual bool IsConnectedAndIdle() const OVERRIDE { return false; }
110 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { 116 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE {
111 return ERR_UNEXPECTED; 117 return ERR_UNEXPECTED;
112 } 118 }
113 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { 119 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE {
114 return ERR_UNEXPECTED; 120 return ERR_UNEXPECTED;
115 } 121 }
116 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 122 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
117 123
118 virtual void SetSubresourceSpeculation() OVERRIDE {} 124 virtual void SetSubresourceSpeculation() OVERRIDE {}
119 virtual void SetOmniboxSpeculation() OVERRIDE {} 125 virtual void SetOmniboxSpeculation() OVERRIDE {}
120 virtual bool WasEverUsed() const OVERRIDE { return false; } 126 virtual bool WasEverUsed() const OVERRIDE { return false; }
121 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 127 virtual void EnableTCPFastOpenIfSupported() OVERRIDE {
128 use_tcp_fastopen_ = true;
129 }
130 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
122 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 131 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
123 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 132 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
124 return kProtoUnknown; 133 return kProtoUnknown;
125 } 134 }
126 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 135 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
127 136
128 // Socket implementation. 137 // Socket implementation.
129 virtual int Read(IOBuffer* buf, 138 virtual int Read(IOBuffer* buf,
130 int buf_len, 139 int buf_len,
131 const CompletionCallback& callback) OVERRIDE { 140 const CompletionCallback& callback) OVERRIDE {
132 return ERR_FAILED; 141 return ERR_FAILED;
133 } 142 }
134 143
135 virtual int Write(IOBuffer* buf, 144 virtual int Write(IOBuffer* buf,
136 int buf_len, 145 int buf_len,
137 const CompletionCallback& callback) OVERRIDE { 146 const CompletionCallback& callback) OVERRIDE {
138 return ERR_FAILED; 147 return ERR_FAILED;
139 } 148 }
140 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } 149 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; }
141 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } 150 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; }
142 151
143 private: 152 private:
144 const AddressList addrlist_; 153 const AddressList addrlist_;
145 BoundNetLog net_log_; 154 BoundNetLog net_log_;
155 bool use_tcp_fastopen_;
146 156
147 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); 157 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket);
148 }; 158 };
149 159
150 class MockTriggerableClientSocket : public StreamSocket { 160 class MockTriggerableClientSocket : public StreamSocket {
151 public: 161 public:
152 // |should_connect| indicates whether the socket should successfully complete 162 // |should_connect| indicates whether the socket should successfully complete
153 // or fail. 163 // or fail.
154 MockTriggerableClientSocket(const AddressList& addrlist, 164 MockTriggerableClientSocket(const AddressList& addrlist,
155 bool should_connect, 165 bool should_connect,
156 net::NetLog* net_log) 166 net::NetLog* net_log)
157 : should_connect_(should_connect), 167 : should_connect_(should_connect),
158 is_connected_(false), 168 is_connected_(false),
159 addrlist_(addrlist), 169 addrlist_(addrlist),
160 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), 170 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
171 use_tcp_fastopen_(false),
161 weak_factory_(this) {} 172 weak_factory_(this) {}
162 173
163 // Call this method to get a closure which will trigger the connect callback 174 // Call this method to get a closure which will trigger the connect callback
164 // when called. The closure can be called even after the socket is deleted; it 175 // when called. The closure can be called even after the socket is deleted; it
165 // will safely do nothing. 176 // will safely do nothing.
166 base::Closure GetConnectCallback() { 177 base::Closure GetConnectCallback() {
167 return base::Bind(&MockTriggerableClientSocket::DoCallback, 178 return base::Bind(&MockTriggerableClientSocket::DoCallback,
168 weak_factory_.GetWeakPtr()); 179 weak_factory_.GetWeakPtr());
169 } 180 }
170 181
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SetIPv4Address(address); 232 SetIPv4Address(address);
222 else 233 else
223 SetIPv6Address(address); 234 SetIPv6Address(address);
224 return OK; 235 return OK;
225 } 236 }
226 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } 237 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; }
227 238
228 virtual void SetSubresourceSpeculation() OVERRIDE {} 239 virtual void SetSubresourceSpeculation() OVERRIDE {}
229 virtual void SetOmniboxSpeculation() OVERRIDE {} 240 virtual void SetOmniboxSpeculation() OVERRIDE {}
230 virtual bool WasEverUsed() const OVERRIDE { return false; } 241 virtual bool WasEverUsed() const OVERRIDE { return false; }
231 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } 242 virtual void EnableTCPFastOpenIfSupported() OVERRIDE {
243 use_tcp_fastopen_ = true;
244 }
245 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; }
232 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } 246 virtual bool WasNpnNegotiated() const OVERRIDE { return false; }
233 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { 247 virtual NextProto GetNegotiatedProtocol() const OVERRIDE {
234 return kProtoUnknown; 248 return kProtoUnknown;
235 } 249 }
236 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } 250 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; }
237 251
238 // Socket implementation. 252 // Socket implementation.
239 virtual int Read(IOBuffer* buf, 253 virtual int Read(IOBuffer* buf,
240 int buf_len, 254 int buf_len,
241 const CompletionCallback& callback) OVERRIDE { 255 const CompletionCallback& callback) OVERRIDE {
(...skipping 12 matching lines...) Expand all
254 void DoCallback() { 268 void DoCallback() {
255 is_connected_ = should_connect_; 269 is_connected_ = should_connect_;
256 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); 270 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED);
257 } 271 }
258 272
259 bool should_connect_; 273 bool should_connect_;
260 bool is_connected_; 274 bool is_connected_;
261 const AddressList addrlist_; 275 const AddressList addrlist_;
262 BoundNetLog net_log_; 276 BoundNetLog net_log_;
263 CompletionCallback callback_; 277 CompletionCallback callback_;
278 bool use_tcp_fastopen_;
264 279
265 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; 280 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_;
266 281
267 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); 282 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket);
268 }; 283 };
269 284
270 } // namespace 285 } // namespace
271 286
272 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { 287 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) {
273 LoadTimingInfo load_timing_info; 288 LoadTimingInfo load_timing_info;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 run_loop_quit_closure_ = run_loop.QuitClosure(); 427 run_loop_quit_closure_ = run_loop.QuitClosure();
413 run_loop.Run(); 428 run_loop.Run();
414 run_loop_quit_closure_.Reset(); 429 run_loop_quit_closure_.Reset();
415 } 430 }
416 base::Closure trigger = triggerable_sockets_.front(); 431 base::Closure trigger = triggerable_sockets_.front();
417 triggerable_sockets_.pop(); 432 triggerable_sockets_.pop();
418 return trigger; 433 return trigger;
419 } 434 }
420 435
421 } // namespace net 436 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/transport_client_socket_pool.cc ('k') | net/socket/transport_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698