| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 return http_server_properties_impl_->alternative_service_map(); | 282 return http_server_properties_impl_->alternative_service_map(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 std::unique_ptr<base::Value> | 285 std::unique_ptr<base::Value> |
| 286 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() const { | 286 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() const { |
| 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 288 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); | 288 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( | 291 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
| 292 const HostPortPair& host_port_pair) { | 292 const url::SchemeHostPort& server) { |
| 293 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 293 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 294 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 294 return http_server_properties_impl_->GetSpdySettings(server); |
| 295 } | 295 } |
| 296 | 296 |
| 297 bool HttpServerPropertiesManager::SetSpdySetting( | 297 bool HttpServerPropertiesManager::SetSpdySetting( |
| 298 const HostPortPair& host_port_pair, | 298 const url::SchemeHostPort& server, |
| 299 SpdySettingsIds id, | 299 SpdySettingsIds id, |
| 300 SpdySettingsFlags flags, | 300 SpdySettingsFlags flags, |
| 301 uint32_t value) { | 301 uint32_t value) { |
| 302 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 302 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 303 bool persist = http_server_properties_impl_->SetSpdySetting( | 303 bool persist = |
| 304 host_port_pair, id, flags, value); | 304 http_server_properties_impl_->SetSpdySetting(server, id, flags, value); |
| 305 if (persist) | 305 if (persist) |
| 306 ScheduleUpdatePrefsOnNetworkThread(SET_SPDY_SETTING); | 306 ScheduleUpdatePrefsOnNetworkThread(SET_SPDY_SETTING); |
| 307 return persist; | 307 return persist; |
| 308 } | 308 } |
| 309 | 309 |
| 310 void HttpServerPropertiesManager::ClearSpdySettings( | 310 void HttpServerPropertiesManager::ClearSpdySettings( |
| 311 const HostPortPair& host_port_pair) { | 311 const url::SchemeHostPort& server) { |
| 312 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 312 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 313 http_server_properties_impl_->ClearSpdySettings(host_port_pair); | 313 http_server_properties_impl_->ClearSpdySettings(server); |
| 314 ScheduleUpdatePrefsOnNetworkThread(CLEAR_SPDY_SETTINGS); | 314 ScheduleUpdatePrefsOnNetworkThread(CLEAR_SPDY_SETTINGS); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void HttpServerPropertiesManager::ClearAllSpdySettings() { | 317 void HttpServerPropertiesManager::ClearAllSpdySettings() { |
| 318 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 318 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 319 http_server_properties_impl_->ClearAllSpdySettings(); | 319 http_server_properties_impl_->ClearAllSpdySettings(); |
| 320 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALL_SPDY_SETTINGS); | 320 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALL_SPDY_SETTINGS); |
| 321 } | 321 } |
| 322 | 322 |
| 323 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() | 323 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 SpdySettingsMap* spdy_settings_map, | 547 SpdySettingsMap* spdy_settings_map, |
| 548 AlternativeServiceMap* alternative_service_map, | 548 AlternativeServiceMap* alternative_service_map, |
| 549 ServerNetworkStatsMap* network_stats_map) { | 549 ServerNetworkStatsMap* network_stats_map) { |
| 550 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); | 550 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); |
| 551 it.Advance()) { | 551 it.Advance()) { |
| 552 // TODO(zhongyi): get server's scheme/host/port when servers_dict migrates | 552 // TODO(zhongyi): get server's scheme/host/port when servers_dict migrates |
| 553 // to SchemeHostPort. | 553 // to SchemeHostPort. |
| 554 // Get server's host/pair. | 554 // Get server's host/pair. |
| 555 const std::string& server_str = it.key(); | 555 const std::string& server_str = it.key(); |
| 556 HostPortPair server = HostPortPair::FromString(server_str); | 556 HostPortPair server = HostPortPair::FromString(server_str); |
| 557 // TODO(zhongyi): fill in the scheme field when servers_dict has scheme. |
| 558 std::string spdy_server_url = "https://" + server_str; |
| 559 url::SchemeHostPort spdy_server((GURL(spdy_server_url))); |
| 557 if (server.host().empty()) { | 560 if (server.host().empty()) { |
| 558 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 561 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
| 559 return false; | 562 return false; |
| 560 } | 563 } |
| 561 | 564 |
| 562 const base::DictionaryValue* server_pref_dict = nullptr; | 565 const base::DictionaryValue* server_pref_dict = nullptr; |
| 563 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 566 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
| 564 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 567 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
| 565 return false; | 568 return false; |
| 566 } | 569 } |
| 567 | 570 |
| 568 // Get if server supports Spdy. | 571 // Get if server supports Spdy. |
| 569 bool supports_spdy = false; | 572 bool supports_spdy = false; |
| 570 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 573 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
| 571 supports_spdy) { | 574 supports_spdy) { |
| 572 // TODO(zhongyi): fill in the scheme field when servers_dict has scheme. | |
| 573 std::string spdy_server_url = "https://" + server_str; | |
| 574 url::SchemeHostPort spdy_server((GURL(spdy_server_url))); | |
| 575 spdy_servers->push_back(spdy_server.Serialize()); | 575 spdy_servers->push_back(spdy_server.Serialize()); |
| 576 } | 576 } |
| 577 | 577 |
| 578 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map); | 578 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map); |
| 579 if (!AddToAlternativeServiceMap(server, *server_pref_dict, | 579 if (!AddToAlternativeServiceMap(server, *server_pref_dict, |
| 580 alternative_service_map) || | 580 alternative_service_map) || |
| 581 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { | 581 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { |
| 582 return false; | 582 return false; |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 return true; | 585 return true; |
| 586 } | 586 } |
| 587 | 587 |
| 588 void HttpServerPropertiesManager::AddToSpdySettingsMap( | 588 void HttpServerPropertiesManager::AddToSpdySettingsMap( |
| 589 const HostPortPair& server, | 589 const url::SchemeHostPort& server, |
| 590 const base::DictionaryValue& server_pref_dict, | 590 const base::DictionaryValue& server_pref_dict, |
| 591 SpdySettingsMap* spdy_settings_map) { | 591 SpdySettingsMap* spdy_settings_map) { |
| 592 // Get SpdySettings. | 592 // Get SpdySettings. |
| 593 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 593 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
| 594 const base::DictionaryValue* spdy_settings_dict = nullptr; | 594 const base::DictionaryValue* spdy_settings_dict = nullptr; |
| 595 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 595 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 596 kSettingsKey, &spdy_settings_dict)) { | 596 kSettingsKey, &spdy_settings_dict)) { |
| 597 return; | 597 return; |
| 598 } | 598 } |
| 599 SettingsMap settings_map; | 599 SettingsMap settings_map; |
| 600 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); | 600 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); |
| 601 !dict_it.IsAtEnd(); dict_it.Advance()) { | 601 !dict_it.IsAtEnd(); dict_it.Advance()) { |
| 602 const std::string& id_str = dict_it.key(); | 602 const std::string& id_str = dict_it.key(); |
| 603 int id = 0; | 603 int id = 0; |
| 604 if (!base::StringToInt(id_str, &id)) { | 604 if (!base::StringToInt(id_str, &id)) { |
| 605 DVLOG(1) << "Malformed id in SpdySettings for server: " | 605 DVLOG(1) << "Malformed id in SpdySettings for server: " |
| 606 << server.ToString(); | 606 << server.Serialize(); |
| 607 NOTREACHED(); | 607 NOTREACHED(); |
| 608 continue; | 608 continue; |
| 609 } | 609 } |
| 610 int value = 0; | 610 int value = 0; |
| 611 if (!dict_it.value().GetAsInteger(&value)) { | 611 if (!dict_it.value().GetAsInteger(&value)) { |
| 612 DVLOG(1) << "Malformed value in SpdySettings for server: " | 612 DVLOG(1) << "Malformed value in SpdySettings for server: " |
| 613 << server.ToString(); | 613 << server.Serialize(); |
| 614 NOTREACHED(); | 614 NOTREACHED(); |
| 615 continue; | 615 continue; |
| 616 } | 616 } |
| 617 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 617 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
| 618 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; | 618 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; |
| 619 } | 619 } |
| 620 spdy_settings_map->Put(server, settings_map); | 620 spdy_settings_map->Put(server, settings_map); |
| 621 } | 621 } |
| 622 | 622 |
| 623 bool HttpServerPropertiesManager::ParseAlternativeServiceDict( | 623 bool HttpServerPropertiesManager::ParseAlternativeServiceDict( |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 server_pref_map.Put(server, server_pref); | 1053 server_pref_map.Put(server, server_pref); |
| 1054 } else { | 1054 } else { |
| 1055 it->second.supports_spdy = true; | 1055 it->second.supports_spdy = true; |
| 1056 } | 1056 } |
| 1057 } | 1057 } |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 // Add servers that have SpdySettings to server_pref_map in the MRU order. | 1060 // Add servers that have SpdySettings to server_pref_map in the MRU order. |
| 1061 for (SpdySettingsMap::reverse_iterator map_it = spdy_settings_map->rbegin(); | 1061 for (SpdySettingsMap::reverse_iterator map_it = spdy_settings_map->rbegin(); |
| 1062 map_it != spdy_settings_map->rend(); ++map_it) { | 1062 map_it != spdy_settings_map->rend(); ++map_it) { |
| 1063 const HostPortPair& server = map_it->first; | 1063 // TODO(zhongyi): use memory data once disk data is migrated. |
| 1064 const url::SchemeHostPort spdy_server = map_it->first; |
| 1065 const HostPortPair server(spdy_server.host(), spdy_server.port()); |
| 1064 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1066 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1065 if (it == server_pref_map.end()) { | 1067 if (it == server_pref_map.end()) { |
| 1066 ServerPref server_pref; | 1068 ServerPref server_pref; |
| 1067 server_pref.settings_map = &map_it->second; | 1069 server_pref.settings_map = &map_it->second; |
| 1068 server_pref_map.Put(server, server_pref); | 1070 server_pref_map.Put(server, server_pref); |
| 1069 } else { | 1071 } else { |
| 1070 it->second.settings_map = &map_it->second; | 1072 it->second.settings_map = &map_it->second; |
| 1071 } | 1073 } |
| 1072 } | 1074 } |
| 1073 | 1075 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 quic_servers_dict); | 1249 quic_servers_dict); |
| 1248 } | 1250 } |
| 1249 | 1251 |
| 1250 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1252 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 1251 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1253 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1252 if (!setting_prefs_) | 1254 if (!setting_prefs_) |
| 1253 ScheduleUpdateCacheOnPrefThread(); | 1255 ScheduleUpdateCacheOnPrefThread(); |
| 1254 } | 1256 } |
| 1255 | 1257 |
| 1256 } // namespace net | 1258 } // namespace net |
| OLD | NEW |