Chromium Code Reviews| 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::ProcessMemoryDump* pmd, | |
| 705 const std::string& parent_dump_absolute_name) const { | |
| 706 base::trace_event::MemoryAllocatorDump* socket_pool_dump = nullptr; | |
| 707 size_t socket_count = 0; | |
| 708 for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end(); | |
|
Primiano Tucci (use gerrit)
2016/12/06 17:06:28
for (const auto& kv : group_map) might save one li
xunjieli
2016/12/06 18:36:08
Done.
| |
| 709 ++it) { | |
| 710 for (const auto& socket : it->second->idle_sockets()) { | |
| 711 // Only create a MemoryAllocatorDump if there is at least one idle socket | |
| 712 if (!socket_pool_dump) { | |
| 713 socket_pool_dump = pmd->CreateAllocatorDump(base::StringPrintf( | |
| 714 "%s/socket_pool", parent_dump_absolute_name.c_str())); | |
| 715 } | |
| 716 socket.socket->DumpMemoryStats(pmd, socket_pool_dump->absolute_name()); | |
| 717 ++socket_count; | |
| 718 } | |
| 719 } | |
| 720 if (socket_pool_dump) { | |
| 721 socket_pool_dump->AddScalar( | |
| 722 base::trace_event::MemoryAllocatorDump::kNameObjectCount, | |
| 723 base::trace_event::MemoryAllocatorDump::kUnitsObjects, socket_count); | |
| 724 } | |
| 725 } | |
| 726 | |
| 700 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { | 727 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const { |
| 701 if (socket->WasEverUsed()) | 728 if (socket->WasEverUsed()) |
| 702 return socket->IsConnectedAndIdle(); | 729 return socket->IsConnectedAndIdle(); |
| 703 return socket->IsConnected(); | 730 return socket->IsConnected(); |
| 704 } | 731 } |
| 705 | 732 |
| 706 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { | 733 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { |
| 707 if (idle_socket_count_ == 0) | 734 if (idle_socket_count_ == 0) |
| 708 return; | 735 return; |
| 709 | 736 |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1381 // If there are no more requests, kill the backup timer. | 1408 // If there are no more requests, kill the backup timer. |
| 1382 if (pending_requests_.empty()) | 1409 if (pending_requests_.empty()) |
| 1383 backup_job_timer_.Stop(); | 1410 backup_job_timer_.Stop(); |
| 1384 request->CrashIfInvalid(); | 1411 request->CrashIfInvalid(); |
| 1385 return request; | 1412 return request; |
| 1386 } | 1413 } |
| 1387 | 1414 |
| 1388 } // namespace internal | 1415 } // namespace internal |
| 1389 | 1416 |
| 1390 } // namespace net | 1417 } // namespace net |
| OLD | NEW |