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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; | 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
31 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 31 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), | 32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), |
33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), | 34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), |
35 alternative_service_probability_threshold_(1.0), | 35 alternative_service_probability_threshold_(1.0), |
36 quic_server_info_map_(kMaxQuicServersToPersist), | 36 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), |
37 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), | |
37 weak_ptr_factory_(this) { | 38 weak_ptr_factory_(this) { |
38 canonical_suffixes_.push_back(".c.youtube.com"); | 39 canonical_suffixes_.push_back(".c.youtube.com"); |
39 canonical_suffixes_.push_back(".googlevideo.com"); | 40 canonical_suffixes_.push_back(".googlevideo.com"); |
40 canonical_suffixes_.push_back(".googleusercontent.com"); | 41 canonical_suffixes_.push_back(".googleusercontent.com"); |
41 } | 42 } |
42 | 43 |
43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 44 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
44 } | 45 } |
45 | 46 |
46 void HttpServerPropertiesImpl::InitializeSpdyServers( | 47 void HttpServerPropertiesImpl::InitializeSpdyServers( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 if (server_network_stats_map_.Get(it->first) == | 178 if (server_network_stats_map_.Get(it->first) == |
178 server_network_stats_map_.end()) { | 179 server_network_stats_map_.end()) { |
179 server_network_stats_map_.Put(it->first, it->second); | 180 server_network_stats_map_.Put(it->first, it->second); |
180 } | 181 } |
181 } | 182 } |
182 } | 183 } |
183 | 184 |
184 void HttpServerPropertiesImpl::InitializeQuicServerInfoMap( | 185 void HttpServerPropertiesImpl::InitializeQuicServerInfoMap( |
185 QuicServerInfoMap* quic_server_info_map) { | 186 QuicServerInfoMap* quic_server_info_map) { |
186 // Add the entries from persisted data. | 187 // Add the entries from persisted data. |
187 QuicServerInfoMap temp_map(kMaxQuicServersToPersist); | 188 QuicServerInfoMap temp_map(QuicServerInfoMap::NO_AUTO_EVICT); |
188 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin(); | 189 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin(); |
189 it != quic_server_info_map->rend(); ++it) { | 190 it != quic_server_info_map->rend(); ++it) { |
190 temp_map.Put(it->first, it->second); | 191 temp_map.Put(it->first, it->second); |
191 } | 192 } |
192 | 193 |
193 quic_server_info_map_.Swap(temp_map); | 194 quic_server_info_map_.Swap(temp_map); |
194 | 195 |
195 // Add the entries from the memory cache. | 196 // Add the entries from the memory cache. |
196 for (QuicServerInfoMap::reverse_iterator it = temp_map.rbegin(); | 197 for (QuicServerInfoMap::reverse_iterator it = temp_map.rbegin(); |
197 it != temp_map.rend(); ++it) { | 198 it != temp_map.rend(); ++it) { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 if (it == quic_server_info_map_.end()) | 670 if (it == quic_server_info_map_.end()) |
670 return nullptr; | 671 return nullptr; |
671 return &it->second; | 672 return &it->second; |
672 } | 673 } |
673 | 674 |
674 const QuicServerInfoMap& HttpServerPropertiesImpl::quic_server_info_map() | 675 const QuicServerInfoMap& HttpServerPropertiesImpl::quic_server_info_map() |
675 const { | 676 const { |
676 return quic_server_info_map_; | 677 return quic_server_info_map_; |
677 } | 678 } |
678 | 679 |
680 int HttpServerPropertiesImpl::max_server_configs_stored_in_properties() const { | |
681 return max_server_configs_stored_in_properties_; | |
682 } | |
683 | |
684 void HttpServerPropertiesImpl::set_max_server_configs_stored_in_properties( | |
mef
2016/01/15 16:12:32
Should this be SetMaxServerConfigsStoredInProperti
ramant (doing other things)
2016/01/15 18:57:01
Good point.
Done.
| |
685 int max_server_configs_stored_in_properties) { | |
686 max_server_configs_stored_in_properties_ = | |
687 max_server_configs_stored_in_properties; | |
688 | |
689 // MRUCache doesn't allow the size of the cache to be changed. Thus create a | |
690 // new map with the new size and add current elements and swap the new map. | |
691 QuicServerInfoMap temp_map(max_server_configs_stored_in_properties_); | |
692 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin(); | |
mef
2016/01/15 16:12:32
Microoptimization: quic_server_info_map_.ShrinkToS
ramant (doing other things)
2016/01/15 18:57:01
+1. Thanks for the above optimization.
Done.
| |
693 it != quic_server_info_map_.rend(); ++it) { | |
694 temp_map.Put(it->first, it->second); | |
695 } | |
696 | |
697 quic_server_info_map_.Swap(temp_map); | |
698 } | |
699 | |
679 void HttpServerPropertiesImpl::SetAlternativeServiceProbabilityThreshold( | 700 void HttpServerPropertiesImpl::SetAlternativeServiceProbabilityThreshold( |
680 double threshold) { | 701 double threshold) { |
681 alternative_service_probability_threshold_ = threshold; | 702 alternative_service_probability_threshold_ = threshold; |
682 } | 703 } |
683 | 704 |
684 AlternativeServiceMap::const_iterator | 705 AlternativeServiceMap::const_iterator |
685 HttpServerPropertiesImpl::GetAlternateProtocolIterator( | 706 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
686 const HostPortPair& server) { | 707 const HostPortPair& server) { |
687 AlternativeServiceMap::const_iterator it = | 708 AlternativeServiceMap::const_iterator it = |
688 alternative_service_map_.Get(server); | 709 alternative_service_map_.Get(server); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 817 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
797 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 818 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
798 FROM_HERE, | 819 FROM_HERE, |
799 base::Bind( | 820 base::Bind( |
800 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 821 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
801 weak_ptr_factory_.GetWeakPtr()), | 822 weak_ptr_factory_.GetWeakPtr()), |
802 delay); | 823 delay); |
803 } | 824 } |
804 | 825 |
805 } // namespace net | 826 } // namespace net |
OLD | NEW |