Index: chrome/browser/net/http_server_properties_manager.cc |
diff --git a/chrome/browser/net/http_server_properties_manager.cc b/chrome/browser/net/http_server_properties_manager.cc |
index 08f8ee2df5fb59edf7e4ec79c3f549d97b9f83c2..c24e588770ae4f7c6e32ca548840150168d55744 100644 |
--- a/chrome/browser/net/http_server_properties_manager.cc |
+++ b/chrome/browser/net/http_server_properties_manager.cc |
@@ -43,6 +43,9 @@ const int kVersionNumber = 2; |
typedef std::vector<std::string> StringVector; |
+// Persist 200 MRU AlternateProtocolHostPortPairs. |
+const int kMaxAlternateProtocolHostsToPersist = 200; |
+ |
} // namespace |
//////////////////////////////////////////////////////////////////////////////// |
@@ -148,14 +151,14 @@ void HttpServerPropertiesManager::SetSupportsSpdy( |
} |
bool HttpServerPropertiesManager::HasAlternateProtocol( |
- const net::HostPortPair& server) const { |
+ const net::HostPortPair& server) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
return http_server_properties_impl_->HasAlternateProtocol(server); |
} |
net::PortAlternateProtocolPair |
HttpServerPropertiesManager::GetAlternateProtocol( |
- const net::HostPortPair& server) const { |
+ const net::HostPortPair& server) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
return http_server_properties_impl_->GetAlternateProtocol(server); |
} |
@@ -327,7 +330,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() { |
scoped_ptr<net::PipelineCapabilityMap> pipeline_capability_map( |
new net::PipelineCapabilityMap); |
scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( |
- new net::AlternateProtocolMap); |
+ new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); |
it.Advance()) { |
@@ -393,7 +396,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() { |
} |
// Get alternate_protocol server. |
- DCHECK(!ContainsKey(*alternate_protocol_map, server)); |
+ DCHECK(alternate_protocol_map->Peek(server) == |
+ alternate_protocol_map->end()); |
const base::DictionaryValue* port_alternate_protocol_dict = NULL; |
if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
"alternate_protocol", &port_alternate_protocol_dict)) { |
@@ -427,7 +431,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() { |
port_alternate_protocol.port = port; |
port_alternate_protocol.protocol = protocol; |
- (*alternate_protocol_map)[server] = port_alternate_protocol; |
+ alternate_protocol_map->Put(server, port_alternate_protocol); |
} while (false); |
} |
@@ -516,9 +520,15 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO( |
*spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); |
net::AlternateProtocolMap* alternate_protocol_map = |
- new net::AlternateProtocolMap; |
- *alternate_protocol_map = |
+ new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); |
+ const net::AlternateProtocolMap& map = |
http_server_properties_impl_->alternate_protocol_map(); |
+ int count = 0; |
+ for (net::AlternateProtocolMap::const_iterator it = map.begin(); |
+ it != map.end() && count < kMaxAlternateProtocolHostsToPersist; |
+ ++it, ++count) { |
+ alternate_protocol_map->Put(it->first, it->second); |
+ } |
net::PipelineCapabilityMap* pipeline_capability_map = |
new net::PipelineCapabilityMap; |
@@ -569,6 +579,8 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI( |
net::PipelineCapabilityMap* pipeline_capability_map, |
const base::Closure& completion) { |
+ // TODO(rtenneti): Fix ServerPrefMap to preserve MRU order of |
+ // alternate_protocol_map and pipeline_capability_map. |
typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; |
ServerPrefMap server_pref_map; |
@@ -592,8 +604,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI( |
} |
// Add servers that have SpdySettings to server_pref_map. |
- for (net::SpdySettingsMap::iterator map_it = |
- spdy_settings_map->begin(); |
+ for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
map_it != spdy_settings_map->end(); ++map_it) { |
const net::HostPortPair& server = map_it->first; |
@@ -608,7 +619,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI( |
// Add AlternateProtocol servers to server_pref_map. |
for (net::AlternateProtocolMap::const_iterator map_it = |
- alternate_protocol_map->begin(); |
+ alternate_protocol_map->begin(); |
map_it != alternate_protocol_map->end(); ++map_it) { |
const net::HostPortPair& server = map_it->first; |
const net::PortAlternateProtocolPair& port_alternate_protocol = |