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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 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 <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 23 matching lines...) Expand all
34 CHECK(address.AssignFromIPLiteral(ip)); 34 CHECK(address.AssignFromIPLiteral(ip));
35 return address; 35 return address;
36 } 36 }
37 37
38 // A StreamSocket which connects synchronously and successfully. 38 // A StreamSocket which connects synchronously and successfully.
39 class MockConnectClientSocket : public StreamSocket { 39 class MockConnectClientSocket : public StreamSocket {
40 public: 40 public:
41 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) 41 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log)
42 : connected_(false), 42 : connected_(false),
43 addrlist_(addrlist), 43 addrlist_(addrlist),
44 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)) {} 44 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)) {}
45 45
46 // StreamSocket implementation. 46 // StreamSocket implementation.
47 int Connect(const CompletionCallback& callback) override { 47 int Connect(const CompletionCallback& callback) override {
48 connected_ = true; 48 connected_ = true;
49 return OK; 49 return OK;
50 } 50 }
51 void Disconnect() override { connected_ = false; } 51 void Disconnect() override { connected_ = false; }
52 bool IsConnected() const override { return connected_; } 52 bool IsConnected() const override { return connected_; }
53 bool IsConnectedAndIdle() const override { return connected_; } 53 bool IsConnectedAndIdle() const override { return connected_; }
54 54
55 int GetPeerAddress(IPEndPoint* address) const override { 55 int GetPeerAddress(IPEndPoint* address) const override {
56 *address = addrlist_.front(); 56 *address = addrlist_.front();
57 return OK; 57 return OK;
58 } 58 }
59 int GetLocalAddress(IPEndPoint* address) const override { 59 int GetLocalAddress(IPEndPoint* address) const override {
60 if (!connected_) 60 if (!connected_)
61 return ERR_SOCKET_NOT_CONNECTED; 61 return ERR_SOCKET_NOT_CONNECTED;
62 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) 62 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4)
63 SetIPv4Address(address); 63 SetIPv4Address(address);
64 else 64 else
65 SetIPv6Address(address); 65 SetIPv6Address(address);
66 return OK; 66 return OK;
67 } 67 }
68 const BoundNetLog& NetLog() const override { return net_log_; } 68 const NetLogWithSource& NetLog() const override { return net_log_; }
69 69
70 void SetSubresourceSpeculation() override {} 70 void SetSubresourceSpeculation() override {}
71 void SetOmniboxSpeculation() override {} 71 void SetOmniboxSpeculation() override {}
72 bool WasEverUsed() const override { return false; } 72 bool WasEverUsed() const override { return false; }
73 void EnableTCPFastOpenIfSupported() override {} 73 void EnableTCPFastOpenIfSupported() override {}
74 bool WasNpnNegotiated() const override { return false; } 74 bool WasNpnNegotiated() const override { return false; }
75 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } 75 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; }
76 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } 76 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; }
77 void GetConnectionAttempts(ConnectionAttempts* out) const override { 77 void GetConnectionAttempts(ConnectionAttempts* out) const override {
78 out->clear(); 78 out->clear();
(...skipping 15 matching lines...) Expand all
94 int buf_len, 94 int buf_len,
95 const CompletionCallback& callback) override { 95 const CompletionCallback& callback) override {
96 return ERR_FAILED; 96 return ERR_FAILED;
97 } 97 }
98 int SetReceiveBufferSize(int32_t size) override { return OK; } 98 int SetReceiveBufferSize(int32_t size) override { return OK; }
99 int SetSendBufferSize(int32_t size) override { return OK; } 99 int SetSendBufferSize(int32_t size) override { return OK; }
100 100
101 private: 101 private:
102 bool connected_; 102 bool connected_;
103 const AddressList addrlist_; 103 const AddressList addrlist_;
104 BoundNetLog net_log_; 104 NetLogWithSource net_log_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); 106 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket);
107 }; 107 };
108 108
109 class MockFailingClientSocket : public StreamSocket { 109 class MockFailingClientSocket : public StreamSocket {
110 public: 110 public:
111 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) 111 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log)
112 : addrlist_(addrlist), 112 : addrlist_(addrlist),
113 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)) {} 113 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)) {}
114 114
115 // StreamSocket implementation. 115 // StreamSocket implementation.
116 int Connect(const CompletionCallback& callback) override { 116 int Connect(const CompletionCallback& callback) override {
117 return ERR_CONNECTION_FAILED; 117 return ERR_CONNECTION_FAILED;
118 } 118 }
119 119
120 void Disconnect() override {} 120 void Disconnect() override {}
121 121
122 bool IsConnected() const override { return false; } 122 bool IsConnected() const override { return false; }
123 bool IsConnectedAndIdle() const override { return false; } 123 bool IsConnectedAndIdle() const override { return false; }
124 int GetPeerAddress(IPEndPoint* address) const override { 124 int GetPeerAddress(IPEndPoint* address) const override {
125 return ERR_UNEXPECTED; 125 return ERR_UNEXPECTED;
126 } 126 }
127 int GetLocalAddress(IPEndPoint* address) const override { 127 int GetLocalAddress(IPEndPoint* address) const override {
128 return ERR_UNEXPECTED; 128 return ERR_UNEXPECTED;
129 } 129 }
130 const BoundNetLog& NetLog() const override { return net_log_; } 130 const NetLogWithSource& NetLog() const override { return net_log_; }
131 131
132 void SetSubresourceSpeculation() override {} 132 void SetSubresourceSpeculation() override {}
133 void SetOmniboxSpeculation() override {} 133 void SetOmniboxSpeculation() override {}
134 bool WasEverUsed() const override { return false; } 134 bool WasEverUsed() const override { return false; }
135 void EnableTCPFastOpenIfSupported() override {} 135 void EnableTCPFastOpenIfSupported() override {}
136 bool WasNpnNegotiated() const override { return false; } 136 bool WasNpnNegotiated() const override { return false; }
137 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } 137 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; }
138 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } 138 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; }
139 void GetConnectionAttempts(ConnectionAttempts* out) const override { 139 void GetConnectionAttempts(ConnectionAttempts* out) const override {
140 out->clear(); 140 out->clear();
(...skipping 17 matching lines...) Expand all
158 int Write(IOBuffer* buf, 158 int Write(IOBuffer* buf,
159 int buf_len, 159 int buf_len,
160 const CompletionCallback& callback) override { 160 const CompletionCallback& callback) override {
161 return ERR_FAILED; 161 return ERR_FAILED;
162 } 162 }
163 int SetReceiveBufferSize(int32_t size) override { return OK; } 163 int SetReceiveBufferSize(int32_t size) override { return OK; }
164 int SetSendBufferSize(int32_t size) override { return OK; } 164 int SetSendBufferSize(int32_t size) override { return OK; }
165 165
166 private: 166 private:
167 const AddressList addrlist_; 167 const AddressList addrlist_;
168 BoundNetLog net_log_; 168 NetLogWithSource net_log_;
169 169
170 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); 170 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket);
171 }; 171 };
172 172
173 class MockTriggerableClientSocket : public StreamSocket { 173 class MockTriggerableClientSocket : public StreamSocket {
174 public: 174 public:
175 // |should_connect| indicates whether the socket should successfully complete 175 // |should_connect| indicates whether the socket should successfully complete
176 // or fail. 176 // or fail.
177 MockTriggerableClientSocket(const AddressList& addrlist, 177 MockTriggerableClientSocket(const AddressList& addrlist,
178 bool should_connect, 178 bool should_connect,
179 net::NetLog* net_log) 179 net::NetLog* net_log)
180 : should_connect_(should_connect), 180 : should_connect_(should_connect),
181 is_connected_(false), 181 is_connected_(false),
182 addrlist_(addrlist), 182 addrlist_(addrlist),
183 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)), 183 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::SOCKET)),
184 weak_factory_(this) {} 184 weak_factory_(this) {}
185 185
186 // Call this method to get a closure which will trigger the connect callback 186 // Call this method to get a closure which will trigger the connect callback
187 // when called. The closure can be called even after the socket is deleted; it 187 // when called. The closure can be called even after the socket is deleted; it
188 // will safely do nothing. 188 // will safely do nothing.
189 base::Closure GetConnectCallback() { 189 base::Closure GetConnectCallback() {
190 return base::Bind(&MockTriggerableClientSocket::DoCallback, 190 return base::Bind(&MockTriggerableClientSocket::DoCallback,
191 weak_factory_.GetWeakPtr()); 191 weak_factory_.GetWeakPtr());
192 } 192 }
193 193
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 246 }
247 int GetLocalAddress(IPEndPoint* address) const override { 247 int GetLocalAddress(IPEndPoint* address) const override {
248 if (!is_connected_) 248 if (!is_connected_)
249 return ERR_SOCKET_NOT_CONNECTED; 249 return ERR_SOCKET_NOT_CONNECTED;
250 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) 250 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4)
251 SetIPv4Address(address); 251 SetIPv4Address(address);
252 else 252 else
253 SetIPv6Address(address); 253 SetIPv6Address(address);
254 return OK; 254 return OK;
255 } 255 }
256 const BoundNetLog& NetLog() const override { return net_log_; } 256 const NetLogWithSource& NetLog() const override { return net_log_; }
257 257
258 void SetSubresourceSpeculation() override {} 258 void SetSubresourceSpeculation() override {}
259 void SetOmniboxSpeculation() override {} 259 void SetOmniboxSpeculation() override {}
260 bool WasEverUsed() const override { return false; } 260 bool WasEverUsed() const override { return false; }
261 void EnableTCPFastOpenIfSupported() override {} 261 void EnableTCPFastOpenIfSupported() override {}
262 bool WasNpnNegotiated() const override { return false; } 262 bool WasNpnNegotiated() const override { return false; }
263 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } 263 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; }
264 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } 264 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; }
265 void GetConnectionAttempts(ConnectionAttempts* out) const override { 265 void GetConnectionAttempts(ConnectionAttempts* out) const override {
266 *out = connection_attempts_; 266 *out = connection_attempts_;
(...skipping 25 matching lines...) Expand all
292 292
293 private: 293 private:
294 void DoCallback() { 294 void DoCallback() {
295 is_connected_ = should_connect_; 295 is_connected_ = should_connect_;
296 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); 296 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED);
297 } 297 }
298 298
299 bool should_connect_; 299 bool should_connect_;
300 bool is_connected_; 300 bool is_connected_;
301 const AddressList addrlist_; 301 const AddressList addrlist_;
302 BoundNetLog net_log_; 302 NetLogWithSource net_log_;
303 CompletionCallback callback_; 303 CompletionCallback callback_;
304 ConnectionAttempts connection_attempts_; 304 ConnectionAttempts connection_attempts_;
305 305
306 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; 306 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_;
307 307
308 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); 308 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket);
309 }; 309 };
310 310
311 } // namespace 311 } // namespace
312 312
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 run_loop_quit_closure_ = run_loop.QuitClosure(); 457 run_loop_quit_closure_ = run_loop.QuitClosure();
458 run_loop.Run(); 458 run_loop.Run();
459 run_loop_quit_closure_.Reset(); 459 run_loop_quit_closure_.Reset();
460 } 460 }
461 base::Closure trigger = triggerable_sockets_.front(); 461 base::Closure trigger = triggerable_sockets_.front();
462 triggerable_sockets_.pop(); 462 triggerable_sockets_.pop();
463 return trigger; 463 return trigger;
464 } 464 }
465 465
466 } // namespace net 466 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698