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 "chrome/browser/net/http_server_properties_manager.h" | 5 #include "chrome/browser/net/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 // "version" 0 indicates, http_server_properties doesn't have "version" | 37 // "version" 0 indicates, http_server_properties doesn't have "version" |
| 38 // property. | 38 // property. |
| 39 const int kMissingVersion = 0; | 39 const int kMissingVersion = 0; |
| 40 | 40 |
| 41 // The version number of persisted http_server_properties. | 41 // The version number of persisted http_server_properties. |
| 42 const int kVersionNumber = 2; | 42 const int kVersionNumber = 2; |
| 43 | 43 |
| 44 typedef std::vector<std::string> StringVector; | 44 typedef std::vector<std::string> StringVector; |
| 45 | 45 |
| 46 // Persist 200 MRU AlternateProtocolHostPortPairs. | |
| 47 const int kMaxAlternateProtocolHostsToPersist = 200; | |
| 48 | |
| 46 } // namespace | 49 } // namespace |
| 47 | 50 |
| 48 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
| 49 // HttpServerPropertiesManager | 52 // HttpServerPropertiesManager |
| 50 | 53 |
| 51 HttpServerPropertiesManager::HttpServerPropertiesManager( | 54 HttpServerPropertiesManager::HttpServerPropertiesManager( |
| 52 PrefService* pref_service) | 55 PrefService* pref_service) |
| 53 : pref_service_(pref_service), | 56 : pref_service_(pref_service), |
| 54 setting_prefs_(false) { | 57 setting_prefs_(false) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 ScheduleUpdatePrefsOnIO(); | 173 ScheduleUpdatePrefsOnIO(); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 176 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
| 174 const net::HostPortPair& server) { | 177 const net::HostPortPair& server) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 176 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 179 http_server_properties_impl_->SetBrokenAlternateProtocol(server); |
| 177 ScheduleUpdatePrefsOnIO(); | 180 ScheduleUpdatePrefsOnIO(); |
| 178 } | 181 } |
| 179 | 182 |
| 180 const net::AlternateProtocolMap& | 183 net::AlternateProtocolMap |
| 181 HttpServerPropertiesManager::alternate_protocol_map() const { | 184 HttpServerPropertiesManager::GetAlternateProtocolMap() const { |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 183 return http_server_properties_impl_->alternate_protocol_map(); | 186 return http_server_properties_impl_->GetAlternateProtocolMap(); |
| 184 } | 187 } |
| 185 | 188 |
| 186 const net::SettingsMap& | 189 const net::SettingsMap& |
| 187 HttpServerPropertiesManager::GetSpdySettings( | 190 HttpServerPropertiesManager::GetSpdySettings( |
| 188 const net::HostPortPair& host_port_pair) const { | 191 const net::HostPortPair& host_port_pair) const { |
| 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 190 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 193 return http_server_properties_impl_->GetSpdySettings(host_port_pair); |
| 191 } | 194 } |
| 192 | 195 |
| 193 bool HttpServerPropertiesManager::SetSpdySetting( | 196 bool HttpServerPropertiesManager::SetSpdySetting( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 | 507 |
| 505 base::ListValue* spdy_server_list = new base::ListValue; | 508 base::ListValue* spdy_server_list = new base::ListValue; |
| 506 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); | 509 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); |
| 507 | 510 |
| 508 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; | 511 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; |
| 509 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); | 512 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); |
| 510 | 513 |
| 511 net::AlternateProtocolMap* alternate_protocol_map = | 514 net::AlternateProtocolMap* alternate_protocol_map = |
| 512 new net::AlternateProtocolMap; | 515 new net::AlternateProtocolMap; |
| 513 *alternate_protocol_map = | 516 *alternate_protocol_map = |
| 514 http_server_properties_impl_->alternate_protocol_map(); | 517 http_server_properties_impl_->GetAlternateProtocolMap(); |
| 515 | 518 |
| 516 net::PipelineCapabilityMap* pipeline_capability_map = | 519 net::PipelineCapabilityMap* pipeline_capability_map = |
| 517 new net::PipelineCapabilityMap; | 520 new net::PipelineCapabilityMap; |
| 518 *pipeline_capability_map = | 521 *pipeline_capability_map = |
| 519 http_server_properties_impl_->GetPipelineCapabilityMap(); | 522 http_server_properties_impl_->GetPipelineCapabilityMap(); |
| 520 | 523 |
| 521 // Update the preferences on the UI thread. | 524 // Update the preferences on the UI thread. |
| 522 BrowserThread::PostTask( | 525 BrowserThread::PostTask( |
| 523 BrowserThread::UI, | 526 BrowserThread::UI, |
| 524 FROM_HERE, | 527 FROM_HERE, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 if (it == server_pref_map.end()) { | 581 if (it == server_pref_map.end()) { |
| 579 ServerPref server_pref(true, NULL, NULL); | 582 ServerPref server_pref(true, NULL, NULL); |
| 580 server_pref_map[server] = server_pref; | 583 server_pref_map[server] = server_pref; |
| 581 } else { | 584 } else { |
| 582 it->second.supports_spdy = true; | 585 it->second.supports_spdy = true; |
| 583 } | 586 } |
| 584 } | 587 } |
| 585 } | 588 } |
| 586 | 589 |
| 587 // Add servers that have SpdySettings to server_pref_map. | 590 // Add servers that have SpdySettings to server_pref_map. |
| 588 for (net::SpdySettingsMap::iterator map_it = | 591 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
| 589 spdy_settings_map->begin(); | |
| 590 map_it != spdy_settings_map->end(); ++map_it) { | 592 map_it != spdy_settings_map->end(); ++map_it) { |
| 591 const net::HostPortPair& server = map_it->first; | 593 const net::HostPortPair& server = map_it->first; |
| 592 | 594 |
| 593 ServerPrefMap::iterator it = server_pref_map.find(server); | 595 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 594 if (it == server_pref_map.end()) { | 596 if (it == server_pref_map.end()) { |
| 595 ServerPref server_pref(false, &map_it->second, NULL); | 597 ServerPref server_pref(false, &map_it->second, NULL); |
| 596 server_pref_map[server] = server_pref; | 598 server_pref_map[server] = server_pref; |
| 597 } else { | 599 } else { |
| 598 it->second.settings_map = &map_it->second; | 600 it->second.settings_map = &map_it->second; |
| 599 } | 601 } |
| 600 } | 602 } |
| 601 | 603 |
| 602 // Add AlternateProtocol servers to server_pref_map. | 604 // Add AlternateProtocol servers to server_pref_map. |
| 605 int count = 0; | |
| 603 for (net::AlternateProtocolMap::const_iterator map_it = | 606 for (net::AlternateProtocolMap::const_iterator map_it = |
|
Ryan Hamilton
2014/03/05 00:19:20
What guarantee do we have that this iterator is go
ramant (doing other things)
2014/03/05 15:11:11
Many thanks for the catch. My fault (had only 200
| |
| 604 alternate_protocol_map->begin(); | 607 alternate_protocol_map->begin(); |
| 605 map_it != alternate_protocol_map->end(); ++map_it) { | 608 map_it != alternate_protocol_map->end() && |
| 609 count < kMaxAlternateProtocolHostsToPersist; | |
| 610 ++map_it) { | |
| 606 const net::HostPortPair& server = map_it->first; | 611 const net::HostPortPair& server = map_it->first; |
| 607 const net::PortAlternateProtocolPair& port_alternate_protocol = | 612 const net::PortAlternateProtocolPair& port_alternate_protocol = |
| 608 map_it->second; | 613 map_it->second; |
| 609 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 614 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
| 610 continue; | 615 continue; |
| 611 } | 616 } |
| 612 | 617 |
| 613 ServerPrefMap::iterator it = server_pref_map.find(server); | 618 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 614 if (it == server_pref_map.end()) { | 619 if (it == server_pref_map.end()) { |
| 615 ServerPref server_pref(false, NULL, &map_it->second); | 620 ServerPref server_pref(false, NULL, &map_it->second); |
| 616 server_pref_map[server] = server_pref; | 621 server_pref_map[server] = server_pref; |
| 617 } else { | 622 } else { |
| 618 it->second.alternate_protocol = &map_it->second; | 623 it->second.alternate_protocol = &map_it->second; |
| 619 } | 624 } |
| 625 ++count; | |
| 620 } | 626 } |
| 621 | 627 |
| 622 for (net::PipelineCapabilityMap::const_iterator map_it = | 628 for (net::PipelineCapabilityMap::const_iterator map_it = |
| 623 pipeline_capability_map->begin(); | 629 pipeline_capability_map->begin(); |
| 624 map_it != pipeline_capability_map->end(); ++map_it) { | 630 map_it != pipeline_capability_map->end(); ++map_it) { |
| 625 const net::HostPortPair& server = map_it->first; | 631 const net::HostPortPair& server = map_it->first; |
| 626 const net::HttpPipelinedHostCapability& pipeline_capability = | 632 const net::HttpPipelinedHostCapability& pipeline_capability = |
| 627 map_it->second; | 633 map_it->second; |
| 628 | 634 |
| 629 ServerPrefMap::iterator it = server_pref_map.find(server); | 635 ServerPrefMap::iterator it = server_pref_map.find(server); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 completion.Run(); | 708 completion.Run(); |
| 703 } | 709 } |
| 704 | 710 |
| 705 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 711 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 707 if (!setting_prefs_) | 713 if (!setting_prefs_) |
| 708 ScheduleUpdateCacheOnUI(); | 714 ScheduleUpdateCacheOnUI(); |
| 709 } | 715 } |
| 710 | 716 |
| 711 } // namespace chrome_browser_net | 717 } // namespace chrome_browser_net |
| OLD | NEW |