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

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

Issue 897313002: Refactor alternate protocol dictionary parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and use name constants. Created 5 years, 10 months 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.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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 << server.ToString(); 443 << server.ToString();
444 NOTREACHED(); 444 NOTREACHED();
445 continue; 445 continue;
446 } 446 }
447 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); 447 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value);
448 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; 448 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value;
449 } 449 }
450 spdy_settings_map->Put(server, settings_map); 450 spdy_settings_map->Put(server, settings_map);
451 } 451 }
452 452
453 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict(
454 const base::DictionaryValue& alternate_protocol_dict,
455 const std::string& server_str) {
456 AlternateProtocolInfo alternate_protocol;
457 int port = 0;
458 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) ||
459 !IsPortValid(port)) {
460 DVLOG(1) << "Malformed AltSvc port for server: " << server_str;
461 return alternate_protocol;
462 }
463 alternate_protocol.port = static_cast<uint16>(port);
464
465 double probability = 1.0;
466 if (alternate_protocol_dict.HasKey(kProbabilityKey) &&
467 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey,
468 &probability)) {
469 DVLOG(1) << "Malformed AltSvc probability for server: " << server_str;
470 return alternate_protocol;
471 }
472 alternate_protocol.probability = probability;
473
474 std::string protocol_str;
475 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey,
476 &protocol_str)) {
477 DVLOG(1) << "Malformed AltSvc protocol string for server: " << server_str;
478 return alternate_protocol;
479 }
480 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
481 if (!IsAlternateProtocolValid(protocol)) {
482 DVLOG(1) << "Invalid AltSvc protocol string for server: " << server_str;
483 return alternate_protocol;
484 }
485 alternate_protocol.protocol = protocol;
486
487 return alternate_protocol;
488 }
489
453 bool HttpServerPropertiesManager::AddToAlternateProtocolMap( 490 bool HttpServerPropertiesManager::AddToAlternateProtocolMap(
454 const HostPortPair& server, 491 const HostPortPair& server,
455 const base::DictionaryValue& server_pref_dict, 492 const base::DictionaryValue& server_pref_dict,
456 AlternateProtocolMap* alternate_protocol_map) { 493 AlternateProtocolMap* alternate_protocol_map) {
457 // Get alternate_protocol server. 494 // Get alternate_protocol server.
458 DCHECK(alternate_protocol_map->Peek(server) == alternate_protocol_map->end()); 495 DCHECK(alternate_protocol_map->Peek(server) == alternate_protocol_map->end());
459 const base::DictionaryValue* port_alternate_protocol_dict = NULL; 496 const base::DictionaryValue* alternate_protocol_dict = NULL;
460 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( 497 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
461 kAlternateProtocolKey, &port_alternate_protocol_dict)) { 498 kAlternateProtocolKey, &alternate_protocol_dict)) {
462 return true; 499 return true;
463 } 500 }
464 int port = 0; 501 AlternateProtocolInfo alternate_protocol =
465 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(kPortKey, 502 ParseAlternateProtocolDict(*alternate_protocol_dict, server.ToString());
466 &port) || 503 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
467 !IsPortValid(port)) {
468 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
469 return false; 504 return false;
470 } 505 alternate_protocol_map->Put(server, alternate_protocol);
471 std::string protocol_str;
472 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion(
473 kProtocolKey, &protocol_str)) {
474 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
475 return false;
476 }
477 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
478 if (!IsAlternateProtocolValid(protocol)) {
479 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
480 return false;
481 }
482 double probability = 1;
483 if (port_alternate_protocol_dict->HasKey(kProbabilityKey) &&
484 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
485 kProbabilityKey, &probability)) {
486 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
487 return false;
488 }
489
490 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
491 protocol, probability);
492 alternate_protocol_map->Put(server, port_alternate_protocol);
493 return true; 506 return true;
494 } 507 }
495 508
496 bool HttpServerPropertiesManager::ReadSupportsQuic( 509 bool HttpServerPropertiesManager::ReadSupportsQuic(
497 const base::DictionaryValue& http_server_properties_dict, 510 const base::DictionaryValue& http_server_properties_dict,
498 IPAddressNumber* last_quic_address) { 511 IPAddressNumber* last_quic_address) {
499 const base::DictionaryValue* supports_quic_dict = NULL; 512 const base::DictionaryValue* supports_quic_dict = NULL;
500 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 513 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
501 kSupportsQuicKey, &supports_quic_dict)) { 514 kSupportsQuicKey, &supports_quic_dict)) {
502 return true; 515 return true;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 server_network_stats_dict); 867 server_network_stats_dict);
855 } 868 }
856 869
857 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
858 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
859 if (!setting_prefs_) 872 if (!setting_prefs_)
860 ScheduleUpdateCacheOnPrefThread(); 873 ScheduleUpdateCacheOnPrefThread();
861 } 874 }
862 875
863 } // namespace net 876 } // 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