| 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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 ~TestConnectJobDelegate() override {} | 627 ~TestConnectJobDelegate() override {} |
| 628 | 628 |
| 629 void OnConnectJobComplete(int result, ConnectJob* job) override { | 629 void OnConnectJobComplete(int result, ConnectJob* job) override { |
| 630 result_ = result; | 630 result_ = result; |
| 631 scoped_ptr<ConnectJob> owned_job(job); | 631 scoped_ptr<ConnectJob> owned_job(job); |
| 632 scoped_ptr<StreamSocket> socket = owned_job->PassSocket(); | 632 scoped_ptr<StreamSocket> socket = owned_job->PassSocket(); |
| 633 // socket.get() should be NULL iff result != OK | 633 // socket.get() should be NULL iff result != OK |
| 634 EXPECT_EQ(socket == NULL, result != OK); | 634 EXPECT_EQ(socket == NULL, result != OK); |
| 635 have_result_ = true; | 635 have_result_ = true; |
| 636 if (waiting_for_result_) | 636 if (waiting_for_result_) |
| 637 base::MessageLoop::current()->Quit(); | 637 base::MessageLoop::current()->QuitWhenIdle(); |
| 638 } | 638 } |
| 639 | 639 |
| 640 int WaitForResult() { | 640 int WaitForResult() { |
| 641 DCHECK(!waiting_for_result_); | 641 DCHECK(!waiting_for_result_); |
| 642 while (!have_result_) { | 642 while (!have_result_) { |
| 643 waiting_for_result_ = true; | 643 waiting_for_result_ = true; |
| 644 base::MessageLoop::current()->Run(); | 644 base::MessageLoop::current()->Run(); |
| 645 waiting_for_result_ = false; | 645 waiting_for_result_ = false; |
| 646 } | 646 } |
| 647 have_result_ = false; // auto-reset for next callback | 647 have_result_ = false; // auto-reset for next callback |
| (...skipping 2996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3644 pool_->RequestSockets("a", ¶ms_, 1, BoundNetLog()); | 3644 pool_->RequestSockets("a", ¶ms_, 1, BoundNetLog()); |
| 3645 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3645 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
| 3646 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a")); | 3646 EXPECT_EQ(1, pool_->NumUnassignedConnectJobsInGroup("a")); |
| 3647 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 3647 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
| 3648 | 3648 |
| 3649 // Verify the backup timer doesn't create a backup job, by making | 3649 // Verify the backup timer doesn't create a backup job, by making |
| 3650 // the backup job a pending job instead of a waiting job, so it | 3650 // the backup job a pending job instead of a waiting job, so it |
| 3651 // *would* complete if it were created. | 3651 // *would* complete if it were created. |
| 3652 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 3652 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
| 3653 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 3653 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 3654 FROM_HERE, base::MessageLoop::QuitClosure(), | 3654 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 3655 base::TimeDelta::FromSeconds(1)); | 3655 base::TimeDelta::FromSeconds(1)); |
| 3656 base::MessageLoop::current()->Run(); | 3656 base::MessageLoop::current()->Run(); |
| 3657 EXPECT_FALSE(pool_->HasGroup("a")); | 3657 EXPECT_FALSE(pool_->HasGroup("a")); |
| 3658 } | 3658 } |
| 3659 | 3659 |
| 3660 TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { | 3660 TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { |
| 3661 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 3661 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 3662 pool_->EnableConnectBackupJobs(); | 3662 pool_->EnableConnectBackupJobs(); |
| 3663 | 3663 |
| 3664 // Make the ConnectJob hang forever. | 3664 // Make the ConnectJob hang forever. |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4072 request(1)->handle()->Reset(); | 4072 request(1)->handle()->Reset(); |
| 4073 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 4073 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
| 4074 | 4074 |
| 4075 EXPECT_EQ(OK, request(2)->WaitForResult()); | 4075 EXPECT_EQ(OK, request(2)->WaitForResult()); |
| 4076 EXPECT_FALSE(request(1)->have_result()); | 4076 EXPECT_FALSE(request(1)->have_result()); |
| 4077 } | 4077 } |
| 4078 | 4078 |
| 4079 } // namespace | 4079 } // namespace |
| 4080 | 4080 |
| 4081 } // namespace net | 4081 } // namespace net |
| OLD | NEW |