| 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/strings/stringprintf.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/trace_event/memory_allocator_dump.h" |
| 21 #include "base/trace_event/process_memory_dump.h" |
| 19 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 20 #include "base/values.h" | 23 #include "base/values.h" |
| 21 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 22 #include "net/log/net_log.h" | 25 #include "net/log/net_log.h" |
| 23 #include "net/log/net_log_event_type.h" | 26 #include "net/log/net_log_event_type.h" |
| 24 #include "net/log/net_log_source.h" | 27 #include "net/log/net_log_source.h" |
| 25 | 28 |
| 26 using base::TimeDelta; | 29 using base::TimeDelta; |
| 27 | 30 |
| 28 namespace net { | 31 namespace net { |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 max_sockets_per_group_)); | 693 max_sockets_per_group_)); |
| 691 group_dict->SetBoolean("backup_job_timer_is_running", | 694 group_dict->SetBoolean("backup_job_timer_is_running", |
| 692 group->BackupJobTimerIsRunning()); | 695 group->BackupJobTimerIsRunning()); |
| 693 | 696 |
| 694 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); | 697 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); |
| 695 } | 698 } |
| 696 dict->Set("groups", all_groups_dict); | 699 dict->Set("groups", all_groups_dict); |
| 697 return dict; | 700 return dict; |
| 698 } | 701 } |
| 699 | 702 |
| 703 void ClientSocketPoolBaseHelper::DumpMemoryStats( |
| 704 base::trace_event::MemoryAllocatorDump* dump) const { |
| 705 base::trace_event::MemoryAllocatorDump* socket_pool_dump = nullptr; |
| 706 size_t socket_count = 0; |
| 707 for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end(); |
| 708 ++it) { |
| 709 const std::list<IdleSocket> sockets = it->second->idle_sockets(); |
| 710 for (auto socket : sockets) { |
| 711 // Only creates a MemoryAllocatorDump if there is at least one idle socket |
| 712 if (!socket_pool_dump) { |
| 713 socket_pool_dump = |
| 714 dump->process_memory_dump()->CreateAllocatorDump(base::StringPrintf( |
| 715 "%s/socket_pool", dump->absolute_name().c_str())); |
| 716 } |
| 717 socket.socket->DumpMemoryStats(socket_pool_dump); |
| 718 ++socket_count; |
| 719 } |
| 720 } |
| 721 if (socket_pool_dump) { |
| 722 socket_pool_dump->AddScalar( |
| 723 base::trace_event::MemoryAllocatorDump::kNameObjectCount, |
| 724 base::trace_event::MemoryAllocatorDump::kUnitsObjects, socket_count); |
| 725 } |
| 726 } |
| 727 |
| 700 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { | 728 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { |
| 701 if (socket->WasEverUsed()) | 729 if (socket->WasEverUsed()) |
| 702 return socket->IsConnectedAndIdle(); | 730 return socket->IsConnectedAndIdle(); |
| 703 return socket->IsConnected(); | 731 return socket->IsConnected(); |
| 704 } | 732 } |
| 705 | 733 |
| 706 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { | 734 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { |
| 707 if (idle_socket_count_ == 0) | 735 if (idle_socket_count_ == 0) |
| 708 return; | 736 return; |
| 709 | 737 |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 // If there are no more requests, kill the backup timer. | 1412 // If there are no more requests, kill the backup timer. |
| 1385 if (pending_requests_.empty()) | 1413 if (pending_requests_.empty()) |
| 1386 backup_job_timer_.Stop(); | 1414 backup_job_timer_.Stop(); |
| 1387 request->CrashIfInvalid(); | 1415 request->CrashIfInvalid(); |
| 1388 return request; | 1416 return request; |
| 1389 } | 1417 } |
| 1390 | 1418 |
| 1391 } // namespace internal | 1419 } // namespace internal |
| 1392 | 1420 |
| 1393 } // namespace net | 1421 } // namespace net |
| OLD | NEW |