Chromium Code Reviews| 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.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 http_server_properties_impl_->ClearAllSpdySettings(); | 275 http_server_properties_impl_->ClearAllSpdySettings(); |
| 276 ScheduleUpdatePrefsOnNetworkThread(); | 276 ScheduleUpdatePrefsOnNetworkThread(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() | 279 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
| 280 const { | 280 const { |
| 281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 282 return http_server_properties_impl_->spdy_settings_map(); | 282 return http_server_properties_impl_->spdy_settings_map(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 SupportsQuic HttpServerPropertiesManager::GetSupportsQuic( | 285 bool HttpServerPropertiesManager::GetSupportsQuic( |
| 286 const HostPortPair& host_port_pair) const { | 286 IPAddressNumber* last_address) const { |
| 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 288 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); | 288 return http_server_properties_impl_->GetSupportsQuic(last_address); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void HttpServerPropertiesManager::SetSupportsQuic( | 291 void HttpServerPropertiesManager::SetSupportsQuic( |
| 292 const HostPortPair& host_port_pair, | |
| 293 bool used_quic, | 292 bool used_quic, |
| 294 const std::string& address) { | 293 const IPAddressNumber& address) { |
| 295 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 294 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 296 http_server_properties_impl_->SetSupportsQuic( | 295 http_server_properties_impl_->SetSupportsQuic(used_quic, address); |
| 297 host_port_pair, used_quic, address); | |
| 298 ScheduleUpdatePrefsOnNetworkThread(); | 296 ScheduleUpdatePrefsOnNetworkThread(); |
| 299 } | 297 } |
| 300 | 298 |
| 301 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map() | |
| 302 const { | |
| 303 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | |
| 304 return http_server_properties_impl_->supports_quic_map(); | |
| 305 } | |
| 306 | |
| 307 void HttpServerPropertiesManager::SetServerNetworkStats( | 299 void HttpServerPropertiesManager::SetServerNetworkStats( |
| 308 const HostPortPair& host_port_pair, | 300 const HostPortPair& host_port_pair, |
| 309 ServerNetworkStats stats) { | 301 ServerNetworkStats stats) { |
| 310 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 302 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 311 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 303 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); |
| 312 ScheduleUpdatePrefsOnNetworkThread(); | 304 ScheduleUpdatePrefsOnNetworkThread(); |
| 313 } | 305 } |
| 314 | 306 |
| 315 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( | 307 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( |
| 316 const HostPortPair& host_port_pair) { | 308 const HostPortPair& host_port_pair) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 357 |
| 366 // The properties for a given server is in | 358 // The properties for a given server is in |
| 367 // http_server_properties_dict["servers"][server]. | 359 // http_server_properties_dict["servers"][server]. |
| 368 const base::DictionaryValue* servers_dict = NULL; | 360 const base::DictionaryValue* servers_dict = NULL; |
| 369 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 361 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
| 370 kServersKey, &servers_dict)) { | 362 kServersKey, &servers_dict)) { |
| 371 DVLOG(1) << "Malformed http_server_properties for servers."; | 363 DVLOG(1) << "Malformed http_server_properties for servers."; |
| 372 return; | 364 return; |
| 373 } | 365 } |
| 374 | 366 |
| 367 IPAddressNumber* addr = new IPAddressNumber; | |
| 368 ReadSupportsQuic(http_server_properties_dict, addr); | |
| 369 | |
| 375 // String is host/port pair of spdy server. | 370 // String is host/port pair of spdy server. |
| 376 scoped_ptr<StringVector> spdy_servers(new StringVector); | 371 scoped_ptr<StringVector> spdy_servers(new StringVector); |
| 377 scoped_ptr<SpdySettingsMap> spdy_settings_map( | 372 scoped_ptr<SpdySettingsMap> spdy_settings_map( |
| 378 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 373 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
| 379 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( | 374 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( |
| 380 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 375 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
| 381 scoped_ptr<SupportsQuicMap> supports_quic_map(new SupportsQuicMap()); | |
| 382 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( | 376 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( |
| 383 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); | 377 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); |
| 384 | 378 |
| 385 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); | 379 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); |
| 386 it.Advance()) { | 380 it.Advance()) { |
| 387 // Get server's host/pair. | 381 // Get server's host/pair. |
| 388 const std::string& server_str = it.key(); | 382 const std::string& server_str = it.key(); |
| 389 HostPortPair server = HostPortPair::FromString(server_str); | 383 HostPortPair server = HostPortPair::FromString(server_str); |
| 390 if (server.host().empty()) { | 384 if (server.host().empty()) { |
| 391 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 385 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 403 // Get if server supports Spdy. | 397 // Get if server supports Spdy. |
| 404 bool supports_spdy = false; | 398 bool supports_spdy = false; |
| 405 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 399 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
| 406 supports_spdy) { | 400 supports_spdy) { |
| 407 spdy_servers->push_back(server_str); | 401 spdy_servers->push_back(server_str); |
| 408 } | 402 } |
| 409 | 403 |
| 410 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); | 404 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); |
| 411 if (!AddToAlternateProtocolMap(server, *server_pref_dict, | 405 if (!AddToAlternateProtocolMap(server, *server_pref_dict, |
| 412 alternate_protocol_map.get()) || | 406 alternate_protocol_map.get()) || |
| 413 !AddToSupportsQuicMap(server, *server_pref_dict, | |
| 414 supports_quic_map.get()) || | |
| 415 !AddToNetworkStatsMap(server, *server_pref_dict, | 407 !AddToNetworkStatsMap(server, *server_pref_dict, |
| 416 server_network_stats_map.get())) { | 408 server_network_stats_map.get())) { |
| 417 detected_corrupted_prefs = true; | 409 detected_corrupted_prefs = true; |
| 418 } | 410 } |
| 419 } | 411 } |
| 420 | 412 |
| 421 network_task_runner_->PostTask( | 413 network_task_runner_->PostTask( |
| 422 FROM_HERE, | 414 FROM_HERE, |
| 423 base::Bind( | 415 base::Bind( |
| 424 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 416 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
| 425 base::Unretained(this), base::Owned(spdy_servers.release()), | 417 base::Unretained(this), base::Owned(spdy_servers.release()), |
| 426 base::Owned(spdy_settings_map.release()), | 418 base::Owned(spdy_settings_map.release()), |
| 427 base::Owned(alternate_protocol_map.release()), | 419 base::Owned(alternate_protocol_map.release()), base::Owned(addr), |
| 428 base::Owned(supports_quic_map.release()), | |
| 429 base::Owned(server_network_stats_map.release()), | 420 base::Owned(server_network_stats_map.release()), |
| 430 detected_corrupted_prefs)); | 421 detected_corrupted_prefs)); |
| 431 } | 422 } |
| 432 | 423 |
| 433 void HttpServerPropertiesManager::AddToSpdySettingsMap( | 424 void HttpServerPropertiesManager::AddToSpdySettingsMap( |
| 434 const HostPortPair& server, | 425 const HostPortPair& server, |
| 435 const base::DictionaryValue& server_pref_dict, | 426 const base::DictionaryValue& server_pref_dict, |
| 436 SpdySettingsMap* spdy_settings_map) { | 427 SpdySettingsMap* spdy_settings_map) { |
| 437 // Get SpdySettings. | 428 // Get SpdySettings. |
| 438 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 429 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString(); | 492 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString(); |
| 502 return false; | 493 return false; |
| 503 } | 494 } |
| 504 | 495 |
| 505 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), | 496 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), |
| 506 protocol, probability); | 497 protocol, probability); |
| 507 alternate_protocol_map->Put(server, port_alternate_protocol); | 498 alternate_protocol_map->Put(server, port_alternate_protocol); |
| 508 return true; | 499 return true; |
| 509 } | 500 } |
| 510 | 501 |
| 511 bool HttpServerPropertiesManager::AddToSupportsQuicMap( | 502 bool HttpServerPropertiesManager::ReadSupportsQuic( |
| 512 const HostPortPair& server, | 503 const base::DictionaryValue& http_server_properties_dict, |
| 513 const base::DictionaryValue& server_pref_dict, | 504 IPAddressNumber* last_quic_address) { |
| 514 SupportsQuicMap* supports_quic_map) { | |
| 515 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); | |
| 516 const base::DictionaryValue* supports_quic_dict = NULL; | 505 const base::DictionaryValue* supports_quic_dict = NULL; |
| 517 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 506 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
| 518 kSupportsQuicKey, &supports_quic_dict)) { | 507 kSupportsQuicKey, &supports_quic_dict)) { |
| 519 return true; | 508 return true; |
| 520 } | 509 } |
| 521 bool used_quic = 0; | 510 bool used_quic = false; |
| 522 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(kUsedQuicKey, | 511 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(kUsedQuicKey, |
| 523 &used_quic)) { | 512 &used_quic)) { |
| 524 DVLOG(1) << "Malformed SupportsQuic server: " << server.ToString(); | 513 DVLOG(1) << "Malformed SupportsQuic"; |
| 525 return false; | 514 return false; |
| 526 } | 515 } |
| 516 if (!used_quic) | |
| 517 return false; | |
| 518 | |
| 527 std::string address; | 519 std::string address; |
| 528 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, | 520 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, |
| 529 &address)) { | 521 &address) || |
| 530 DVLOG(1) << "Malformed SupportsQuic server: " << server.ToString(); | 522 !ParseIPLiteralToNumber(address, last_quic_address)) { |
| 523 DVLOG(1) << "Malformed SupportsQuic"; | |
| 531 return false; | 524 return false; |
| 532 } | 525 } |
| 533 SupportsQuic supports_quic(used_quic, address); | |
| 534 supports_quic_map->insert(std::make_pair(server, supports_quic)); | |
| 535 return true; | 526 return true; |
| 536 } | 527 } |
| 537 | 528 |
| 538 bool HttpServerPropertiesManager::AddToNetworkStatsMap( | 529 bool HttpServerPropertiesManager::AddToNetworkStatsMap( |
| 539 const HostPortPair& server, | 530 const HostPortPair& server, |
| 540 const base::DictionaryValue& server_pref_dict, | 531 const base::DictionaryValue& server_pref_dict, |
| 541 ServerNetworkStatsMap* network_stats_map) { | 532 ServerNetworkStatsMap* network_stats_map) { |
| 542 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); | 533 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); |
| 543 const base::DictionaryValue* server_network_stats_dict = NULL; | 534 const base::DictionaryValue* server_network_stats_dict = NULL; |
| 544 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 535 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 557 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist | 548 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 558 // bandwidth_estimate. | 549 // bandwidth_estimate. |
| 559 network_stats_map->Put(server, server_network_stats); | 550 network_stats_map->Put(server, server_network_stats); |
| 560 return true; | 551 return true; |
| 561 } | 552 } |
| 562 | 553 |
| 563 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( | 554 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
| 564 StringVector* spdy_servers, | 555 StringVector* spdy_servers, |
| 565 SpdySettingsMap* spdy_settings_map, | 556 SpdySettingsMap* spdy_settings_map, |
| 566 AlternateProtocolMap* alternate_protocol_map, | 557 AlternateProtocolMap* alternate_protocol_map, |
| 567 SupportsQuicMap* supports_quic_map, | 558 IPAddressNumber* last_quic_address, |
| 568 ServerNetworkStatsMap* server_network_stats_map, | 559 ServerNetworkStatsMap* server_network_stats_map, |
| 569 bool detected_corrupted_prefs) { | 560 bool detected_corrupted_prefs) { |
| 570 // Preferences have the master data because admins might have pushed new | 561 // Preferences have the master data because admins might have pushed new |
| 571 // preferences. Update the cached data with new data from preferences. | 562 // preferences. Update the cached data with new data from preferences. |
| 572 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 563 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 573 | 564 |
| 574 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 565 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
| 575 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 566 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
| 576 | 567 |
| 577 // Update the cached data and use the new spdy_settings from preferences. | 568 // Update the cached data and use the new spdy_settings from preferences. |
| 578 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 569 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
| 579 http_server_properties_impl_->InitializeSpdySettingsServers( | 570 http_server_properties_impl_->InitializeSpdySettingsServers( |
| 580 spdy_settings_map); | 571 spdy_settings_map); |
| 581 | 572 |
| 582 // Update the cached data and use the new Alternate-Protocol server list from | 573 // Update the cached data and use the new Alternate-Protocol server list from |
| 583 // preferences. | 574 // preferences. |
| 584 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 575 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
| 585 alternate_protocol_map->size()); | 576 alternate_protocol_map->size()); |
| 586 http_server_properties_impl_->InitializeAlternateProtocolServers( | 577 http_server_properties_impl_->InitializeAlternateProtocolServers( |
| 587 alternate_protocol_map); | 578 alternate_protocol_map); |
| 588 | 579 |
| 589 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); | 580 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); |
| 590 | 581 |
| 591 http_server_properties_impl_->InitializeServerNetworkStats( | 582 http_server_properties_impl_->InitializeServerNetworkStats( |
| 592 server_network_stats_map); | 583 server_network_stats_map); |
| 593 | 584 |
| 594 // Update the prefs with what we have read (delete all corrupted prefs). | 585 // Update the prefs with what we have read (delete all corrupted prefs). |
| 595 if (detected_corrupted_prefs) | 586 if (detected_corrupted_prefs) |
| 596 ScheduleUpdatePrefsOnNetworkThread(); | 587 ScheduleUpdatePrefsOnNetworkThread(); |
| 597 } | 588 } |
| 598 | 589 |
| 599 // | 590 // |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 http_server_properties_impl_->GetCanonicalSuffix(server.host()); | 647 http_server_properties_impl_->GetCanonicalSuffix(server.host()); |
| 657 if (!canonical_suffix.empty()) { | 648 if (!canonical_suffix.empty()) { |
| 658 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 649 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
| 659 continue; | 650 continue; |
| 660 persisted_map[canonical_suffix] = true; | 651 persisted_map[canonical_suffix] = true; |
| 661 } | 652 } |
| 662 alternate_protocol_map->Put(server, it->second); | 653 alternate_protocol_map->Put(server, it->second); |
| 663 ++count; | 654 ++count; |
| 664 } | 655 } |
| 665 | 656 |
| 666 SupportsQuicMap* supports_quic_map = new SupportsQuicMap(); | |
| 667 const SupportsQuicMap& main_supports_quic_map = | |
| 668 http_server_properties_impl_->supports_quic_map(); | |
| 669 for (SupportsQuicMap::const_iterator it = main_supports_quic_map.begin(); | |
| 670 it != main_supports_quic_map.end(); ++it) { | |
| 671 supports_quic_map->insert(std::make_pair(it->first, it->second)); | |
| 672 } | |
| 673 | |
| 674 ServerNetworkStatsMap* server_network_stats_map = | 657 ServerNetworkStatsMap* server_network_stats_map = |
| 675 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); | 658 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); |
| 676 const ServerNetworkStatsMap& main_server_network_stats_map = | 659 const ServerNetworkStatsMap& main_server_network_stats_map = |
| 677 http_server_properties_impl_->server_network_stats_map(); | 660 http_server_properties_impl_->server_network_stats_map(); |
| 678 for (ServerNetworkStatsMap::const_iterator it = | 661 for (ServerNetworkStatsMap::const_iterator it = |
| 679 main_server_network_stats_map.begin(); | 662 main_server_network_stats_map.begin(); |
| 680 it != main_server_network_stats_map.end(); ++it) { | 663 it != main_server_network_stats_map.end(); ++it) { |
| 681 server_network_stats_map->Put(it->first, it->second); | 664 server_network_stats_map->Put(it->first, it->second); |
| 682 } | 665 } |
| 683 | 666 |
| 667 IPAddressNumber* last_quic_addr = new IPAddressNumber; | |
| 668 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); | |
| 684 // Update the preferences on the pref thread. | 669 // Update the preferences on the pref thread. |
| 685 pref_task_runner_->PostTask( | 670 pref_task_runner_->PostTask( |
| 686 FROM_HERE, | 671 FROM_HERE, |
| 687 base::Bind( | 672 base::Bind( |
| 688 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, | 673 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, |
| 689 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), | 674 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), |
| 690 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), | 675 base::Owned(alternate_protocol_map), base::Owned(last_quic_addr), |
| 691 base::Owned(server_network_stats_map), completion)); | 676 base::Owned(server_network_stats_map), completion)); |
| 692 } | 677 } |
| 693 | 678 |
| 694 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 679 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
| 695 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used | 680 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used |
| 696 // only in UpdatePrefsOnPrefThread. | 681 // only in UpdatePrefsOnPrefThread. |
| 697 struct ServerPref { | 682 struct ServerPref { |
| 698 ServerPref() | 683 ServerPref() |
| 699 : supports_spdy(false), | 684 : supports_spdy(false), |
| 700 settings_map(NULL), | 685 settings_map(NULL), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 715 const SettingsMap* settings_map; | 700 const SettingsMap* settings_map; |
| 716 const AlternateProtocolInfo* alternate_protocol; | 701 const AlternateProtocolInfo* alternate_protocol; |
| 717 const SupportsQuic* supports_quic; | 702 const SupportsQuic* supports_quic; |
| 718 const ServerNetworkStats* server_network_stats; | 703 const ServerNetworkStats* server_network_stats; |
| 719 }; | 704 }; |
| 720 | 705 |
| 721 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 706 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
| 722 base::ListValue* spdy_server_list, | 707 base::ListValue* spdy_server_list, |
| 723 SpdySettingsMap* spdy_settings_map, | 708 SpdySettingsMap* spdy_settings_map, |
| 724 AlternateProtocolMap* alternate_protocol_map, | 709 AlternateProtocolMap* alternate_protocol_map, |
| 725 SupportsQuicMap* supports_quic_map, | 710 IPAddressNumber* last_quic_address, |
| 726 ServerNetworkStatsMap* server_network_stats_map, | 711 ServerNetworkStatsMap* server_network_stats_map, |
| 727 const base::Closure& completion) { | 712 const base::Closure& completion) { |
| 728 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; | 713 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; |
| 729 ServerPrefMap server_pref_map; | 714 ServerPrefMap server_pref_map; |
| 730 | 715 |
| 731 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 716 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 732 | 717 |
| 733 // Add servers that support spdy to server_pref_map. | 718 // Add servers that support spdy to server_pref_map. |
| 734 std::string s; | 719 std::string s; |
| 735 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); | 720 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 754 map_it != alternate_protocol_map->end(); ++map_it) { | 739 map_it != alternate_protocol_map->end(); ++map_it) { |
| 755 const HostPortPair& server = map_it->first; | 740 const HostPortPair& server = map_it->first; |
| 756 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; | 741 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; |
| 757 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 742 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
| 758 continue; | 743 continue; |
| 759 } | 744 } |
| 760 server_pref_map[server].alternate_protocol = &map_it->second; | 745 server_pref_map[server].alternate_protocol = &map_it->second; |
| 761 } | 746 } |
| 762 | 747 |
| 763 // Add SupportsQuic servers to server_pref_map. | 748 // Add SupportsQuic servers to server_pref_map. |
| 749 /* | |
| 764 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); | 750 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); |
| 765 map_it != supports_quic_map->end(); ++map_it) { | 751 map_it != supports_quic_map->end(); ++map_it) { |
| 766 const HostPortPair& server = map_it->first; | 752 const HostPortPair& server = map_it->first; |
| 767 server_pref_map[server].supports_quic = &map_it->second; | 753 server_pref_map[server].supports_quic = &map_it->second; |
| 768 } | 754 } |
| 755 */ | |
|
ramant (doing other things)
2015/02/03 18:09:37
nit: could lines 747-755 be deleted.
Ryan Hamilton
2015/02/03 22:50:45
Done.
| |
| 769 | 756 |
| 770 // Add ServerNetworkStats servers to server_pref_map. | 757 // Add ServerNetworkStats servers to server_pref_map. |
| 771 for (ServerNetworkStatsMap::const_iterator map_it = | 758 for (ServerNetworkStatsMap::const_iterator map_it = |
| 772 server_network_stats_map->begin(); | 759 server_network_stats_map->begin(); |
| 773 map_it != server_network_stats_map->end(); ++map_it) { | 760 map_it != server_network_stats_map->end(); ++map_it) { |
| 774 const HostPortPair& server = map_it->first; | 761 const HostPortPair& server = map_it->first; |
| 775 server_pref_map[server].server_network_stats = &map_it->second; | 762 server_pref_map[server].server_network_stats = &map_it->second; |
| 776 } | 763 } |
| 777 | 764 |
| 778 // Persist properties to the |path_|. | 765 // Persist properties to the |path_|. |
| 779 base::DictionaryValue http_server_properties_dict; | 766 base::DictionaryValue http_server_properties_dict; |
| 780 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 767 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 781 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); | 768 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
| 782 map_it != server_pref_map.end(); | 769 map_it != server_pref_map.end(); |
| 783 ++map_it) { | 770 ++map_it) { |
| 784 const HostPortPair& server = map_it->first; | 771 const HostPortPair& server = map_it->first; |
| 785 const ServerPref& server_pref = map_it->second; | 772 const ServerPref& server_pref = map_it->second; |
| 786 | 773 |
| 787 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 774 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 788 | 775 |
| 789 // Save supports_spdy. | 776 // Save supports_spdy. |
| 790 if (server_pref.supports_spdy) | 777 if (server_pref.supports_spdy) |
| 791 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); | 778 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); |
| 792 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); | 779 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); |
| 793 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol, | 780 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol, |
| 794 server_pref_dict); | 781 server_pref_dict); |
| 795 SaveSupportsQuicToServerPrefs(server_pref.supports_quic, server_pref_dict); | |
| 796 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, | 782 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, |
| 797 server_pref_dict); | 783 server_pref_dict); |
| 798 | 784 |
| 799 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 785 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
| 800 } | 786 } |
| 801 | 787 |
| 802 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, | 788 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, |
| 803 servers_dict); | 789 servers_dict); |
| 804 SetVersion(&http_server_properties_dict, kVersionNumber); | 790 SetVersion(&http_server_properties_dict, kVersionNumber); |
| 791 | |
| 792 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); | |
| 793 | |
| 805 setting_prefs_ = true; | 794 setting_prefs_ = true; |
| 806 pref_service_->Set(path_, http_server_properties_dict); | 795 pref_service_->Set(path_, http_server_properties_dict); |
| 807 setting_prefs_ = false; | 796 setting_prefs_ = false; |
| 808 | 797 |
| 809 // Note that |completion| will be fired after we have written everything to | 798 // Note that |completion| will be fired after we have written everything to |
| 810 // the Preferences, but likely before these changes are serialized to disk. | 799 // the Preferences, but likely before these changes are serialized to disk. |
| 811 // This is not a problem though, as JSONPrefStore guarantees that this will | 800 // This is not a problem though, as JSONPrefStore guarantees that this will |
| 812 // happen, pretty soon, and even in the case we shut down immediately. | 801 // happen, pretty soon, and even in the case we shut down immediately. |
| 813 if (!completion.is_null()) | 802 if (!completion.is_null()) |
| 814 completion.Run(); | 803 completion.Run(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 843 port_alternate_protocol->port); | 832 port_alternate_protocol->port); |
| 844 const char* protocol_str = | 833 const char* protocol_str = |
| 845 AlternateProtocolToString(port_alternate_protocol->protocol); | 834 AlternateProtocolToString(port_alternate_protocol->protocol); |
| 846 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); | 835 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); |
| 847 port_alternate_protocol_dict->SetDouble(kProbabilityKey, | 836 port_alternate_protocol_dict->SetDouble(kProbabilityKey, |
| 848 port_alternate_protocol->probability); | 837 port_alternate_protocol->probability); |
| 849 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey, | 838 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey, |
| 850 port_alternate_protocol_dict); | 839 port_alternate_protocol_dict); |
| 851 } | 840 } |
| 852 | 841 |
| 853 void HttpServerPropertiesManager::SaveSupportsQuicToServerPrefs( | 842 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |
| 854 const SupportsQuic* supports_quic, | 843 const IPAddressNumber* last_quic_address, |
| 855 base::DictionaryValue* server_pref_dict) { | 844 base::DictionaryValue* http_server_properties_dict) { |
| 856 // Save supports_quic. | 845 if (!last_quic_address || last_quic_address->empty()) |
| 857 if (!supports_quic) | |
| 858 return; | 846 return; |
| 859 | 847 |
| 860 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 848 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
| 861 supports_quic_dict->SetBoolean(kUsedQuicKey, supports_quic->used_quic); | 849 supports_quic_dict->SetBoolean(kUsedQuicKey, true); |
| 862 supports_quic_dict->SetString(kAddressKey, supports_quic->address); | 850 supports_quic_dict->SetString(kAddressKey, |
| 863 server_pref_dict->SetWithoutPathExpansion(kSupportsQuicKey, | 851 IPAddressToString(*last_quic_address)); |
| 864 supports_quic_dict); | 852 http_server_properties_dict->SetWithoutPathExpansion(kSupportsQuicKey, |
| 853 supports_quic_dict); | |
| 865 } | 854 } |
| 866 | 855 |
| 867 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs( | 856 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs( |
| 868 const ServerNetworkStats* server_network_stats, | 857 const ServerNetworkStats* server_network_stats, |
| 869 base::DictionaryValue* server_pref_dict) { | 858 base::DictionaryValue* server_pref_dict) { |
| 870 if (!server_network_stats) | 859 if (!server_network_stats) |
| 871 return; | 860 return; |
| 872 | 861 |
| 873 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue; | 862 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue; |
| 874 // Becasue JSON doesn't support int64, persist int64 as a string. | 863 // Becasue JSON doesn't support int64, persist int64 as a string. |
| 875 server_network_stats_dict->SetInteger( | 864 server_network_stats_dict->SetInteger( |
| 876 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue())); | 865 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue())); |
| 877 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist | 866 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 878 // bandwidth_estimate. | 867 // bandwidth_estimate. |
| 879 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey, | 868 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey, |
| 880 server_network_stats_dict); | 869 server_network_stats_dict); |
| 881 } | 870 } |
| 882 | 871 |
| 883 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 872 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 884 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 873 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 885 if (!setting_prefs_) | 874 if (!setting_prefs_) |
| 886 ScheduleUpdateCacheOnPrefThread(); | 875 ScheduleUpdateCacheOnPrefThread(); |
| 887 } | 876 } |
| 888 | 877 |
| 889 } // namespace net | 878 } // namespace net |
| OLD | NEW |