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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const int kMaxServerNetworkStatsHostsToPersist = 200; | 51 const int kMaxServerNetworkStatsHostsToPersist = 200; |
52 | 52 |
53 const char kVersionKey[] = "version"; | 53 const char kVersionKey[] = "version"; |
54 const char kServersKey[] = "servers"; | 54 const char kServersKey[] = "servers"; |
55 const char kSupportsSpdyKey[] = "supports_spdy"; | 55 const char kSupportsSpdyKey[] = "supports_spdy"; |
56 const char kSettingsKey[] = "settings"; | 56 const char kSettingsKey[] = "settings"; |
57 const char kSupportsQuicKey[] = "supports_quic"; | 57 const char kSupportsQuicKey[] = "supports_quic"; |
58 const char kUsedQuicKey[] = "used_quic"; | 58 const char kUsedQuicKey[] = "used_quic"; |
59 const char kAddressKey[] = "address"; | 59 const char kAddressKey[] = "address"; |
60 const char kAlternateProtocolKey[] = "alternate_protocol"; | 60 const char kAlternateProtocolKey[] = "alternate_protocol"; |
| 61 const char kAlternativeServiceKey[] = "alternative_service"; |
| 62 const char kProtocolKey[] = "protocol_str"; |
| 63 const char kHostKey[] = "host"; |
61 const char kPortKey[] = "port"; | 64 const char kPortKey[] = "port"; |
62 const char kProtocolKey[] = "protocol_str"; | |
63 const char kProbabilityKey[] = "probability"; | 65 const char kProbabilityKey[] = "probability"; |
64 const char kNetworkStatsKey[] = "network_stats"; | 66 const char kNetworkStatsKey[] = "network_stats"; |
65 const char kSrttKey[] = "srtt"; | 67 const char kSrttKey[] = "srtt"; |
66 | 68 |
67 } // namespace | 69 } // namespace |
68 | 70 |
69 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
70 // HttpServerPropertiesManager | 72 // HttpServerPropertiesManager |
71 | 73 |
72 HttpServerPropertiesManager::HttpServerPropertiesManager( | 74 HttpServerPropertiesManager::HttpServerPropertiesManager( |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 ScheduleUpdatePrefsOnNetworkThread(); | 235 ScheduleUpdatePrefsOnNetworkThread(); |
234 } | 236 } |
235 | 237 |
236 void HttpServerPropertiesManager::ClearAlternativeService( | 238 void HttpServerPropertiesManager::ClearAlternativeService( |
237 const HostPortPair& origin) { | 239 const HostPortPair& origin) { |
238 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 240 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
239 http_server_properties_impl_->ClearAlternativeService(origin); | 241 http_server_properties_impl_->ClearAlternativeService(origin); |
240 ScheduleUpdatePrefsOnNetworkThread(); | 242 ScheduleUpdatePrefsOnNetworkThread(); |
241 } | 243 } |
242 | 244 |
243 const AlternateProtocolMap& | 245 const AlternativeServiceMap& |
244 HttpServerPropertiesManager::alternate_protocol_map() const { | 246 HttpServerPropertiesManager::alternative_service_map() const { |
245 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 247 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
246 return http_server_properties_impl_->alternate_protocol_map(); | 248 return http_server_properties_impl_->alternative_service_map(); |
247 } | 249 } |
248 | 250 |
249 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( | 251 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( |
250 double threshold) { | 252 double threshold) { |
251 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 253 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
252 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( | 254 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( |
253 threshold); | 255 threshold); |
254 } | 256 } |
255 | 257 |
256 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( | 258 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 return; | 375 return; |
374 } | 376 } |
375 | 377 |
376 IPAddressNumber* addr = new IPAddressNumber; | 378 IPAddressNumber* addr = new IPAddressNumber; |
377 ReadSupportsQuic(http_server_properties_dict, addr); | 379 ReadSupportsQuic(http_server_properties_dict, addr); |
378 | 380 |
379 // String is host/port pair of spdy server. | 381 // String is host/port pair of spdy server. |
380 scoped_ptr<StringVector> spdy_servers(new StringVector); | 382 scoped_ptr<StringVector> spdy_servers(new StringVector); |
381 scoped_ptr<SpdySettingsMap> spdy_settings_map( | 383 scoped_ptr<SpdySettingsMap> spdy_settings_map( |
382 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 384 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
383 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( | 385 scoped_ptr<AlternativeServiceMap> alternative_service_map( |
384 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 386 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); |
385 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( | 387 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( |
386 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); | 388 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); |
387 | 389 |
388 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); | 390 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); |
389 it.Advance()) { | 391 it.Advance()) { |
390 // Get server's host/pair. | 392 // Get server's host/pair. |
391 const std::string& server_str = it.key(); | 393 const std::string& server_str = it.key(); |
392 HostPortPair server = HostPortPair::FromString(server_str); | 394 HostPortPair server = HostPortPair::FromString(server_str); |
393 if (server.host().empty()) { | 395 if (server.host().empty()) { |
394 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 396 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
395 detected_corrupted_prefs = true; | 397 detected_corrupted_prefs = true; |
396 continue; | 398 continue; |
397 } | 399 } |
398 | 400 |
399 const base::DictionaryValue* server_pref_dict = NULL; | 401 const base::DictionaryValue* server_pref_dict = NULL; |
400 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 402 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
401 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 403 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
402 detected_corrupted_prefs = true; | 404 detected_corrupted_prefs = true; |
403 continue; | 405 continue; |
404 } | 406 } |
405 | 407 |
406 // Get if server supports Spdy. | 408 // Get if server supports Spdy. |
407 bool supports_spdy = false; | 409 bool supports_spdy = false; |
408 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 410 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
409 supports_spdy) { | 411 supports_spdy) { |
410 spdy_servers->push_back(server_str); | 412 spdy_servers->push_back(server_str); |
411 } | 413 } |
412 | 414 |
413 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); | 415 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); |
414 if (!AddToAlternateProtocolMap(server, *server_pref_dict, | 416 if (!AddToAlternativeServiceMap(server, *server_pref_dict, |
415 alternate_protocol_map.get()) || | 417 alternative_service_map.get()) || |
416 !AddToNetworkStatsMap(server, *server_pref_dict, | 418 !AddToNetworkStatsMap(server, *server_pref_dict, |
417 server_network_stats_map.get())) { | 419 server_network_stats_map.get())) { |
418 detected_corrupted_prefs = true; | 420 detected_corrupted_prefs = true; |
419 } | 421 } |
420 } | 422 } |
421 | 423 |
422 network_task_runner_->PostTask( | 424 network_task_runner_->PostTask( |
423 FROM_HERE, | 425 FROM_HERE, |
424 base::Bind( | 426 base::Bind( |
425 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 427 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
426 base::Unretained(this), base::Owned(spdy_servers.release()), | 428 base::Unretained(this), base::Owned(spdy_servers.release()), |
427 base::Owned(spdy_settings_map.release()), | 429 base::Owned(spdy_settings_map.release()), |
428 base::Owned(alternate_protocol_map.release()), base::Owned(addr), | 430 base::Owned(alternative_service_map.release()), base::Owned(addr), |
429 base::Owned(server_network_stats_map.release()), | 431 base::Owned(server_network_stats_map.release()), |
430 detected_corrupted_prefs)); | 432 detected_corrupted_prefs)); |
431 } | 433 } |
432 | 434 |
433 void HttpServerPropertiesManager::AddToSpdySettingsMap( | 435 void HttpServerPropertiesManager::AddToSpdySettingsMap( |
434 const HostPortPair& server, | 436 const HostPortPair& server, |
435 const base::DictionaryValue& server_pref_dict, | 437 const base::DictionaryValue& server_pref_dict, |
436 SpdySettingsMap* spdy_settings_map) { | 438 SpdySettingsMap* spdy_settings_map) { |
437 // Get SpdySettings. | 439 // Get SpdySettings. |
438 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 440 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
(...skipping 19 matching lines...) Expand all Loading... |
458 << server.ToString(); | 460 << server.ToString(); |
459 NOTREACHED(); | 461 NOTREACHED(); |
460 continue; | 462 continue; |
461 } | 463 } |
462 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 464 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
463 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; | 465 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; |
464 } | 466 } |
465 spdy_settings_map->Put(server, settings_map); | 467 spdy_settings_map->Put(server, settings_map); |
466 } | 468 } |
467 | 469 |
468 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict( | 470 AlternativeServiceInfo HttpServerPropertiesManager::ParseAlternativeServiceDict( |
469 const base::DictionaryValue& alternate_protocol_dict, | 471 const base::DictionaryValue& alternative_service_dict, |
470 const std::string& server_str) { | 472 const std::string& server_str) { |
471 AlternateProtocolInfo alternate_protocol; | 473 // Protocol is mandatory. |
472 int port = 0; | |
473 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) || | |
474 !IsPortValid(port)) { | |
475 DVLOG(1) << "Malformed alternative service port for server: " << server_str; | |
476 return alternate_protocol; | |
477 } | |
478 alternate_protocol.port = static_cast<uint16>(port); | |
479 | |
480 double probability = 1.0; | |
481 if (alternate_protocol_dict.HasKey(kProbabilityKey) && | |
482 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey, | |
483 &probability)) { | |
484 DVLOG(1) << "Malformed alternative service probability for server: " | |
485 << server_str; | |
486 return alternate_protocol; | |
487 } | |
488 alternate_protocol.probability = probability; | |
489 | |
490 std::string protocol_str; | 474 std::string protocol_str; |
491 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey, | 475 if (!alternative_service_dict.GetStringWithoutPathExpansion(kProtocolKey, |
492 &protocol_str)) { | 476 &protocol_str)) { |
493 DVLOG(1) << "Malformed alternative service protocol string for server: " | 477 DVLOG(1) << "Malformed alternative service protocol string for server: " |
494 << server_str; | 478 << server_str; |
495 return alternate_protocol; | 479 return AlternativeServiceInfo(); |
496 } | 480 } |
497 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); | 481 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); |
498 if (!IsAlternateProtocolValid(protocol)) { | 482 if (!IsAlternateProtocolValid(protocol)) { |
499 DVLOG(1) << "Invalid alternative service protocol string for server: " | 483 DVLOG(1) << "Invalid alternative service protocol string for server: " |
500 << server_str; | 484 << server_str; |
501 return alternate_protocol; | 485 return AlternativeServiceInfo(); |
502 } | 486 } |
503 alternate_protocol.protocol = protocol; | |
504 | 487 |
505 return alternate_protocol; | 488 // Host is optional, defaults to "". |
| 489 std::string host; |
| 490 if (alternative_service_dict.HasKey(kHostKey) && |
| 491 !alternative_service_dict.GetStringWithoutPathExpansion(kHostKey, |
| 492 &host)) { |
| 493 DVLOG(1) << "Malformed alternative service host string for server: " |
| 494 << server_str; |
| 495 return AlternativeServiceInfo(); |
| 496 } |
| 497 |
| 498 // Port is mandatory. |
| 499 int port = 0; |
| 500 if (!alternative_service_dict.GetInteger(kPortKey, &port) || |
| 501 !IsPortValid(port)) { |
| 502 DVLOG(1) << "Malformed alternative service port for server: " << server_str; |
| 503 return AlternativeServiceInfo(); |
| 504 } |
| 505 |
| 506 // Probability is optional, defaults to 1.0. |
| 507 double probability = 1.0; |
| 508 if (alternative_service_dict.HasKey(kProbabilityKey) && |
| 509 !alternative_service_dict.GetDoubleWithoutPathExpansion(kProbabilityKey, |
| 510 &probability)) { |
| 511 DVLOG(1) << "Malformed alternative service probability for server: " |
| 512 << server_str; |
| 513 return AlternativeServiceInfo(); |
| 514 } |
| 515 |
| 516 return AlternativeServiceInfo(protocol, host, static_cast<uint16>(port), |
| 517 probability); |
506 } | 518 } |
507 | 519 |
508 bool HttpServerPropertiesManager::AddToAlternateProtocolMap( | 520 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( |
509 const HostPortPair& server, | 521 const HostPortPair& server, |
510 const base::DictionaryValue& server_pref_dict, | 522 const base::DictionaryValue& server_pref_dict, |
511 AlternateProtocolMap* alternate_protocol_map) { | 523 AlternativeServiceMap* alternative_service_map) { |
512 // Get alternate_protocol server. | 524 DCHECK(alternative_service_map->Peek(server) == |
513 DCHECK(alternate_protocol_map->Peek(server) == alternate_protocol_map->end()); | 525 alternative_service_map->end()); |
514 const base::DictionaryValue* alternate_protocol_dict = NULL; | 526 // Get alternative_services... |
515 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 527 const base::ListValue* alternative_service_list; |
516 kAlternateProtocolKey, &alternate_protocol_dict)) { | 528 const base::DictionaryValue* alternative_service_dict; |
517 return true; | 529 AlternativeServiceInfo alternative_service_info; |
| 530 if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey, |
| 531 &alternative_service_list)) { |
| 532 if (alternative_service_list->empty()) { |
| 533 return false; |
| 534 } |
| 535 // Get first element of the list. |
| 536 // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, read |
| 537 // all of them. |
| 538 if (!alternative_service_list->GetDictionary(0, |
| 539 &alternative_service_dict)) { |
| 540 return false; |
| 541 } |
| 542 alternative_service_info = ParseAlternativeServiceDict( |
| 543 *alternative_service_dict, server.ToString()); |
| 544 } else { |
| 545 // ...or alternate_protocol. |
| 546 // TODO(bnc): Remove this in M46, we do not need preference migration for |
| 547 // long. |
| 548 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 549 kAlternateProtocolKey, &alternative_service_dict)) { |
| 550 return true; |
| 551 } |
| 552 alternative_service_info = ParseAlternativeServiceDict( |
| 553 *alternative_service_dict, server.ToString()); |
518 } | 554 } |
519 AlternateProtocolInfo alternate_protocol = | 555 |
520 ParseAlternateProtocolDict(*alternate_protocol_dict, server.ToString()); | 556 if (alternative_service_info.alternative_service.protocol == |
521 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 557 UNINITIALIZED_ALTERNATE_PROTOCOL) { |
522 return false; | 558 return false; |
523 alternate_protocol_map->Put(server, alternate_protocol); | 559 } |
| 560 alternative_service_map->Put(server, alternative_service_info); |
524 return true; | 561 return true; |
525 } | 562 } |
526 | 563 |
527 bool HttpServerPropertiesManager::ReadSupportsQuic( | 564 bool HttpServerPropertiesManager::ReadSupportsQuic( |
528 const base::DictionaryValue& http_server_properties_dict, | 565 const base::DictionaryValue& http_server_properties_dict, |
529 IPAddressNumber* last_quic_address) { | 566 IPAddressNumber* last_quic_address) { |
530 const base::DictionaryValue* supports_quic_dict = NULL; | 567 const base::DictionaryValue* supports_quic_dict = NULL; |
531 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 568 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
532 kSupportsQuicKey, &supports_quic_dict)) { | 569 kSupportsQuicKey, &supports_quic_dict)) { |
533 return true; | 570 return true; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); | 609 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); |
573 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist | 610 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
574 // bandwidth_estimate. | 611 // bandwidth_estimate. |
575 network_stats_map->Put(server, server_network_stats); | 612 network_stats_map->Put(server, server_network_stats); |
576 return true; | 613 return true; |
577 } | 614 } |
578 | 615 |
579 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( | 616 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
580 StringVector* spdy_servers, | 617 StringVector* spdy_servers, |
581 SpdySettingsMap* spdy_settings_map, | 618 SpdySettingsMap* spdy_settings_map, |
582 AlternateProtocolMap* alternate_protocol_map, | 619 AlternativeServiceMap* alternative_service_map, |
583 IPAddressNumber* last_quic_address, | 620 IPAddressNumber* last_quic_address, |
584 ServerNetworkStatsMap* server_network_stats_map, | 621 ServerNetworkStatsMap* server_network_stats_map, |
585 bool detected_corrupted_prefs) { | 622 bool detected_corrupted_prefs) { |
586 // Preferences have the master data because admins might have pushed new | 623 // Preferences have the master data because admins might have pushed new |
587 // preferences. Update the cached data with new data from preferences. | 624 // preferences. Update the cached data with new data from preferences. |
588 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 625 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
589 | 626 |
590 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 627 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
591 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 628 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
592 | 629 |
593 // Update the cached data and use the new spdy_settings from preferences. | 630 // Update the cached data and use the new spdy_settings from preferences. |
594 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 631 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
595 http_server_properties_impl_->InitializeSpdySettingsServers( | 632 http_server_properties_impl_->InitializeSpdySettingsServers( |
596 spdy_settings_map); | 633 spdy_settings_map); |
597 | 634 |
598 // Update the cached data and use the new Alternate-Protocol server list from | 635 // Update the cached data and use the new Alternate-Protocol server list from |
599 // preferences. | 636 // preferences. |
600 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 637 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
601 alternate_protocol_map->size()); | 638 alternative_service_map->size()); |
602 http_server_properties_impl_->InitializeAlternateProtocolServers( | 639 http_server_properties_impl_->InitializeAlternativeServiceServers( |
603 alternate_protocol_map); | 640 alternative_service_map); |
604 | 641 |
605 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); | 642 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); |
606 | 643 |
607 http_server_properties_impl_->InitializeServerNetworkStats( | 644 http_server_properties_impl_->InitializeServerNetworkStats( |
608 server_network_stats_map); | 645 server_network_stats_map); |
609 | 646 |
610 // Update the prefs with what we have read (delete all corrupted prefs). | 647 // Update the prefs with what we have read (delete all corrupted prefs). |
611 if (detected_corrupted_prefs) | 648 if (detected_corrupted_prefs) |
612 ScheduleUpdatePrefsOnNetworkThread(); | 649 ScheduleUpdatePrefsOnNetworkThread(); |
613 } | 650 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist); | 688 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist); |
652 const SpdySettingsMap& main_map = | 689 const SpdySettingsMap& main_map = |
653 http_server_properties_impl_->spdy_settings_map(); | 690 http_server_properties_impl_->spdy_settings_map(); |
654 int count = 0; | 691 int count = 0; |
655 for (SpdySettingsMap::const_iterator it = main_map.begin(); | 692 for (SpdySettingsMap::const_iterator it = main_map.begin(); |
656 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; | 693 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; |
657 ++it, ++count) { | 694 ++it, ++count) { |
658 spdy_settings_map->Put(it->first, it->second); | 695 spdy_settings_map->Put(it->first, it->second); |
659 } | 696 } |
660 | 697 |
661 AlternateProtocolMap* alternate_protocol_map = | 698 AlternativeServiceMap* alternative_service_map = |
662 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); | 699 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist); |
663 const AlternateProtocolMap& map = | 700 const AlternativeServiceMap& map = |
664 http_server_properties_impl_->alternate_protocol_map(); | 701 http_server_properties_impl_->alternative_service_map(); |
665 count = 0; | 702 count = 0; |
666 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | 703 typedef std::map<std::string, bool> CanonicalHostPersistedMap; |
667 CanonicalHostPersistedMap persisted_map; | 704 CanonicalHostPersistedMap persisted_map; |
668 for (AlternateProtocolMap::const_iterator it = map.begin(); | 705 for (AlternativeServiceMap::const_iterator it = map.begin(); |
669 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { | 706 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { |
670 const AlternateProtocolInfo& alternate_protocol = it->second; | 707 const AlternativeServiceInfo& alternative_service_info = it->second; |
671 if (!IsAlternateProtocolValid(alternate_protocol.protocol)) { | 708 if (!IsAlternateProtocolValid( |
| 709 alternative_service_info.alternative_service.protocol)) { |
672 continue; | 710 continue; |
673 } | 711 } |
674 const HostPortPair& server = it->first; | 712 const HostPortPair& server = it->first; |
675 if (IsAlternativeServiceBroken( | 713 AlternativeService alternative_service( |
676 AlternativeService(alternate_protocol.protocol, server.host(), | 714 alternative_service_info.alternative_service); |
677 alternate_protocol.port))) { | 715 if (alternative_service.host.empty()) { |
| 716 alternative_service.host = server.host(); |
| 717 } |
| 718 if (IsAlternativeServiceBroken(alternative_service)) { |
678 continue; | 719 continue; |
679 } | 720 } |
680 std::string canonical_suffix = | 721 std::string canonical_suffix = |
681 http_server_properties_impl_->GetCanonicalSuffix(server.host()); | 722 http_server_properties_impl_->GetCanonicalSuffix(server.host()); |
682 if (!canonical_suffix.empty()) { | 723 if (!canonical_suffix.empty()) { |
683 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 724 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
684 continue; | 725 continue; |
685 persisted_map[canonical_suffix] = true; | 726 persisted_map[canonical_suffix] = true; |
686 } | 727 } |
687 alternate_protocol_map->Put(server, alternate_protocol); | 728 alternative_service_map->Put(server, alternative_service_info); |
688 ++count; | 729 ++count; |
689 } | 730 } |
690 | 731 |
691 ServerNetworkStatsMap* server_network_stats_map = | 732 ServerNetworkStatsMap* server_network_stats_map = |
692 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); | 733 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); |
693 const ServerNetworkStatsMap& main_server_network_stats_map = | 734 const ServerNetworkStatsMap& main_server_network_stats_map = |
694 http_server_properties_impl_->server_network_stats_map(); | 735 http_server_properties_impl_->server_network_stats_map(); |
695 for (ServerNetworkStatsMap::const_iterator it = | 736 for (ServerNetworkStatsMap::const_iterator it = |
696 main_server_network_stats_map.begin(); | 737 main_server_network_stats_map.begin(); |
697 it != main_server_network_stats_map.end(); ++it) { | 738 it != main_server_network_stats_map.end(); ++it) { |
698 server_network_stats_map->Put(it->first, it->second); | 739 server_network_stats_map->Put(it->first, it->second); |
699 } | 740 } |
700 | 741 |
701 IPAddressNumber* last_quic_addr = new IPAddressNumber; | 742 IPAddressNumber* last_quic_addr = new IPAddressNumber; |
702 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); | 743 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); |
703 // Update the preferences on the pref thread. | 744 // Update the preferences on the pref thread. |
704 pref_task_runner_->PostTask( | 745 pref_task_runner_->PostTask( |
705 FROM_HERE, | 746 FROM_HERE, |
706 base::Bind( | 747 base::Bind( |
707 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, | 748 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, |
708 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), | 749 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), |
709 base::Owned(alternate_protocol_map), base::Owned(last_quic_addr), | 750 base::Owned(alternative_service_map), base::Owned(last_quic_addr), |
710 base::Owned(server_network_stats_map), completion)); | 751 base::Owned(server_network_stats_map), completion)); |
711 } | 752 } |
712 | 753 |
713 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 754 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
714 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used | 755 // AlternativeServiceInfo and SupportsQuic preferences for a server. This is |
715 // only in UpdatePrefsOnPrefThread. | 756 // used only in UpdatePrefsOnPrefThread. |
716 struct ServerPref { | 757 struct ServerPref { |
717 ServerPref() | 758 ServerPref() |
718 : supports_spdy(false), | 759 : supports_spdy(false), |
719 settings_map(NULL), | 760 settings_map(NULL), |
720 alternate_protocol(NULL), | 761 alternative_service(NULL), |
721 supports_quic(NULL), | 762 supports_quic(NULL), |
722 server_network_stats(NULL) {} | 763 server_network_stats(NULL) {} |
723 ServerPref(bool supports_spdy, | 764 ServerPref(bool supports_spdy, |
724 const SettingsMap* settings_map, | 765 const SettingsMap* settings_map, |
725 const AlternateProtocolInfo* alternate_protocol, | 766 const AlternativeServiceInfo* alternative_service, |
726 const SupportsQuic* supports_quic, | 767 const SupportsQuic* supports_quic, |
727 const ServerNetworkStats* server_network_stats) | 768 const ServerNetworkStats* server_network_stats) |
728 : supports_spdy(supports_spdy), | 769 : supports_spdy(supports_spdy), |
729 settings_map(settings_map), | 770 settings_map(settings_map), |
730 alternate_protocol(alternate_protocol), | 771 alternative_service(alternative_service), |
731 supports_quic(supports_quic), | 772 supports_quic(supports_quic), |
732 server_network_stats(server_network_stats) {} | 773 server_network_stats(server_network_stats) {} |
733 bool supports_spdy; | 774 bool supports_spdy; |
734 const SettingsMap* settings_map; | 775 const SettingsMap* settings_map; |
735 const AlternateProtocolInfo* alternate_protocol; | 776 const AlternativeServiceInfo* alternative_service; |
736 const SupportsQuic* supports_quic; | 777 const SupportsQuic* supports_quic; |
737 const ServerNetworkStats* server_network_stats; | 778 const ServerNetworkStats* server_network_stats; |
738 }; | 779 }; |
739 | 780 |
740 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 781 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
741 base::ListValue* spdy_server_list, | 782 base::ListValue* spdy_server_list, |
742 SpdySettingsMap* spdy_settings_map, | 783 SpdySettingsMap* spdy_settings_map, |
743 AlternateProtocolMap* alternate_protocol_map, | 784 AlternativeServiceMap* alternative_service_map, |
744 IPAddressNumber* last_quic_address, | 785 IPAddressNumber* last_quic_address, |
745 ServerNetworkStatsMap* server_network_stats_map, | 786 ServerNetworkStatsMap* server_network_stats_map, |
746 const base::Closure& completion) { | 787 const base::Closure& completion) { |
747 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; | 788 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; |
748 ServerPrefMap server_pref_map; | 789 ServerPrefMap server_pref_map; |
749 | 790 |
750 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 791 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
751 | 792 |
752 // Add servers that support spdy to server_pref_map. | 793 // Add servers that support spdy to server_pref_map. |
753 std::string s; | 794 std::string s; |
754 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); | 795 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); |
755 list_it != spdy_server_list->end(); | 796 list_it != spdy_server_list->end(); |
756 ++list_it) { | 797 ++list_it) { |
757 if ((*list_it)->GetAsString(&s)) { | 798 if ((*list_it)->GetAsString(&s)) { |
758 HostPortPair server = HostPortPair::FromString(s); | 799 HostPortPair server = HostPortPair::FromString(s); |
759 server_pref_map[server].supports_spdy = true; | 800 server_pref_map[server].supports_spdy = true; |
760 } | 801 } |
761 } | 802 } |
762 | 803 |
763 // Add servers that have SpdySettings to server_pref_map. | 804 // Add servers that have SpdySettings to server_pref_map. |
764 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 805 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
765 map_it != spdy_settings_map->end(); ++map_it) { | 806 map_it != spdy_settings_map->end(); ++map_it) { |
766 const HostPortPair& server = map_it->first; | 807 const HostPortPair& server = map_it->first; |
767 server_pref_map[server].settings_map = &map_it->second; | 808 server_pref_map[server].settings_map = &map_it->second; |
768 } | 809 } |
769 | 810 |
770 // Add AlternateProtocol servers to server_pref_map. | 811 // Add AlternateProtocol servers to server_pref_map. |
771 for (AlternateProtocolMap::const_iterator map_it = | 812 for (AlternativeServiceMap::const_iterator map_it = |
772 alternate_protocol_map->begin(); | 813 alternative_service_map->begin(); |
773 map_it != alternate_protocol_map->end(); ++map_it) { | 814 map_it != alternative_service_map->end(); ++map_it) { |
774 server_pref_map[map_it->first].alternate_protocol = &map_it->second; | 815 server_pref_map[map_it->first].alternative_service = &map_it->second; |
775 } | 816 } |
776 | 817 |
777 // Add ServerNetworkStats servers to server_pref_map. | 818 // Add ServerNetworkStats servers to server_pref_map. |
778 for (ServerNetworkStatsMap::const_iterator map_it = | 819 for (ServerNetworkStatsMap::const_iterator map_it = |
779 server_network_stats_map->begin(); | 820 server_network_stats_map->begin(); |
780 map_it != server_network_stats_map->end(); ++map_it) { | 821 map_it != server_network_stats_map->end(); ++map_it) { |
781 const HostPortPair& server = map_it->first; | 822 const HostPortPair& server = map_it->first; |
782 server_pref_map[server].server_network_stats = &map_it->second; | 823 server_pref_map[server].server_network_stats = &map_it->second; |
783 } | 824 } |
784 | 825 |
785 // Persist properties to the |path_|. | 826 // Persist properties to the |path_|. |
786 base::DictionaryValue http_server_properties_dict; | 827 base::DictionaryValue http_server_properties_dict; |
787 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 828 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
788 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); | 829 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
789 map_it != server_pref_map.end(); | 830 map_it != server_pref_map.end(); |
790 ++map_it) { | 831 ++map_it) { |
791 const HostPortPair& server = map_it->first; | 832 const HostPortPair& server = map_it->first; |
792 const ServerPref& server_pref = map_it->second; | 833 const ServerPref& server_pref = map_it->second; |
793 | 834 |
794 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 835 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
795 | 836 |
796 // Save supports_spdy. | 837 // Save supports_spdy. |
797 if (server_pref.supports_spdy) | 838 if (server_pref.supports_spdy) |
798 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); | 839 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); |
799 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); | 840 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); |
800 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol, | 841 SaveAlternativeServiceToServerPrefs(server_pref.alternative_service, |
801 server_pref_dict); | 842 server_pref_dict); |
802 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, | 843 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, |
803 server_pref_dict); | 844 server_pref_dict); |
804 | 845 |
805 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 846 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
806 } | 847 } |
807 | 848 |
808 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, | 849 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, |
809 servers_dict); | 850 servers_dict); |
810 SetVersion(&http_server_properties_dict, kVersionNumber); | 851 SetVersion(&http_server_properties_dict, kVersionNumber); |
811 | 852 |
(...skipping 21 matching lines...) Expand all Loading... |
833 for (SettingsMap::const_iterator it = settings_map->begin(); | 874 for (SettingsMap::const_iterator it = settings_map->begin(); |
834 it != settings_map->end(); ++it) { | 875 it != settings_map->end(); ++it) { |
835 SpdySettingsIds id = it->first; | 876 SpdySettingsIds id = it->first; |
836 uint32 value = it->second.second; | 877 uint32 value = it->second.second; |
837 std::string key = base::StringPrintf("%u", id); | 878 std::string key = base::StringPrintf("%u", id); |
838 spdy_settings_dict->SetInteger(key, value); | 879 spdy_settings_dict->SetInteger(key, value); |
839 } | 880 } |
840 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); | 881 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); |
841 } | 882 } |
842 | 883 |
843 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( | 884 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( |
844 const AlternateProtocolInfo* port_alternate_protocol, | 885 const AlternativeServiceInfo* alternative_service_info, |
845 base::DictionaryValue* server_pref_dict) { | 886 base::DictionaryValue* server_pref_dict) { |
846 if (!port_alternate_protocol) | 887 if (!alternative_service_info) |
847 return; | 888 return; |
848 | 889 |
849 base::DictionaryValue* port_alternate_protocol_dict = | 890 const AlternativeService& alternative_service = |
| 891 alternative_service_info->alternative_service; |
| 892 base::DictionaryValue* alternative_service_info_dict = |
850 new base::DictionaryValue; | 893 new base::DictionaryValue; |
851 port_alternate_protocol_dict->SetInteger(kPortKey, | 894 alternative_service_info_dict->SetString( |
852 port_alternate_protocol->port); | 895 kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); |
853 const char* protocol_str = | 896 if (!alternative_service.host.empty()) { |
854 AlternateProtocolToString(port_alternate_protocol->protocol); | 897 alternative_service_info_dict->SetString(kHostKey, |
855 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); | 898 alternative_service.host); |
856 port_alternate_protocol_dict->SetDouble(kProbabilityKey, | 899 } |
857 port_alternate_protocol->probability); | 900 alternative_service_info_dict->SetInteger(kPortKey, alternative_service.port); |
858 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey, | 901 alternative_service_info_dict->SetDouble( |
859 port_alternate_protocol_dict); | 902 kProbabilityKey, alternative_service_info->probability); |
| 903 |
| 904 // Create a single element list here. |
| 905 // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, save |
| 906 // all of them. |
| 907 base::ListValue* alternative_service_list = new base::ListValue(); |
| 908 alternative_service_list->Append(alternative_service_info_dict); |
| 909 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, |
| 910 alternative_service_list); |
860 } | 911 } |
861 | 912 |
862 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( | 913 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |
863 const IPAddressNumber* last_quic_address, | 914 const IPAddressNumber* last_quic_address, |
864 base::DictionaryValue* http_server_properties_dict) { | 915 base::DictionaryValue* http_server_properties_dict) { |
865 if (!last_quic_address || last_quic_address->empty()) | 916 if (!last_quic_address || last_quic_address->empty()) |
866 return; | 917 return; |
867 | 918 |
868 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 919 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
869 supports_quic_dict->SetBoolean(kUsedQuicKey, true); | 920 supports_quic_dict->SetBoolean(kUsedQuicKey, true); |
(...skipping 19 matching lines...) Expand all Loading... |
889 server_network_stats_dict); | 940 server_network_stats_dict); |
890 } | 941 } |
891 | 942 |
892 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 943 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
893 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 944 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
894 if (!setting_prefs_) | 945 if (!setting_prefs_) |
895 ScheduleUpdateCacheOnPrefThread(); | 946 ScheduleUpdateCacheOnPrefThread(); |
896 } | 947 } |
897 | 948 |
898 } // namespace net | 949 } // namespace net |
OLD | NEW |