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