diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-08-14 11:38:45 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-08-14 17:16:47 +0000 |
commit | 3a97ca8dd9b96b599ae2d33e40df0dd2f7ea5859 (patch) | |
tree | 43cc572ba067417c7341db81f71ae7cc6e0fcc3e /chromium/net/http/http_server_properties_manager.cc | |
parent | f61ab1ac7f855cd281809255c0aedbb1895e1823 (diff) | |
download | qtwebengine-chromium-3a97ca8dd9b96b599ae2d33e40df0dd2f7ea5859.tar.gz |
BASELINE: Update chromium to 45.0.2454.40
Change-Id: Id2121d9f11a8fc633677236c65a3e41feef589e4
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/net/http/http_server_properties_manager.cc')
-rw-r--r-- | chromium/net/http/http_server_properties_manager.cc | 191 |
1 files changed, 110 insertions, 81 deletions
diff --git a/chromium/net/http/http_server_properties_manager.cc b/chromium/net/http/http_server_properties_manager.cc index 669b091d13c..d89efab5a41 100644 --- a/chromium/net/http/http_server_properties_manager.cc +++ b/chromium/net/http/http_server_properties_manager.cc @@ -5,7 +5,7 @@ #include "net/http/http_server_properties_manager.h" #include "base/bind.h" -#include "base/metrics/histogram.h" +#include "base/metrics/histogram_macros.h" #include "base/prefs/pref_service.h" #include "base/single_thread_task_runner.h" #include "base/stl_util.h" @@ -13,7 +13,7 @@ #include "base/strings/stringprintf.h" #include "base/thread_task_runner_handle.h" #include "base/values.h" -#include "net/base/net_util.h" +#include "net/base/ip_address_number.h" namespace net { @@ -190,26 +190,35 @@ void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); } -AlternativeService HttpServerPropertiesManager::GetAlternativeService( +AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( const HostPortPair& origin) { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); - return http_server_properties_impl_->GetAlternativeService(origin); + return http_server_properties_impl_->GetAlternativeServices(origin); } -void HttpServerPropertiesManager::SetAlternativeService( +bool HttpServerPropertiesManager::SetAlternativeService( const HostPortPair& origin, const AlternativeService& alternative_service, double alternative_probability) { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); - AlternativeService old_alternative_service = GetAlternativeService(origin); - http_server_properties_impl_->SetAlternativeService( + const bool changed = http_server_properties_impl_->SetAlternativeService( origin, alternative_service, alternative_probability); - AlternativeService new_alternative_service = GetAlternativeService(origin); - // If |alternative_probability| was above the threashold now it is below or - // vice versa, then a different alternative_service will be returned from the - // old and if so, then persist. - if (old_alternative_service != new_alternative_service) - ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICE); + if (changed) { + ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); + } + return changed; +} + +bool HttpServerPropertiesManager::SetAlternativeServices( + const HostPortPair& origin, + const AlternativeServiceInfoVector& alternative_service_info_vector) { + DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); + const bool changed = http_server_properties_impl_->SetAlternativeServices( + origin, alternative_service_info_vector); + if (changed) { + ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); + } + return changed; } void HttpServerPropertiesManager::MarkAlternativeServiceBroken( @@ -256,13 +265,13 @@ void HttpServerPropertiesManager::ConfirmAlternativeService( ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); } -void HttpServerPropertiesManager::ClearAlternativeService( +void HttpServerPropertiesManager::ClearAlternativeServices( const HostPortPair& origin) { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); const AlternativeServiceMap& map = http_server_properties_impl_->alternative_service_map(); size_t old_size = map.size(); - http_server_properties_impl_->ClearAlternativeService(origin); + http_server_properties_impl_->ClearAlternativeServices(origin); size_t new_size = map.size(); // Persist only if we have deleted an entry. if (old_size != new_size) @@ -275,7 +284,8 @@ HttpServerPropertiesManager::alternative_service_map() const { return http_server_properties_impl_->alternative_service_map(); } -base::Value* HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() +scoped_ptr<base::Value> +HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() const { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); @@ -572,21 +582,23 @@ bool HttpServerPropertiesManager::AddToAlternativeServiceMap( // Get alternative_services... const base::ListValue* alternative_service_list; const base::DictionaryValue* alternative_service_dict; - AlternativeServiceInfo alternative_service_info; + AlternativeServiceInfoVector alternative_service_info_vector; if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey, &alternative_service_list)) { - if (alternative_service_list->empty()) { - return false; + for (const base::Value* alternative_service_list_item : + *alternative_service_list) { + if (!alternative_service_list_item->GetAsDictionary( + &alternative_service_dict)) + return false; + AlternativeServiceInfo alternative_service_info = + ParseAlternativeServiceDict(*alternative_service_dict, + server.ToString()); + if (alternative_service_info.alternative_service.protocol == + UNINITIALIZED_ALTERNATE_PROTOCOL) { + return false; + } + alternative_service_info_vector.push_back(alternative_service_info); } - // Get first element of the list. - // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, read - // all of them. - if (!alternative_service_list->GetDictionary(0, - &alternative_service_dict)) { - return false; - } - alternative_service_info = ParseAlternativeServiceDict( - *alternative_service_dict, server.ToString()); } else { // ...or alternate_protocol. // TODO(bnc): Remove this in M46, we do not need preference migration for @@ -595,15 +607,21 @@ bool HttpServerPropertiesManager::AddToAlternativeServiceMap( kAlternateProtocolKey, &alternative_service_dict)) { return true; } - alternative_service_info = ParseAlternativeServiceDict( - *alternative_service_dict, server.ToString()); + AlternativeServiceInfo alternative_service_info = + ParseAlternativeServiceDict(*alternative_service_dict, + server.ToString()); + if (alternative_service_info.alternative_service.protocol == + UNINITIALIZED_ALTERNATE_PROTOCOL) { + return false; + } + alternative_service_info_vector.push_back(alternative_service_info); } - if (alternative_service_info.alternative_service.protocol == - UNINITIALIZED_ALTERNATE_PROTOCOL) { + if (alternative_service_info_vector.empty()) { return false; } - alternative_service_map->Put(server, alternative_service_info); + + alternative_service_map->Put(server, alternative_service_info_vector); return true; } @@ -678,7 +696,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( http_server_properties_impl_->InitializeSpdySettingsServers( spdy_settings_map); - // Update the cached data and use the new Alternate-Protocol server list from + // Update the cached data and use the new alternative service list from // preferences. UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", alternative_service_map->size()); @@ -754,20 +772,29 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( CanonicalHostPersistedMap persisted_map; for (AlternativeServiceMap::const_iterator it = map.begin(); it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { - const AlternativeServiceInfo& alternative_service_info = it->second; - if (!IsAlternateProtocolValid( - alternative_service_info.alternative_service.protocol)) { - continue; - } const HostPortPair& server = it->first; - AlternativeService alternative_service( - alternative_service_info.alternative_service); - if (alternative_service.host.empty()) { - alternative_service.host = server.host(); + AlternativeServiceInfoVector notbroken_alternative_service_info_vector; + for (const AlternativeServiceInfo& alternative_service_info : it->second) { + if (!IsAlternateProtocolValid( + alternative_service_info.alternative_service.protocol)) { + continue; + } + AlternativeService alternative_service( + alternative_service_info.alternative_service); + if (alternative_service.host.empty()) { + alternative_service.host = server.host(); + } + if (IsAlternativeServiceBroken(alternative_service)) { + continue; + } + notbroken_alternative_service_info_vector.push_back( + alternative_service_info); } - if (IsAlternativeServiceBroken(alternative_service)) { + if (notbroken_alternative_service_info_vector.empty()) { continue; } + alternative_service_map->Put(server, + notbroken_alternative_service_info_vector); std::string canonical_suffix = http_server_properties_impl_->GetCanonicalSuffix(server.host()); if (!canonical_suffix.empty()) { @@ -775,7 +802,6 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( continue; persisted_map[canonical_suffix] = true; } - alternative_service_map->Put(server, alternative_service_info); ++count; } @@ -802,28 +828,29 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( } // A local or temporary data structure to hold |supports_spdy|, SpdySettings, -// AlternativeServiceInfo and SupportsQuic preferences for a server. This is -// used only in UpdatePrefsOnPrefThread. +// AlternativeServiceInfoVector, and SupportsQuic preferences for a server. This +// is used only in UpdatePrefsOnPrefThread. struct ServerPref { ServerPref() : supports_spdy(false), settings_map(NULL), - alternative_service(NULL), + alternative_service_info_vector(NULL), supports_quic(NULL), server_network_stats(NULL) {} - ServerPref(bool supports_spdy, - const SettingsMap* settings_map, - const AlternativeServiceInfo* alternative_service, - const SupportsQuic* supports_quic, - const ServerNetworkStats* server_network_stats) + ServerPref( + bool supports_spdy, + const SettingsMap* settings_map, + const AlternativeServiceInfoVector* alternative_service_info_vector, + const SupportsQuic* supports_quic, + const ServerNetworkStats* server_network_stats) : supports_spdy(supports_spdy), settings_map(settings_map), - alternative_service(alternative_service), + alternative_service_info_vector(alternative_service_info_vector), supports_quic(supports_quic), server_network_stats(server_network_stats) {} bool supports_spdy; const SettingsMap* settings_map; - const AlternativeServiceInfo* alternative_service; + const AlternativeServiceInfoVector* alternative_service_info_vector; const SupportsQuic* supports_quic; const ServerNetworkStats* server_network_stats; }; @@ -858,11 +885,12 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( server_pref_map[server].settings_map = &map_it->second; } - // Add AlternateProtocol servers to server_pref_map. + // Add alternative services to server_pref_map. for (AlternativeServiceMap::const_iterator map_it = alternative_service_map->begin(); map_it != alternative_service_map->end(); ++map_it) { - server_pref_map[map_it->first].alternative_service = &map_it->second; + server_pref_map[map_it->first].alternative_service_info_vector = + &map_it->second; } // Add ServerNetworkStats servers to server_pref_map. @@ -888,8 +916,8 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( if (server_pref.supports_spdy) server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); - SaveAlternativeServiceToServerPrefs(server_pref.alternative_service, - server_pref_dict); + SaveAlternativeServiceToServerPrefs( + server_pref.alternative_service_info_vector, server_pref_dict); SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, server_pref_dict); @@ -932,32 +960,33 @@ void HttpServerPropertiesManager::SaveSpdySettingsToServerPrefs( } void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( - const AlternativeServiceInfo* alternative_service_info, + const AlternativeServiceInfoVector* alternative_service_info_vector, base::DictionaryValue* server_pref_dict) { - if (!alternative_service_info) + if (!alternative_service_info_vector || + alternative_service_info_vector->empty()) { return; - - const AlternativeService& alternative_service = - alternative_service_info->alternative_service; - base::DictionaryValue* alternative_service_info_dict = - new base::DictionaryValue; - alternative_service_info_dict->SetString( - kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); - if (!alternative_service.host.empty()) { - alternative_service_info_dict->SetString(kHostKey, - alternative_service.host); } - alternative_service_info_dict->SetInteger(kPortKey, alternative_service.port); - alternative_service_info_dict->SetDouble( - kProbabilityKey, alternative_service_info->probability); - - // Create a single element list here. - // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, save - // all of them. - base::ListValue* alternative_service_list = new base::ListValue(); - alternative_service_list->Append(alternative_service_info_dict); + scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); + for (const AlternativeServiceInfo& alternative_service_info : + *alternative_service_info_vector) { + const AlternativeService alternative_service = + alternative_service_info.alternative_service; + DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); + base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; + alternative_service_dict->SetInteger(kPortKey, alternative_service.port); + if (!alternative_service.host.empty()) { + alternative_service_dict->SetString(kHostKey, alternative_service.host); + } + alternative_service_dict->SetString( + kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); + alternative_service_dict->SetDouble(kProbabilityKey, + alternative_service_info.probability); + alternative_service_list->Append(alternative_service_dict); + } + if (alternative_service_list->GetSize() == 0) + return; server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, - alternative_service_list); + alternative_service_list.release()); } void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |