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/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const uint64 kBrokenAlternativeProtocolDelaySecs = 300; | 25 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 29 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
30 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 30 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
31 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), | 31 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), |
32 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 32 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
33 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), | 33 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
34 alternative_service_probability_threshold_(1.0), | 34 alternative_service_probability_threshold_(1.0), |
35 quic_server_info_map_(kMaxQuicServersToPersist), | 35 quic_server_info_map_(kMaxQuicServersToPersist), |
(...skipping 28 matching lines...) Expand all Loading... |
64 it != spdy_servers_map.rend(); ++it) { | 64 it != spdy_servers_map.rend(); ++it) { |
65 // Add the entry if it is not in the cache, otherwise move it to the front | 65 // Add the entry if it is not in the cache, otherwise move it to the front |
66 // of recency list. | 66 // of recency list. |
67 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) | 67 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) |
68 spdy_servers_map_.Put(it->first, it->second); | 68 spdy_servers_map_.Put(it->first, it->second); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( | 72 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( |
73 AlternativeServiceMap* alternative_service_map) { | 73 AlternativeServiceMap* alternative_service_map) { |
74 int32 size_diff = | 74 int32_t size_diff = |
75 alternative_service_map->size() - alternative_service_map_.size(); | 75 alternative_service_map->size() - alternative_service_map_.size(); |
76 if (size_diff > 0) { | 76 if (size_diff > 0) { |
77 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries", | 77 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries", |
78 size_diff); | 78 size_diff); |
79 } else { | 79 } else { |
80 UMA_HISTOGRAM_COUNTS( | 80 UMA_HISTOGRAM_COUNTS( |
81 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff); | 81 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff); |
82 } | 82 } |
83 | 83 |
84 AlternativeServiceMap new_alternative_service_map( | 84 AlternativeServiceMap new_alternative_service_map( |
(...skipping 12 matching lines...) Expand all Loading... |
97 for (AlternativeServiceMap::reverse_iterator input_it = | 97 for (AlternativeServiceMap::reverse_iterator input_it = |
98 new_alternative_service_map.rbegin(); | 98 new_alternative_service_map.rbegin(); |
99 input_it != new_alternative_service_map.rend(); ++input_it) { | 99 input_it != new_alternative_service_map.rend(); ++input_it) { |
100 if (alternative_service_map_.Get(input_it->first) == | 100 if (alternative_service_map_.Get(input_it->first) == |
101 alternative_service_map_.end()) { | 101 alternative_service_map_.end()) { |
102 alternative_service_map_.Put(input_it->first, input_it->second); | 102 alternative_service_map_.Put(input_it->first, input_it->second); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 // Attempt to find canonical servers. | 106 // Attempt to find canonical servers. |
107 uint16 canonical_ports[] = { 80, 443 }; | 107 uint16_t canonical_ports[] = {80, 443}; |
108 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 108 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
109 std::string canonical_suffix = canonical_suffixes_[i]; | 109 std::string canonical_suffix = canonical_suffixes_[i]; |
110 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 110 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { |
111 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 111 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
112 // If we already have a valid canonical server, we're done. | 112 // If we already have a valid canonical server, we're done. |
113 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 113 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
114 (alternative_service_map_.Peek( | 114 (alternative_service_map_.Peek( |
115 canonical_host_to_origin_map_[canonical_host]) != | 115 canonical_host_to_origin_map_[canonical_host]) != |
116 alternative_service_map_.end())) { | 116 alternative_service_map_.end())) { |
117 continue; | 117 continue; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 573 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
574 return kEmptySettingsMap; | 574 return kEmptySettingsMap; |
575 } | 575 } |
576 return it->second; | 576 return it->second; |
577 } | 577 } |
578 | 578 |
579 bool HttpServerPropertiesImpl::SetSpdySetting( | 579 bool HttpServerPropertiesImpl::SetSpdySetting( |
580 const HostPortPair& host_port_pair, | 580 const HostPortPair& host_port_pair, |
581 SpdySettingsIds id, | 581 SpdySettingsIds id, |
582 SpdySettingsFlags flags, | 582 SpdySettingsFlags flags, |
583 uint32 value) { | 583 uint32_t value) { |
584 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) | 584 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) |
585 return false; | 585 return false; |
586 | 586 |
587 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 587 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
588 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 588 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
589 if (it == spdy_settings_map_.end()) { | 589 if (it == spdy_settings_map_.end()) { |
590 SettingsMap settings_map; | 590 SettingsMap settings_map; |
591 settings_map[id] = flags_and_value; | 591 settings_map[id] = flags_and_value; |
592 spdy_settings_map_.Put(host_port_pair, settings_map); | 592 spdy_settings_map_.Put(host_port_pair, settings_map); |
593 } else { | 593 } else { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 795 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
796 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 796 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
797 FROM_HERE, | 797 FROM_HERE, |
798 base::Bind( | 798 base::Bind( |
799 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 799 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
800 weak_ptr_factory_.GetWeakPtr()), | 800 weak_ptr_factory_.GetWeakPtr()), |
801 delay); | 801 delay); |
802 } | 802 } |
803 | 803 |
804 } // namespace net | 804 } // namespace net |
OLD | NEW |