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 <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 int id) override { | 542 int id) override { |
543 base_.ReleaseSocket(group_name, std::move(socket), id); | 543 base_.ReleaseSocket(group_name, std::move(socket), id); |
544 } | 544 } |
545 | 545 |
546 void FlushWithError(int error) override { base_.FlushWithError(error); } | 546 void FlushWithError(int error) override { base_.FlushWithError(error); } |
547 | 547 |
548 bool IsStalled() const override { return base_.IsStalled(); } | 548 bool IsStalled() const override { return base_.IsStalled(); } |
549 | 549 |
550 void CloseIdleSockets() override { base_.CloseIdleSockets(); } | 550 void CloseIdleSockets() override { base_.CloseIdleSockets(); } |
551 | 551 |
| 552 void CloseIdleSocketsInGroup(const std::string& group_name) override { |
| 553 base_.CloseIdleSocketsInGroup(group_name); |
| 554 } |
| 555 |
552 int IdleSocketCount() const override { return base_.idle_socket_count(); } | 556 int IdleSocketCount() const override { return base_.idle_socket_count(); } |
553 | 557 |
554 int IdleSocketCountInGroup(const std::string& group_name) const override { | 558 int IdleSocketCountInGroup(const std::string& group_name) const override { |
555 return base_.IdleSocketCountInGroup(group_name); | 559 return base_.IdleSocketCountInGroup(group_name); |
556 } | 560 } |
557 | 561 |
558 LoadState GetLoadState(const std::string& group_name, | 562 LoadState GetLoadState(const std::string& group_name, |
559 const ClientSocketHandle* handle) const override { | 563 const ClientSocketHandle* handle) const override { |
560 return base_.GetLoadState(group_name, handle); | 564 return base_.GetLoadState(group_name, handle); |
561 } | 565 } |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 callback.callback(), pool_.get(), log.bound()); | 1617 callback.callback(), pool_.get(), log.bound()); |
1614 EXPECT_THAT(rv, IsOk()); | 1618 EXPECT_THAT(rv, IsOk()); |
1615 handle.Reset(); | 1619 handle.Reset(); |
1616 EXPECT_EQ(1, pool_->IdleSocketCount()); | 1620 EXPECT_EQ(1, pool_->IdleSocketCount()); |
1617 pool_->CloseIdleSockets(); | 1621 pool_->CloseIdleSockets(); |
1618 EXPECT_THAT(histograms.GetAllSamples(kIdleSocketFateHistogram), | 1622 EXPECT_THAT(histograms.GetAllSamples(kIdleSocketFateHistogram), |
1619 testing::ElementsAre( | 1623 testing::ElementsAre( |
1620 base::Bucket(/*IDLE_SOCKET_FATE_CLEAN_UP_FORCED=*/4, 1))); | 1624 base::Bucket(/*IDLE_SOCKET_FATE_CLEAN_UP_FORCED=*/4, 1))); |
1621 } | 1625 } |
1622 | 1626 |
| 1627 TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsInGroupForced) { |
| 1628 base::HistogramTester histograms; |
| 1629 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
| 1630 TestCompletionCallback callback; |
| 1631 BoundTestNetLog log; |
| 1632 ClientSocketHandle handle1; |
| 1633 int rv = handle1.Init("a", params_, LOWEST, |
| 1634 ClientSocketPool::RespectLimits::ENABLED, |
| 1635 callback.callback(), pool_.get(), log.bound()); |
| 1636 EXPECT_THAT(rv, IsOk()); |
| 1637 ClientSocketHandle handle2; |
| 1638 rv = handle2.Init("a", params_, LOWEST, |
| 1639 ClientSocketPool::RespectLimits::ENABLED, |
| 1640 callback.callback(), pool_.get(), log.bound()); |
| 1641 ClientSocketHandle handle3; |
| 1642 rv = handle3.Init("b", params_, LOWEST, |
| 1643 ClientSocketPool::RespectLimits::ENABLED, |
| 1644 callback.callback(), pool_.get(), log.bound()); |
| 1645 EXPECT_THAT(rv, IsOk()); |
| 1646 handle1.Reset(); |
| 1647 handle2.Reset(); |
| 1648 handle3.Reset(); |
| 1649 EXPECT_EQ(3, pool_->IdleSocketCount()); |
| 1650 pool_->CloseIdleSocketsInGroup("a"); |
| 1651 EXPECT_EQ(1, pool_->IdleSocketCount()); |
| 1652 EXPECT_THAT(histograms.GetAllSamples(kIdleSocketFateHistogram), |
| 1653 testing::ElementsAre( |
| 1654 base::Bucket(/*IDLE_SOCKET_FATE_CLEAN_UP_FORCED=*/4, 2))); |
| 1655 } |
| 1656 |
1623 TEST_F(ClientSocketPoolBaseTest, CleanUpUnusableIdleSockets) { | 1657 TEST_F(ClientSocketPoolBaseTest, CleanUpUnusableIdleSockets) { |
1624 base::HistogramTester histograms; | 1658 base::HistogramTester histograms; |
1625 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1659 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1626 ClientSocketHandle handle; | 1660 ClientSocketHandle handle; |
1627 TestCompletionCallback callback; | 1661 TestCompletionCallback callback; |
1628 BoundTestNetLog log; | 1662 BoundTestNetLog log; |
1629 int rv = handle.Init("a", params_, LOWEST, | 1663 int rv = handle.Init("a", params_, LOWEST, |
1630 ClientSocketPool::RespectLimits::ENABLED, | 1664 ClientSocketPool::RespectLimits::ENABLED, |
1631 callback.callback(), pool_.get(), log.bound()); | 1665 callback.callback(), pool_.get(), log.bound()); |
1632 EXPECT_THAT(rv, IsOk()); | 1666 EXPECT_THAT(rv, IsOk()); |
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3932 request(1)->handle()->Reset(); | 3966 request(1)->handle()->Reset(); |
3933 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); | 3967 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); |
3934 | 3968 |
3935 EXPECT_THAT(request(2)->WaitForResult(), IsOk()); | 3969 EXPECT_THAT(request(2)->WaitForResult(), IsOk()); |
3936 EXPECT_FALSE(request(1)->have_result()); | 3970 EXPECT_FALSE(request(1)->have_result()); |
3937 } | 3971 } |
3938 | 3972 |
3939 } // namespace | 3973 } // namespace |
3940 | 3974 |
3941 } // namespace net | 3975 } // namespace net |
OLD | NEW |