| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/log/net_log.h" | 22 #include "net/log/net_log.h" |
| 23 #include "net/log/net_log_event_type.h" | 23 #include "net/log/net_log_event_type.h" |
| 24 #include "net/log/net_log_source.h" | 24 #include "net/log/net_log_source.h" |
| 25 | 25 |
| 26 #include "base/trace_event/memory_allocator_dump.h" |
| 27 #include "base/trace_event/process_memory_dump.h" |
| 28 #include "base/strings/stringprintf.h" |
| 29 |
| 26 using base::TimeDelta; | 30 using base::TimeDelta; |
| 27 | 31 |
| 28 namespace net { | 32 namespace net { |
| 29 | 33 |
| 30 namespace { | 34 namespace { |
| 31 | 35 |
| 32 // Indicate whether or not we should establish a new transport layer connection | 36 // Indicate whether or not we should establish a new transport layer connection |
| 33 // after a certain timeout has passed without receiving an ACK. | 37 // after a certain timeout has passed without receiving an ACK. |
| 34 bool g_connect_backup_jobs_enabled = true; | 38 bool g_connect_backup_jobs_enabled = true; |
| 35 | 39 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 ClientSocketHandle::SocketReuseType reuse_type = | 492 ClientSocketHandle::SocketReuseType reuse_type = |
| 489 idle_socket.socket->WasEverUsed() ? | 493 idle_socket.socket->WasEverUsed() ? |
| 490 ClientSocketHandle::REUSED_IDLE : | 494 ClientSocketHandle::REUSED_IDLE : |
| 491 ClientSocketHandle::UNUSED_IDLE; | 495 ClientSocketHandle::UNUSED_IDLE; |
| 492 | 496 |
| 493 // If this socket took multiple attempts to obtain, don't report those | 497 // If this socket took multiple attempts to obtain, don't report those |
| 494 // every time it's reused, just to the first user. | 498 // every time it's reused, just to the first user. |
| 495 if (idle_socket.socket->WasEverUsed()) | 499 if (idle_socket.socket->WasEverUsed()) |
| 496 idle_socket.socket->ClearConnectionAttempts(); | 500 idle_socket.socket->ClearConnectionAttempts(); |
| 497 | 501 |
| 502 idle_socket.socket->OnRemovedFromPool(); |
| 503 |
| 498 HandOutSocket(std::unique_ptr<StreamSocket>(idle_socket.socket), reuse_type, | 504 HandOutSocket(std::unique_ptr<StreamSocket>(idle_socket.socket), reuse_type, |
| 499 LoadTimingInfo::ConnectTiming(), request.handle(), idle_time, | 505 LoadTimingInfo::ConnectTiming(), request.handle(), idle_time, |
| 500 group, request.net_log()); | 506 group, request.net_log()); |
| 501 return true; | 507 return true; |
| 502 } | 508 } |
| 503 | 509 |
| 504 return false; | 510 return false; |
| 505 } | 511 } |
| 506 | 512 |
| 507 // static | 513 // static |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 max_sockets_per_group_)); | 650 max_sockets_per_group_)); |
| 645 group_dict->SetBoolean("backup_job_timer_is_running", | 651 group_dict->SetBoolean("backup_job_timer_is_running", |
| 646 group->BackupJobTimerIsRunning()); | 652 group->BackupJobTimerIsRunning()); |
| 647 | 653 |
| 648 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); | 654 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); |
| 649 } | 655 } |
| 650 dict->Set("groups", all_groups_dict); | 656 dict->Set("groups", all_groups_dict); |
| 651 return dict; | 657 return dict; |
| 652 } | 658 } |
| 653 | 659 |
| 660 void ClientSocketPoolBaseHelper::PopulateAllocatorDump( |
| 661 base::trace_event::MemoryAllocatorDump* dump) const { |
| 662 base::trace_event::MemoryAllocatorDump* socket_pool_dump = |
| 663 dump->process_memory_dump()->CreateAllocatorDump(base::StringPrintf( |
| 664 "%s/socket_pool", dump->absolute_name().c_str())); |
| 665 for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end(); |
| 666 ++it) { |
| 667 const std::list<IdleSocket> sockets = it->second->idle_sockets(); |
| 668 for (auto socket : sockets) { |
| 669 socket.socket->PopulateAllocatorDump(socket_pool_dump); |
| 670 } |
| 671 } |
| 672 } |
| 673 |
| 654 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { | 674 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { |
| 655 if (socket->WasEverUsed()) | 675 if (socket->WasEverUsed()) |
| 656 return socket->IsConnectedAndIdle(); | 676 return socket->IsConnectedAndIdle(); |
| 657 return socket->IsConnected(); | 677 return socket->IsConnected(); |
| 658 } | 678 } |
| 659 | 679 |
| 660 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( | 680 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( |
| 661 base::TimeTicks now, | 681 base::TimeTicks now, |
| 662 base::TimeDelta timeout) const { | 682 base::TimeDelta timeout) const { |
| 663 bool timed_out = (now - start_time) >= timeout; | 683 bool timed_out = (now - start_time) >= timeout; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 handle->socket()->NetLog().source().ToEventParametersCallback()); | 1023 handle->socket()->NetLog().source().ToEventParametersCallback()); |
| 1004 | 1024 |
| 1005 handed_out_socket_count_++; | 1025 handed_out_socket_count_++; |
| 1006 group->IncrementActiveSocketCount(); | 1026 group->IncrementActiveSocketCount(); |
| 1007 } | 1027 } |
| 1008 | 1028 |
| 1009 void ClientSocketPoolBaseHelper::AddIdleSocket( | 1029 void ClientSocketPoolBaseHelper::AddIdleSocket( |
| 1010 std::unique_ptr<StreamSocket> socket, | 1030 std::unique_ptr<StreamSocket> socket, |
| 1011 Group* group) { | 1031 Group* group) { |
| 1012 DCHECK(socket); | 1032 DCHECK(socket); |
| 1033 socket->OnAddedToPool(); |
| 1013 IdleSocket idle_socket; | 1034 IdleSocket idle_socket; |
| 1014 idle_socket.socket = socket.release(); | 1035 idle_socket.socket = socket.release(); |
| 1015 idle_socket.start_time = base::TimeTicks::Now(); | 1036 idle_socket.start_time = base::TimeTicks::Now(); |
| 1016 | 1037 |
| 1017 group->mutable_idle_sockets()->push_back(idle_socket); | 1038 group->mutable_idle_sockets()->push_back(idle_socket); |
| 1018 IncrementIdleCount(); | 1039 IncrementIdleCount(); |
| 1019 } | 1040 } |
| 1020 | 1041 |
| 1021 void ClientSocketPoolBaseHelper::CancelAllConnectJobs() { | 1042 void ClientSocketPoolBaseHelper::CancelAllConnectJobs() { |
| 1022 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { | 1043 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 // If there are no more requests, kill the backup timer. | 1350 // If there are no more requests, kill the backup timer. |
| 1330 if (pending_requests_.empty()) | 1351 if (pending_requests_.empty()) |
| 1331 backup_job_timer_.Stop(); | 1352 backup_job_timer_.Stop(); |
| 1332 request->CrashIfInvalid(); | 1353 request->CrashIfInvalid(); |
| 1333 return request; | 1354 return request; |
| 1334 } | 1355 } |
| 1335 | 1356 |
| 1336 } // namespace internal | 1357 } // namespace internal |
| 1337 | 1358 |
| 1338 } // namespace net | 1359 } // namespace net |
| OLD | NEW |