Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: net/http/http_server_properties_manager.cc

Issue 1546493002: HttpServerProperties - Minor reorganization of code in preperation of (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ServerList - fix comments for PatchSet 1 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 19 matching lines...) Expand all
30 // period will reset the timer. 30 // period will reset the timer.
31 const int64_t kUpdatePrefsDelayMs = 60000; 31 const int64_t kUpdatePrefsDelayMs = 60000;
32 32
33 // "version" 0 indicates, http_server_properties doesn't have "version" 33 // "version" 0 indicates, http_server_properties doesn't have "version"
34 // property. 34 // property.
35 const int kMissingVersion = 0; 35 const int kMissingVersion = 0;
36 36
37 // The version number of persisted http_server_properties. 37 // The version number of persisted http_server_properties.
38 const int kVersionNumber = 3; 38 const int kVersionNumber = 3;
39 39
40 typedef std::vector<std::string> StringVector;
41
42 // Persist 200 MRU AlternateProtocolHostPortPairs. 40 // Persist 200 MRU AlternateProtocolHostPortPairs.
43 const int kMaxAlternateProtocolHostsToPersist = 200; 41 const int kMaxAlternateProtocolHostsToPersist = 200;
44 42
45 // Persist 200 MRU SpdySettingsHostPortPairs. 43 // Persist 200 MRU SpdySettingsHostPortPairs.
46 const int kMaxSpdySettingsHostsToPersist = 200; 44 const int kMaxSpdySettingsHostsToPersist = 200;
47 45
48 // Persist 300 MRU SupportsSpdyServerHostPortPairs. 46 // Persist 300 MRU SupportsSpdyServerHostPortPairs.
49 const int kMaxSupportsSpdyServerHostsToPersist = 300; 47 const int kMaxSupportsSpdyServerHostsToPersist = 300;
50 48
51 // Persist 200 ServerNetworkStats. 49 // Persist 200 ServerNetworkStats.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 440
443 int version = kMissingVersion; 441 int version = kMissingVersion;
444 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey, 442 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey,
445 &version)) { 443 &version)) {
446 DVLOG(1) << "Missing version. Clearing all properties."; 444 DVLOG(1) << "Missing version. Clearing all properties.";
447 return; 445 return;
448 } 446 }
449 447
450 // The properties for a given server is in 448 // The properties for a given server is in
451 // http_server_properties_dict["servers"][server]. 449 // http_server_properties_dict["servers"][server].
450 // Server data was stored in the following format in alphabetical order.
451 //
452 // "http_server_properties": {
453 // "servers": {
454 // "accounts.google.com:443": {...},
455 // "accounts.youtube.com:443": {...},
456 // "android.clients.google.com:443": {...},
457 // ...
458 // }, ...
459 // },
452 const base::DictionaryValue* servers_dict = NULL; 460 const base::DictionaryValue* servers_dict = NULL;
453 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 461 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
454 kServersKey, &servers_dict)) { 462 kServersKey, &servers_dict)) {
455 DVLOG(1) << "Malformed http_server_properties for servers."; 463 DVLOG(1) << "Malformed http_server_properties for servers.";
456 return; 464 return;
457 } 465 }
458 466
459 IPAddressNumber* addr = new IPAddressNumber; 467 IPAddressNumber* addr = new IPAddressNumber;
460 ReadSupportsQuic(http_server_properties_dict, addr); 468 ReadSupportsQuic(http_server_properties_dict, addr);
461 469
462 // String is host/port pair of spdy server. 470 // String is host/port pair of spdy server.
463 scoped_ptr<StringVector> spdy_servers(new StringVector); 471 scoped_ptr<ServerList> spdy_servers(new ServerList);
464 scoped_ptr<SpdySettingsMap> spdy_settings_map( 472 scoped_ptr<SpdySettingsMap> spdy_settings_map(
465 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); 473 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist));
466 scoped_ptr<AlternativeServiceMap> alternative_service_map( 474 scoped_ptr<AlternativeServiceMap> alternative_service_map(
467 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); 475 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist));
468 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( 476 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map(
469 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); 477 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist));
470 scoped_ptr<QuicServerInfoMap> quic_server_info_map( 478 scoped_ptr<QuicServerInfoMap> quic_server_info_map(
471 new QuicServerInfoMap(kMaxQuicServersToPersist)); 479 new QuicServerInfoMap(kMaxQuicServersToPersist));
472 480
473 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 481 if (!AddServersData(*servers_dict, spdy_servers.get(),
482 spdy_settings_map.get(), alternative_service_map.get(),
483 server_network_stats_map.get())) {
484 detected_corrupted_prefs = true;
485 }
486
487 if (!AddToQuicServerInfoMap(http_server_properties_dict,
488 quic_server_info_map.get())) {
489 detected_corrupted_prefs = true;
490 }
491
492 network_task_runner_->PostTask(
493 FROM_HERE,
494 base::Bind(
495 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread,
496 base::Unretained(this), base::Owned(spdy_servers.release()),
497 base::Owned(spdy_settings_map.release()),
498 base::Owned(alternative_service_map.release()), base::Owned(addr),
499 base::Owned(server_network_stats_map.release()),
500 base::Owned(quic_server_info_map.release()),
501 detected_corrupted_prefs));
502 }
503
504 bool HttpServerPropertiesManager::AddServersData(
505 const base::DictionaryValue& servers_dict,
506 ServerList* spdy_servers,
507 SpdySettingsMap* spdy_settings_map,
508 AlternativeServiceMap* alternative_service_map,
509 ServerNetworkStatsMap* network_stats_map) {
510 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd();
474 it.Advance()) { 511 it.Advance()) {
475 // Get server's host/pair. 512 // Get server's host/pair.
476 const std::string& server_str = it.key(); 513 const std::string& server_str = it.key();
477 HostPortPair server = HostPortPair::FromString(server_str); 514 HostPortPair server = HostPortPair::FromString(server_str);
478 if (server.host().empty()) { 515 if (server.host().empty()) {
479 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 516 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
480 detected_corrupted_prefs = true; 517 return false;
481 continue;
482 } 518 }
483 519
484 const base::DictionaryValue* server_pref_dict = NULL; 520 const base::DictionaryValue* server_pref_dict = NULL;
485 if (!it.value().GetAsDictionary(&server_pref_dict)) { 521 if (!it.value().GetAsDictionary(&server_pref_dict)) {
486 DVLOG(1) << "Malformed http_server_properties server: " << server_str; 522 DVLOG(1) << "Malformed http_server_properties server: " << server_str;
487 detected_corrupted_prefs = true; 523 return false;
488 continue;
489 } 524 }
490 525
491 // Get if server supports Spdy. 526 // Get if server supports Spdy.
492 bool supports_spdy = false; 527 bool supports_spdy = false;
493 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && 528 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) &&
494 supports_spdy) { 529 supports_spdy) {
495 spdy_servers->push_back(server_str); 530 spdy_servers->push_back(server_str);
496 } 531 }
497 532
498 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); 533 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map);
499 if (!AddToAlternativeServiceMap(server, *server_pref_dict, 534 if (!AddToAlternativeServiceMap(server, *server_pref_dict,
500 alternative_service_map.get()) || 535 alternative_service_map) ||
501 !AddToNetworkStatsMap(server, *server_pref_dict, 536 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) {
502 server_network_stats_map.get())) { 537 return false;
503 detected_corrupted_prefs = true;
504 } 538 }
505 } 539 }
506 540 return true;
507 if (!AddToQuicServerInfoMap(http_server_properties_dict,
508 quic_server_info_map.get())) {
509 detected_corrupted_prefs = true;
510 }
511
512 network_task_runner_->PostTask(
513 FROM_HERE,
514 base::Bind(
515 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread,
516 base::Unretained(this), base::Owned(spdy_servers.release()),
517 base::Owned(spdy_settings_map.release()),
518 base::Owned(alternative_service_map.release()), base::Owned(addr),
519 base::Owned(server_network_stats_map.release()),
520 base::Owned(quic_server_info_map.release()),
521 detected_corrupted_prefs));
522 } 541 }
523 542
524 void HttpServerPropertiesManager::AddToSpdySettingsMap( 543 void HttpServerPropertiesManager::AddToSpdySettingsMap(
525 const HostPortPair& server, 544 const HostPortPair& server,
526 const base::DictionaryValue& server_pref_dict, 545 const base::DictionaryValue& server_pref_dict,
527 SpdySettingsMap* spdy_settings_map) { 546 SpdySettingsMap* spdy_settings_map) {
528 // Get SpdySettings. 547 // Get SpdySettings.
529 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); 548 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end());
530 const base::DictionaryValue* spdy_settings_dict = NULL; 549 const base::DictionaryValue* spdy_settings_dict = NULL;
531 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( 550 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 << quic_server_id_str; 780 << quic_server_id_str;
762 detected_corrupted_prefs = true; 781 detected_corrupted_prefs = true;
763 continue; 782 continue;
764 } 783 }
765 quic_server_info_map->Put(quic_server_id, quic_server_info); 784 quic_server_info_map->Put(quic_server_id, quic_server_info);
766 } 785 }
767 return !detected_corrupted_prefs; 786 return !detected_corrupted_prefs;
768 } 787 }
769 788
770 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( 789 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
771 StringVector* spdy_servers, 790 ServerList* spdy_servers,
772 SpdySettingsMap* spdy_settings_map, 791 SpdySettingsMap* spdy_settings_map,
773 AlternativeServiceMap* alternative_service_map, 792 AlternativeServiceMap* alternative_service_map,
774 IPAddressNumber* last_quic_address, 793 IPAddressNumber* last_quic_address,
775 ServerNetworkStatsMap* server_network_stats_map, 794 ServerNetworkStatsMap* server_network_stats_map,
776 QuicServerInfoMap* quic_server_info_map, 795 QuicServerInfoMap* quic_server_info_map,
777 bool detected_corrupted_prefs) { 796 bool detected_corrupted_prefs) {
778 // Preferences have the master data because admins might have pushed new 797 // Preferences have the master data because admins might have pushed new
779 // preferences. Update the cached data with new data from preferences. 798 // preferences. Update the cached data with new data from preferences.
780 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 799 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
781 800
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 quic_servers_dict); 1180 quic_servers_dict);
1162 } 1181 }
1163 1182
1164 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1183 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1165 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1184 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1166 if (!setting_prefs_) 1185 if (!setting_prefs_)
1167 ScheduleUpdateCacheOnPrefThread(); 1186 ScheduleUpdateCacheOnPrefThread();
1168 } 1187 }
1169 1188
1170 } // namespace net 1189 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698