| OLD | NEW |
| 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/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 was_used_to_convey_data_(false) { | 121 was_used_to_convey_data_(false) { |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Sets whether the socket has unread data. If true, the next call to Read() | 124 // Sets whether the socket has unread data. If true, the next call to Read() |
| 125 // will return 1 byte and IsConnectedAndIdle() will return false. | 125 // will return 1 byte and IsConnectedAndIdle() will return false. |
| 126 void set_has_unread_data(bool has_unread_data) { | 126 void set_has_unread_data(bool has_unread_data) { |
| 127 has_unread_data_ = has_unread_data; | 127 has_unread_data_ = has_unread_data; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Socket implementation. | 130 // Socket implementation. |
| 131 virtual int Read( | 131 int Read(IOBuffer* /* buf */, |
| 132 IOBuffer* /* buf */, int len, | 132 int len, |
| 133 const CompletionCallback& /* callback */) override { | 133 const CompletionCallback& /* callback */) override { |
| 134 if (has_unread_data_ && len > 0) { | 134 if (has_unread_data_ && len > 0) { |
| 135 has_unread_data_ = false; | 135 has_unread_data_ = false; |
| 136 was_used_to_convey_data_ = true; | 136 was_used_to_convey_data_ = true; |
| 137 return 1; | 137 return 1; |
| 138 } | 138 } |
| 139 return ERR_UNEXPECTED; | 139 return ERR_UNEXPECTED; |
| 140 } | 140 } |
| 141 | 141 |
| 142 virtual int Write( | 142 int Write(IOBuffer* /* buf */, |
| 143 IOBuffer* /* buf */, int len, | 143 int len, |
| 144 const CompletionCallback& /* callback */) override { | 144 const CompletionCallback& /* callback */) override { |
| 145 was_used_to_convey_data_ = true; | 145 was_used_to_convey_data_ = true; |
| 146 return len; | 146 return len; |
| 147 } | 147 } |
| 148 virtual int SetReceiveBufferSize(int32 size) override { return OK; } | 148 int SetReceiveBufferSize(int32 size) override { return OK; } |
| 149 virtual int SetSendBufferSize(int32 size) override { return OK; } | 149 int SetSendBufferSize(int32 size) override { return OK; } |
| 150 | 150 |
| 151 // StreamSocket implementation. | 151 // StreamSocket implementation. |
| 152 virtual int Connect(const CompletionCallback& callback) override { | 152 int Connect(const CompletionCallback& callback) override { |
| 153 connected_ = true; | 153 connected_ = true; |
| 154 return OK; | 154 return OK; |
| 155 } | 155 } |
| 156 | 156 |
| 157 virtual void Disconnect() override { connected_ = false; } | 157 void Disconnect() override { connected_ = false; } |
| 158 virtual bool IsConnected() const override { return connected_; } | 158 bool IsConnected() const override { return connected_; } |
| 159 virtual bool IsConnectedAndIdle() const override { | 159 bool IsConnectedAndIdle() const override { |
| 160 return connected_ && !has_unread_data_; | 160 return connected_ && !has_unread_data_; |
| 161 } | 161 } |
| 162 | 162 |
| 163 virtual int GetPeerAddress(IPEndPoint* /* address */) const override { | 163 int GetPeerAddress(IPEndPoint* /* address */) const override { |
| 164 return ERR_UNEXPECTED; | 164 return ERR_UNEXPECTED; |
| 165 } | 165 } |
| 166 | 166 |
| 167 virtual int GetLocalAddress(IPEndPoint* /* address */) const override { | 167 int GetLocalAddress(IPEndPoint* /* address */) const override { |
| 168 return ERR_UNEXPECTED; | 168 return ERR_UNEXPECTED; |
| 169 } | 169 } |
| 170 | 170 |
| 171 virtual const BoundNetLog& NetLog() const override { | 171 const BoundNetLog& NetLog() const override { return net_log_; } |
| 172 return net_log_; | |
| 173 } | |
| 174 | 172 |
| 175 virtual void SetSubresourceSpeculation() override {} | 173 void SetSubresourceSpeculation() override {} |
| 176 virtual void SetOmniboxSpeculation() override {} | 174 void SetOmniboxSpeculation() override {} |
| 177 virtual bool WasEverUsed() const override { | 175 bool WasEverUsed() const override { return was_used_to_convey_data_; } |
| 178 return was_used_to_convey_data_; | 176 bool UsingTCPFastOpen() const override { return false; } |
| 179 } | 177 bool WasNpnNegotiated() const override { return false; } |
| 180 virtual bool UsingTCPFastOpen() const override { return false; } | 178 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 181 virtual bool WasNpnNegotiated() const override { | 179 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 182 return false; | |
| 183 } | |
| 184 virtual NextProto GetNegotiatedProtocol() const override { | |
| 185 return kProtoUnknown; | |
| 186 } | |
| 187 virtual bool GetSSLInfo(SSLInfo* ssl_info) override { | |
| 188 return false; | |
| 189 } | |
| 190 | 180 |
| 191 private: | 181 private: |
| 192 bool connected_; | 182 bool connected_; |
| 193 bool has_unread_data_; | 183 bool has_unread_data_; |
| 194 BoundNetLog net_log_; | 184 BoundNetLog net_log_; |
| 195 bool was_used_to_convey_data_; | 185 bool was_used_to_convey_data_; |
| 196 | 186 |
| 197 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); | 187 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); |
| 198 }; | 188 }; |
| 199 | 189 |
| 200 class TestConnectJob; | 190 class TestConnectJob; |
| 201 | 191 |
| 202 class MockClientSocketFactory : public ClientSocketFactory { | 192 class MockClientSocketFactory : public ClientSocketFactory { |
| 203 public: | 193 public: |
| 204 MockClientSocketFactory() : allocation_count_(0) {} | 194 MockClientSocketFactory() : allocation_count_(0) {} |
| 205 | 195 |
| 206 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 196 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 207 DatagramSocket::BindType bind_type, | 197 DatagramSocket::BindType bind_type, |
| 208 const RandIntCallback& rand_int_cb, | 198 const RandIntCallback& rand_int_cb, |
| 209 NetLog* net_log, | 199 NetLog* net_log, |
| 210 const NetLog::Source& source) override { | 200 const NetLog::Source& source) override { |
| 211 NOTREACHED(); | 201 NOTREACHED(); |
| 212 return scoped_ptr<DatagramClientSocket>(); | 202 return scoped_ptr<DatagramClientSocket>(); |
| 213 } | 203 } |
| 214 | 204 |
| 215 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 205 scoped_ptr<StreamSocket> CreateTransportClientSocket( |
| 216 const AddressList& addresses, | 206 const AddressList& addresses, |
| 217 NetLog* /* net_log */, | 207 NetLog* /* net_log */, |
| 218 const NetLog::Source& /*source*/) override { | 208 const NetLog::Source& /*source*/) override { |
| 219 allocation_count_++; | 209 allocation_count_++; |
| 220 return scoped_ptr<StreamSocket>(); | 210 return scoped_ptr<StreamSocket>(); |
| 221 } | 211 } |
| 222 | 212 |
| 223 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 213 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 224 scoped_ptr<ClientSocketHandle> transport_socket, | 214 scoped_ptr<ClientSocketHandle> transport_socket, |
| 225 const HostPortPair& host_and_port, | 215 const HostPortPair& host_and_port, |
| 226 const SSLConfig& ssl_config, | 216 const SSLConfig& ssl_config, |
| 227 const SSLClientSocketContext& context) override { | 217 const SSLClientSocketContext& context) override { |
| 228 NOTIMPLEMENTED(); | 218 NOTIMPLEMENTED(); |
| 229 return scoped_ptr<SSLClientSocket>(); | 219 return scoped_ptr<SSLClientSocket>(); |
| 230 } | 220 } |
| 231 | 221 |
| 232 virtual void ClearSSLSessionCache() override { | 222 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); } |
| 233 NOTIMPLEMENTED(); | |
| 234 } | |
| 235 | 223 |
| 236 void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); } | 224 void WaitForSignal(TestConnectJob* job) { waiting_jobs_.push_back(job); } |
| 237 | 225 |
| 238 void SignalJobs(); | 226 void SignalJobs(); |
| 239 | 227 |
| 240 void SignalJob(size_t job); | 228 void SignalJob(size_t job); |
| 241 | 229 |
| 242 void SetJobLoadState(size_t job, LoadState load_state); | 230 void SetJobLoadState(size_t job, LoadState load_state); |
| 243 | 231 |
| 244 int allocation_count() const { return allocation_count_; } | 232 int allocation_count() const { return allocation_count_; } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 272 } |
| 285 | 273 |
| 286 void Signal() { | 274 void Signal() { |
| 287 DoConnect(waiting_success_, true /* async */, false /* recoverable */); | 275 DoConnect(waiting_success_, true /* async */, false /* recoverable */); |
| 288 } | 276 } |
| 289 | 277 |
| 290 void set_load_state(LoadState load_state) { load_state_ = load_state; } | 278 void set_load_state(LoadState load_state) { load_state_ = load_state; } |
| 291 | 279 |
| 292 // From ConnectJob: | 280 // From ConnectJob: |
| 293 | 281 |
| 294 virtual LoadState GetLoadState() const override { return load_state_; } | 282 LoadState GetLoadState() const override { return load_state_; } |
| 295 | 283 |
| 296 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) override { | 284 void GetAdditionalErrorState(ClientSocketHandle* handle) override { |
| 297 if (store_additional_error_state_) { | 285 if (store_additional_error_state_) { |
| 298 // Set all of the additional error state fields in some way. | 286 // Set all of the additional error state fields in some way. |
| 299 handle->set_is_ssl_error(true); | 287 handle->set_is_ssl_error(true); |
| 300 HttpResponseInfo info; | 288 HttpResponseInfo info; |
| 301 info.headers = new HttpResponseHeaders(std::string()); | 289 info.headers = new HttpResponseHeaders(std::string()); |
| 302 handle->set_ssl_error_response_info(info); | 290 handle->set_ssl_error_response_info(info); |
| 303 } | 291 } |
| 304 } | 292 } |
| 305 | 293 |
| 306 private: | 294 private: |
| 307 // From ConnectJob: | 295 // From ConnectJob: |
| 308 | 296 |
| 309 virtual int ConnectInternal() override { | 297 int ConnectInternal() override { |
| 310 AddressList ignored; | 298 AddressList ignored; |
| 311 client_socket_factory_->CreateTransportClientSocket( | 299 client_socket_factory_->CreateTransportClientSocket( |
| 312 ignored, NULL, net::NetLog::Source()); | 300 ignored, NULL, net::NetLog::Source()); |
| 313 SetSocket( | 301 SetSocket( |
| 314 scoped_ptr<StreamSocket>(new MockClientSocket(net_log().net_log()))); | 302 scoped_ptr<StreamSocket>(new MockClientSocket(net_log().net_log()))); |
| 315 switch (job_type_) { | 303 switch (job_type_) { |
| 316 case kMockJob: | 304 case kMockJob: |
| 317 return DoConnect(true /* successful */, false /* sync */, | 305 return DoConnect(true /* successful */, false /* sync */, |
| 318 false /* recoverable */); | 306 false /* recoverable */); |
| 319 case kMockFailingJob: | 307 case kMockFailingJob: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 : public TestClientSocketPoolBase::ConnectJobFactory { | 420 : public TestClientSocketPoolBase::ConnectJobFactory { |
| 433 public: | 421 public: |
| 434 TestConnectJobFactory(MockClientSocketFactory* client_socket_factory, | 422 TestConnectJobFactory(MockClientSocketFactory* client_socket_factory, |
| 435 NetLog* net_log) | 423 NetLog* net_log) |
| 436 : job_type_(TestConnectJob::kMockJob), | 424 : job_type_(TestConnectJob::kMockJob), |
| 437 job_types_(NULL), | 425 job_types_(NULL), |
| 438 client_socket_factory_(client_socket_factory), | 426 client_socket_factory_(client_socket_factory), |
| 439 net_log_(net_log) { | 427 net_log_(net_log) { |
| 440 } | 428 } |
| 441 | 429 |
| 442 virtual ~TestConnectJobFactory() {} | 430 ~TestConnectJobFactory() override {} |
| 443 | 431 |
| 444 void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } | 432 void set_job_type(TestConnectJob::JobType job_type) { job_type_ = job_type; } |
| 445 | 433 |
| 446 void set_job_types(std::list<TestConnectJob::JobType>* job_types) { | 434 void set_job_types(std::list<TestConnectJob::JobType>* job_types) { |
| 447 job_types_ = job_types; | 435 job_types_ = job_types; |
| 448 CHECK(!job_types_->empty()); | 436 CHECK(!job_types_->empty()); |
| 449 } | 437 } |
| 450 | 438 |
| 451 void set_timeout_duration(base::TimeDelta timeout_duration) { | 439 void set_timeout_duration(base::TimeDelta timeout_duration) { |
| 452 timeout_duration_ = timeout_duration; | 440 timeout_duration_ = timeout_duration; |
| 453 } | 441 } |
| 454 | 442 |
| 455 // ConnectJobFactory implementation. | 443 // ConnectJobFactory implementation. |
| 456 | 444 |
| 457 virtual scoped_ptr<ConnectJob> NewConnectJob( | 445 scoped_ptr<ConnectJob> NewConnectJob( |
| 458 const std::string& group_name, | 446 const std::string& group_name, |
| 459 const TestClientSocketPoolBase::Request& request, | 447 const TestClientSocketPoolBase::Request& request, |
| 460 ConnectJob::Delegate* delegate) const override { | 448 ConnectJob::Delegate* delegate) const override { |
| 461 EXPECT_TRUE(!job_types_ || !job_types_->empty()); | 449 EXPECT_TRUE(!job_types_ || !job_types_->empty()); |
| 462 TestConnectJob::JobType job_type = job_type_; | 450 TestConnectJob::JobType job_type = job_type_; |
| 463 if (job_types_ && !job_types_->empty()) { | 451 if (job_types_ && !job_types_->empty()) { |
| 464 job_type = job_types_->front(); | 452 job_type = job_types_->front(); |
| 465 job_types_->pop_front(); | 453 job_types_->pop_front(); |
| 466 } | 454 } |
| 467 return scoped_ptr<ConnectJob>(new TestConnectJob(job_type, | 455 return scoped_ptr<ConnectJob>(new TestConnectJob(job_type, |
| 468 group_name, | 456 group_name, |
| 469 request, | 457 request, |
| 470 timeout_duration_, | 458 timeout_duration_, |
| 471 delegate, | 459 delegate, |
| 472 client_socket_factory_, | 460 client_socket_factory_, |
| 473 net_log_)); | 461 net_log_)); |
| 474 } | 462 } |
| 475 | 463 |
| 476 virtual base::TimeDelta ConnectionTimeout() const override { | 464 base::TimeDelta ConnectionTimeout() const override { |
| 477 return timeout_duration_; | 465 return timeout_duration_; |
| 478 } | 466 } |
| 479 | 467 |
| 480 private: | 468 private: |
| 481 TestConnectJob::JobType job_type_; | 469 TestConnectJob::JobType job_type_; |
| 482 std::list<TestConnectJob::JobType>* job_types_; | 470 std::list<TestConnectJob::JobType>* job_types_; |
| 483 base::TimeDelta timeout_duration_; | 471 base::TimeDelta timeout_duration_; |
| 484 MockClientSocketFactory* const client_socket_factory_; | 472 MockClientSocketFactory* const client_socket_factory_; |
| 485 NetLog* net_log_; | 473 NetLog* net_log_; |
| 486 | 474 |
| 487 DISALLOW_COPY_AND_ASSIGN(TestConnectJobFactory); | 475 DISALLOW_COPY_AND_ASSIGN(TestConnectJobFactory); |
| 488 }; | 476 }; |
| 489 | 477 |
| 490 class TestClientSocketPool : public ClientSocketPool { | 478 class TestClientSocketPool : public ClientSocketPool { |
| 491 public: | 479 public: |
| 492 typedef TestSocketParams SocketParams; | 480 typedef TestSocketParams SocketParams; |
| 493 | 481 |
| 494 TestClientSocketPool( | 482 TestClientSocketPool( |
| 495 int max_sockets, | 483 int max_sockets, |
| 496 int max_sockets_per_group, | 484 int max_sockets_per_group, |
| 497 ClientSocketPoolHistograms* histograms, | 485 ClientSocketPoolHistograms* histograms, |
| 498 base::TimeDelta unused_idle_socket_timeout, | 486 base::TimeDelta unused_idle_socket_timeout, |
| 499 base::TimeDelta used_idle_socket_timeout, | 487 base::TimeDelta used_idle_socket_timeout, |
| 500 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) | 488 TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) |
| 501 : base_(NULL, max_sockets, max_sockets_per_group, histograms, | 489 : base_(NULL, max_sockets, max_sockets_per_group, histograms, |
| 502 unused_idle_socket_timeout, used_idle_socket_timeout, | 490 unused_idle_socket_timeout, used_idle_socket_timeout, |
| 503 connect_job_factory) {} | 491 connect_job_factory) {} |
| 504 | 492 |
| 505 virtual ~TestClientSocketPool() {} | 493 ~TestClientSocketPool() override {} |
| 506 | 494 |
| 507 virtual int RequestSocket( | 495 int RequestSocket(const std::string& group_name, |
| 508 const std::string& group_name, | 496 const void* params, |
| 509 const void* params, | 497 net::RequestPriority priority, |
| 510 net::RequestPriority priority, | 498 ClientSocketHandle* handle, |
| 511 ClientSocketHandle* handle, | 499 const CompletionCallback& callback, |
| 512 const CompletionCallback& callback, | 500 const BoundNetLog& net_log) override { |
| 513 const BoundNetLog& net_log) override { | |
| 514 const scoped_refptr<TestSocketParams>* casted_socket_params = | 501 const scoped_refptr<TestSocketParams>* casted_socket_params = |
| 515 static_cast<const scoped_refptr<TestSocketParams>*>(params); | 502 static_cast<const scoped_refptr<TestSocketParams>*>(params); |
| 516 return base_.RequestSocket(group_name, *casted_socket_params, priority, | 503 return base_.RequestSocket(group_name, *casted_socket_params, priority, |
| 517 handle, callback, net_log); | 504 handle, callback, net_log); |
| 518 } | 505 } |
| 519 | 506 |
| 520 virtual void RequestSockets(const std::string& group_name, | 507 void RequestSockets(const std::string& group_name, |
| 521 const void* params, | 508 const void* params, |
| 522 int num_sockets, | 509 int num_sockets, |
| 523 const BoundNetLog& net_log) override { | 510 const BoundNetLog& net_log) override { |
| 524 const scoped_refptr<TestSocketParams>* casted_params = | 511 const scoped_refptr<TestSocketParams>* casted_params = |
| 525 static_cast<const scoped_refptr<TestSocketParams>*>(params); | 512 static_cast<const scoped_refptr<TestSocketParams>*>(params); |
| 526 | 513 |
| 527 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); | 514 base_.RequestSockets(group_name, *casted_params, num_sockets, net_log); |
| 528 } | 515 } |
| 529 | 516 |
| 530 virtual void CancelRequest( | 517 void CancelRequest(const std::string& group_name, |
| 531 const std::string& group_name, | 518 ClientSocketHandle* handle) override { |
| 532 ClientSocketHandle* handle) override { | |
| 533 base_.CancelRequest(group_name, handle); | 519 base_.CancelRequest(group_name, handle); |
| 534 } | 520 } |
| 535 | 521 |
| 536 virtual void ReleaseSocket( | 522 void ReleaseSocket(const std::string& group_name, |
| 537 const std::string& group_name, | 523 scoped_ptr<StreamSocket> socket, |
| 538 scoped_ptr<StreamSocket> socket, | 524 int id) override { |
| 539 int id) override { | |
| 540 base_.ReleaseSocket(group_name, socket.Pass(), id); | 525 base_.ReleaseSocket(group_name, socket.Pass(), id); |
| 541 } | 526 } |
| 542 | 527 |
| 543 virtual void FlushWithError(int error) override { | 528 void FlushWithError(int error) override { base_.FlushWithError(error); } |
| 544 base_.FlushWithError(error); | |
| 545 } | |
| 546 | 529 |
| 547 virtual bool IsStalled() const override { | 530 bool IsStalled() const override { return base_.IsStalled(); } |
| 548 return base_.IsStalled(); | |
| 549 } | |
| 550 | 531 |
| 551 virtual void CloseIdleSockets() override { | 532 void CloseIdleSockets() override { base_.CloseIdleSockets(); } |
| 552 base_.CloseIdleSockets(); | |
| 553 } | |
| 554 | 533 |
| 555 virtual int IdleSocketCount() const override { | 534 int IdleSocketCount() const override { return base_.idle_socket_count(); } |
| 556 return base_.idle_socket_count(); | |
| 557 } | |
| 558 | 535 |
| 559 virtual int IdleSocketCountInGroup( | 536 int IdleSocketCountInGroup(const std::string& group_name) const override { |
| 560 const std::string& group_name) const override { | |
| 561 return base_.IdleSocketCountInGroup(group_name); | 537 return base_.IdleSocketCountInGroup(group_name); |
| 562 } | 538 } |
| 563 | 539 |
| 564 virtual LoadState GetLoadState( | 540 LoadState GetLoadState(const std::string& group_name, |
| 565 const std::string& group_name, | 541 const ClientSocketHandle* handle) const override { |
| 566 const ClientSocketHandle* handle) const override { | |
| 567 return base_.GetLoadState(group_name, handle); | 542 return base_.GetLoadState(group_name, handle); |
| 568 } | 543 } |
| 569 | 544 |
| 570 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override { | 545 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) override { |
| 571 base_.AddHigherLayeredPool(higher_pool); | 546 base_.AddHigherLayeredPool(higher_pool); |
| 572 } | 547 } |
| 573 | 548 |
| 574 virtual void RemoveHigherLayeredPool( | 549 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) override { |
| 575 HigherLayeredPool* higher_pool) override { | |
| 576 base_.RemoveHigherLayeredPool(higher_pool); | 550 base_.RemoveHigherLayeredPool(higher_pool); |
| 577 } | 551 } |
| 578 | 552 |
| 579 virtual base::DictionaryValue* GetInfoAsValue( | 553 base::DictionaryValue* GetInfoAsValue( |
| 580 const std::string& name, | 554 const std::string& name, |
| 581 const std::string& type, | 555 const std::string& type, |
| 582 bool include_nested_pools) const override { | 556 bool include_nested_pools) const override { |
| 583 return base_.GetInfoAsValue(name, type); | 557 return base_.GetInfoAsValue(name, type); |
| 584 } | 558 } |
| 585 | 559 |
| 586 virtual base::TimeDelta ConnectionTimeout() const override { | 560 base::TimeDelta ConnectionTimeout() const override { |
| 587 return base_.ConnectionTimeout(); | 561 return base_.ConnectionTimeout(); |
| 588 } | 562 } |
| 589 | 563 |
| 590 virtual ClientSocketPoolHistograms* histograms() const override { | 564 ClientSocketPoolHistograms* histograms() const override { |
| 591 return base_.histograms(); | 565 return base_.histograms(); |
| 592 } | 566 } |
| 593 | 567 |
| 594 const TestClientSocketPoolBase* base() const { return &base_; } | 568 const TestClientSocketPoolBase* base() const { return &base_; } |
| 595 | 569 |
| 596 int NumUnassignedConnectJobsInGroup(const std::string& group_name) const { | 570 int NumUnassignedConnectJobsInGroup(const std::string& group_name) const { |
| 597 return base_.NumUnassignedConnectJobsInGroup(group_name); | 571 return base_.NumUnassignedConnectJobsInGroup(group_name); |
| 598 } | 572 } |
| 599 | 573 |
| 600 int NumConnectJobsInGroup(const std::string& group_name) const { | 574 int NumConnectJobsInGroup(const std::string& group_name) const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 void MockClientSocketFactory::SetJobLoadState(size_t job, | 618 void MockClientSocketFactory::SetJobLoadState(size_t job, |
| 645 LoadState load_state) { | 619 LoadState load_state) { |
| 646 ASSERT_LT(job, waiting_jobs_.size()); | 620 ASSERT_LT(job, waiting_jobs_.size()); |
| 647 waiting_jobs_[job]->set_load_state(load_state); | 621 waiting_jobs_[job]->set_load_state(load_state); |
| 648 } | 622 } |
| 649 | 623 |
| 650 class TestConnectJobDelegate : public ConnectJob::Delegate { | 624 class TestConnectJobDelegate : public ConnectJob::Delegate { |
| 651 public: | 625 public: |
| 652 TestConnectJobDelegate() | 626 TestConnectJobDelegate() |
| 653 : have_result_(false), waiting_for_result_(false), result_(OK) {} | 627 : have_result_(false), waiting_for_result_(false), result_(OK) {} |
| 654 virtual ~TestConnectJobDelegate() {} | 628 ~TestConnectJobDelegate() override {} |
| 655 | 629 |
| 656 virtual void OnConnectJobComplete(int result, ConnectJob* job) override { | 630 void OnConnectJobComplete(int result, ConnectJob* job) override { |
| 657 result_ = result; | 631 result_ = result; |
| 658 scoped_ptr<ConnectJob> owned_job(job); | 632 scoped_ptr<ConnectJob> owned_job(job); |
| 659 scoped_ptr<StreamSocket> socket = owned_job->PassSocket(); | 633 scoped_ptr<StreamSocket> socket = owned_job->PassSocket(); |
| 660 // socket.get() should be NULL iff result != OK | 634 // socket.get() should be NULL iff result != OK |
| 661 EXPECT_EQ(socket == NULL, result != OK); | 635 EXPECT_EQ(socket == NULL, result != OK); |
| 662 have_result_ = true; | 636 have_result_ = true; |
| 663 if (waiting_for_result_) | 637 if (waiting_for_result_) |
| 664 base::MessageLoop::current()->Quit(); | 638 base::MessageLoop::current()->Quit(); |
| 665 } | 639 } |
| 666 | 640 |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 TestConnectJob::JobType next_job_type) | 1440 TestConnectJob::JobType next_job_type) |
| 1467 : handle_(handle), | 1441 : handle_(handle), |
| 1468 pool_(pool), | 1442 pool_(pool), |
| 1469 within_callback_(false), | 1443 within_callback_(false), |
| 1470 test_connect_job_factory_(test_connect_job_factory), | 1444 test_connect_job_factory_(test_connect_job_factory), |
| 1471 next_job_type_(next_job_type), | 1445 next_job_type_(next_job_type), |
| 1472 callback_(base::Bind(&RequestSocketCallback::OnComplete, | 1446 callback_(base::Bind(&RequestSocketCallback::OnComplete, |
| 1473 base::Unretained(this))) { | 1447 base::Unretained(this))) { |
| 1474 } | 1448 } |
| 1475 | 1449 |
| 1476 virtual ~RequestSocketCallback() {} | 1450 ~RequestSocketCallback() override {} |
| 1477 | 1451 |
| 1478 const CompletionCallback& callback() const { return callback_; } | 1452 const CompletionCallback& callback() const { return callback_; } |
| 1479 | 1453 |
| 1480 private: | 1454 private: |
| 1481 void OnComplete(int result) { | 1455 void OnComplete(int result) { |
| 1482 SetResult(result); | 1456 SetResult(result); |
| 1483 ASSERT_EQ(OK, result); | 1457 ASSERT_EQ(OK, result); |
| 1484 | 1458 |
| 1485 if (!within_callback_) { | 1459 if (!within_callback_) { |
| 1486 test_connect_job_factory_->set_job_type(next_job_type_); | 1460 test_connect_job_factory_->set_job_type(next_job_type_); |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2584 TestReleasingSocketRequest(TestClientSocketPool* pool, | 2558 TestReleasingSocketRequest(TestClientSocketPool* pool, |
| 2585 int expected_result, | 2559 int expected_result, |
| 2586 bool reset_releasing_handle) | 2560 bool reset_releasing_handle) |
| 2587 : pool_(pool), | 2561 : pool_(pool), |
| 2588 expected_result_(expected_result), | 2562 expected_result_(expected_result), |
| 2589 reset_releasing_handle_(reset_releasing_handle), | 2563 reset_releasing_handle_(reset_releasing_handle), |
| 2590 callback_(base::Bind(&TestReleasingSocketRequest::OnComplete, | 2564 callback_(base::Bind(&TestReleasingSocketRequest::OnComplete, |
| 2591 base::Unretained(this))) { | 2565 base::Unretained(this))) { |
| 2592 } | 2566 } |
| 2593 | 2567 |
| 2594 virtual ~TestReleasingSocketRequest() {} | 2568 ~TestReleasingSocketRequest() override {} |
| 2595 | 2569 |
| 2596 ClientSocketHandle* handle() { return &handle_; } | 2570 ClientSocketHandle* handle() { return &handle_; } |
| 2597 | 2571 |
| 2598 const CompletionCallback& callback() const { return callback_; } | 2572 const CompletionCallback& callback() const { return callback_; } |
| 2599 | 2573 |
| 2600 private: | 2574 private: |
| 2601 void OnComplete(int result) { | 2575 void OnComplete(int result) { |
| 2602 SetResult(result); | 2576 SetResult(result); |
| 2603 if (reset_releasing_handle_) | 2577 if (reset_releasing_handle_) |
| 2604 handle_.Reset(); | 2578 handle_.Reset(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2709 const std::string& group_name, | 2683 const std::string& group_name, |
| 2710 const scoped_refptr<TestSocketParams>& params, | 2684 const scoped_refptr<TestSocketParams>& params, |
| 2711 TestClientSocketPool* pool) | 2685 TestClientSocketPool* pool) |
| 2712 : group_name_(group_name), | 2686 : group_name_(group_name), |
| 2713 params_(params), | 2687 params_(params), |
| 2714 pool_(pool), | 2688 pool_(pool), |
| 2715 callback_(base::Bind(&ConnectWithinCallback::OnComplete, | 2689 callback_(base::Bind(&ConnectWithinCallback::OnComplete, |
| 2716 base::Unretained(this))) { | 2690 base::Unretained(this))) { |
| 2717 } | 2691 } |
| 2718 | 2692 |
| 2719 virtual ~ConnectWithinCallback() {} | 2693 ~ConnectWithinCallback() override {} |
| 2720 | 2694 |
| 2721 int WaitForNestedResult() { | 2695 int WaitForNestedResult() { |
| 2722 return nested_callback_.WaitForResult(); | 2696 return nested_callback_.WaitForResult(); |
| 2723 } | 2697 } |
| 2724 | 2698 |
| 2725 const CompletionCallback& callback() const { return callback_; } | 2699 const CompletionCallback& callback() const { return callback_; } |
| 2726 | 2700 |
| 2727 private: | 2701 private: |
| 2728 void OnComplete(int result) { | 2702 void OnComplete(int result) { |
| 2729 SetResult(result); | 2703 SetResult(result); |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4120 request(1)->handle()->Reset(); | 4094 request(1)->handle()->Reset(); |
| 4121 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 4095 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
| 4122 | 4096 |
| 4123 EXPECT_EQ(OK, request(2)->WaitForResult()); | 4097 EXPECT_EQ(OK, request(2)->WaitForResult()); |
| 4124 EXPECT_FALSE(request(1)->have_result()); | 4098 EXPECT_FALSE(request(1)->have_result()); |
| 4125 } | 4099 } |
| 4126 | 4100 |
| 4127 } // namespace | 4101 } // namespace |
| 4128 | 4102 |
| 4129 } // namespace net | 4103 } // namespace net |
| OLD | NEW |