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

Side by Side Diff: chrome/browser/net/http_server_properties_manager.cc

Issue 182383016: HttpServerProperties - Implement MRU for AlternateProtocolMap. Persist (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Used MRUCache for AlternateProtocolMap. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/net/http_server_properties_manager.h" 5 #include "chrome/browser/net/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/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 25 matching lines...) Expand all
36 36
37 // "version" 0 indicates, http_server_properties doesn't have "version" 37 // "version" 0 indicates, http_server_properties doesn't have "version"
38 // property. 38 // property.
39 const int kMissingVersion = 0; 39 const int kMissingVersion = 0;
40 40
41 // The version number of persisted http_server_properties. 41 // The version number of persisted http_server_properties.
42 const int kVersionNumber = 2; 42 const int kVersionNumber = 2;
43 43
44 typedef std::vector<std::string> StringVector; 44 typedef std::vector<std::string> StringVector;
45 45
46 // Persist 200 MRU AlternateProtocolHostPortPairs.
47 const int kMaxAlternateProtocolHostsToPersist = 200;
48
46 } // namespace 49 } // namespace
47 50
48 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
49 // HttpServerPropertiesManager 52 // HttpServerPropertiesManager
50 53
51 HttpServerPropertiesManager::HttpServerPropertiesManager( 54 HttpServerPropertiesManager::HttpServerPropertiesManager(
52 PrefService* pref_service) 55 PrefService* pref_service)
53 : pref_service_(pref_service), 56 : pref_service_(pref_service),
54 setting_prefs_(false) { 57 setting_prefs_(false) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void HttpServerPropertiesManager::SetSupportsSpdy( 144 void HttpServerPropertiesManager::SetSupportsSpdy(
142 const net::HostPortPair& server, 145 const net::HostPortPair& server,
143 bool support_spdy) { 146 bool support_spdy) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
145 148
146 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); 149 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
147 ScheduleUpdatePrefsOnIO(); 150 ScheduleUpdatePrefsOnIO();
148 } 151 }
149 152
150 bool HttpServerPropertiesManager::HasAlternateProtocol( 153 bool HttpServerPropertiesManager::HasAlternateProtocol(
151 const net::HostPortPair& server) const { 154 const net::HostPortPair& server) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
153 return http_server_properties_impl_->HasAlternateProtocol(server); 156 return http_server_properties_impl_->HasAlternateProtocol(server);
154 } 157 }
155 158
156 net::PortAlternateProtocolPair 159 net::PortAlternateProtocolPair
157 HttpServerPropertiesManager::GetAlternateProtocol( 160 HttpServerPropertiesManager::GetAlternateProtocol(
158 const net::HostPortPair& server) const { 161 const net::HostPortPair& server) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
160 return http_server_properties_impl_->GetAlternateProtocol(server); 163 return http_server_properties_impl_->GetAlternateProtocol(server);
161 } 164 }
162 165
163 void HttpServerPropertiesManager::SetAlternateProtocol( 166 void HttpServerPropertiesManager::SetAlternateProtocol(
164 const net::HostPortPair& server, 167 const net::HostPortPair& server,
165 uint16 alternate_port, 168 uint16 alternate_port,
166 net::AlternateProtocol alternate_protocol) { 169 net::AlternateProtocol alternate_protocol) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
168 http_server_properties_impl_->SetAlternateProtocol( 171 http_server_properties_impl_->SetAlternateProtocol(
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 DVLOG(1) << "Size is too large. Clearing all properties."; 316 DVLOG(1) << "Size is too large. Clearing all properties.";
314 return; 317 return;
315 } 318 }
316 319
317 // String is host/port pair of spdy server. 320 // String is host/port pair of spdy server.
318 scoped_ptr<StringVector> spdy_servers(new StringVector); 321 scoped_ptr<StringVector> spdy_servers(new StringVector);
319 scoped_ptr<net::SpdySettingsMap> spdy_settings_map(new net::SpdySettingsMap); 322 scoped_ptr<net::SpdySettingsMap> spdy_settings_map(new net::SpdySettingsMap);
320 scoped_ptr<net::PipelineCapabilityMap> pipeline_capability_map( 323 scoped_ptr<net::PipelineCapabilityMap> pipeline_capability_map(
321 new net::PipelineCapabilityMap); 324 new net::PipelineCapabilityMap);
322 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( 325 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map(
323 new net::AlternateProtocolMap); 326 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist));
324 327
325 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 328 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd();
326 it.Advance()) { 329 it.Advance()) {
327 // Get server's host/pair. 330 // Get server's host/pair.
328 const std::string& server_str = it.key(); 331 const std::string& server_str = it.key();
329 net::HostPortPair server = net::HostPortPair::FromString(server_str); 332 net::HostPortPair server = net::HostPortPair::FromString(server_str);
330 if (server.host().empty()) { 333 if (server.host().empty()) {
331 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 334 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
332 detected_corrupted_prefs = true; 335 detected_corrupted_prefs = true;
333 continue; 336 continue;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 382
380 int pipeline_capability = net::PIPELINE_UNKNOWN; 383 int pipeline_capability = net::PIPELINE_UNKNOWN;
381 if ((server_pref_dict->GetInteger( 384 if ((server_pref_dict->GetInteger(
382 "pipeline_capability", &pipeline_capability)) && 385 "pipeline_capability", &pipeline_capability)) &&
383 pipeline_capability != net::PIPELINE_UNKNOWN) { 386 pipeline_capability != net::PIPELINE_UNKNOWN) {
384 (*pipeline_capability_map)[server] = 387 (*pipeline_capability_map)[server] =
385 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability); 388 static_cast<net::HttpPipelinedHostCapability>(pipeline_capability);
386 } 389 }
387 390
388 // Get alternate_protocol server. 391 // Get alternate_protocol server.
389 DCHECK(!ContainsKey(*alternate_protocol_map, server)); 392 DCHECK(alternate_protocol_map->Peek(server) ==
393 alternate_protocol_map->end());
390 const base::DictionaryValue* port_alternate_protocol_dict = NULL; 394 const base::DictionaryValue* port_alternate_protocol_dict = NULL;
391 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( 395 if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
392 "alternate_protocol", &port_alternate_protocol_dict)) { 396 "alternate_protocol", &port_alternate_protocol_dict)) {
393 continue; 397 continue;
394 } 398 }
395 399
396 do { 400 do {
397 int port = 0; 401 int port = 0;
398 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( 402 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
399 "port", &port) || (port > (1 << 16))) { 403 "port", &port) || (port > (1 << 16))) {
(...skipping 13 matching lines...) Expand all
413 if (!net::IsAlternateProtocolValid(protocol)) { 417 if (!net::IsAlternateProtocolValid(protocol)) {
414 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; 418 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
415 detected_corrupted_prefs = true; 419 detected_corrupted_prefs = true;
416 continue; 420 continue;
417 } 421 }
418 422
419 net::PortAlternateProtocolPair port_alternate_protocol; 423 net::PortAlternateProtocolPair port_alternate_protocol;
420 port_alternate_protocol.port = port; 424 port_alternate_protocol.port = port;
421 port_alternate_protocol.protocol = protocol; 425 port_alternate_protocol.protocol = protocol;
422 426
423 (*alternate_protocol_map)[server] = port_alternate_protocol; 427 alternate_protocol_map->Put(server, port_alternate_protocol);
424 } while (false); 428 } while (false);
425 } 429 }
426 430
427 BrowserThread::PostTask( 431 BrowserThread::PostTask(
428 BrowserThread::IO, 432 BrowserThread::IO,
429 FROM_HERE, 433 FROM_HERE,
430 base::Bind(&HttpServerPropertiesManager:: 434 base::Bind(&HttpServerPropertiesManager::
431 UpdateCacheFromPrefsOnIO, 435 UpdateCacheFromPrefsOnIO,
432 base::Unretained(this), 436 base::Unretained(this),
433 base::Owned(spdy_servers.release()), 437 base::Owned(spdy_servers.release()),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 const base::Closure& completion) { 506 const base::Closure& completion) {
503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
504 508
505 base::ListValue* spdy_server_list = new base::ListValue; 509 base::ListValue* spdy_server_list = new base::ListValue;
506 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); 510 http_server_properties_impl_->GetSpdyServerList(spdy_server_list);
507 511
508 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap; 512 net::SpdySettingsMap* spdy_settings_map = new net::SpdySettingsMap;
509 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map(); 513 *spdy_settings_map = http_server_properties_impl_->spdy_settings_map();
510 514
511 net::AlternateProtocolMap* alternate_protocol_map = 515 net::AlternateProtocolMap* alternate_protocol_map =
512 new net::AlternateProtocolMap; 516 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist);
513 *alternate_protocol_map = 517 const net::AlternateProtocolMap& map =
514 http_server_properties_impl_->alternate_protocol_map(); 518 http_server_properties_impl_->alternate_protocol_map();
519 int count = 0;
520 for (net::AlternateProtocolMap::const_iterator it = map.begin();
521 it != map.end() && count < kMaxAlternateProtocolHostsToPersist;
522 ++it, ++count) {
523 alternate_protocol_map->Put(it->first, it->second);
524 }
515 525
516 net::PipelineCapabilityMap* pipeline_capability_map = 526 net::PipelineCapabilityMap* pipeline_capability_map =
517 new net::PipelineCapabilityMap; 527 new net::PipelineCapabilityMap;
518 *pipeline_capability_map = 528 *pipeline_capability_map =
519 http_server_properties_impl_->GetPipelineCapabilityMap(); 529 http_server_properties_impl_->GetPipelineCapabilityMap();
520 530
521 // Update the preferences on the UI thread. 531 // Update the preferences on the UI thread.
522 BrowserThread::PostTask( 532 BrowserThread::PostTask(
523 BrowserThread::UI, 533 BrowserThread::UI,
524 FROM_HERE, 534 FROM_HERE,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 if (it == server_pref_map.end()) { 588 if (it == server_pref_map.end()) {
579 ServerPref server_pref(true, NULL, NULL); 589 ServerPref server_pref(true, NULL, NULL);
580 server_pref_map[server] = server_pref; 590 server_pref_map[server] = server_pref;
581 } else { 591 } else {
582 it->second.supports_spdy = true; 592 it->second.supports_spdy = true;
583 } 593 }
584 } 594 }
585 } 595 }
586 596
587 // Add servers that have SpdySettings to server_pref_map. 597 // Add servers that have SpdySettings to server_pref_map.
588 for (net::SpdySettingsMap::iterator map_it = 598 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin();
589 spdy_settings_map->begin();
590 map_it != spdy_settings_map->end(); ++map_it) { 599 map_it != spdy_settings_map->end(); ++map_it) {
591 const net::HostPortPair& server = map_it->first; 600 const net::HostPortPair& server = map_it->first;
592 601
593 ServerPrefMap::iterator it = server_pref_map.find(server); 602 ServerPrefMap::iterator it = server_pref_map.find(server);
594 if (it == server_pref_map.end()) { 603 if (it == server_pref_map.end()) {
595 ServerPref server_pref(false, &map_it->second, NULL); 604 ServerPref server_pref(false, &map_it->second, NULL);
596 server_pref_map[server] = server_pref; 605 server_pref_map[server] = server_pref;
597 } else { 606 } else {
598 it->second.settings_map = &map_it->second; 607 it->second.settings_map = &map_it->second;
599 } 608 }
600 } 609 }
601 610
602 // Add AlternateProtocol servers to server_pref_map. 611 // Add AlternateProtocol servers to server_pref_map.
603 for (net::AlternateProtocolMap::const_iterator map_it = 612 for (net::AlternateProtocolMap::const_iterator map_it =
604 alternate_protocol_map->begin(); 613 alternate_protocol_map->begin();
605 map_it != alternate_protocol_map->end(); ++map_it) { 614 map_it != alternate_protocol_map->end(); ++map_it) {
606 const net::HostPortPair& server = map_it->first; 615 const net::HostPortPair& server = map_it->first;
607 const net::PortAlternateProtocolPair& port_alternate_protocol = 616 const net::PortAlternateProtocolPair& port_alternate_protocol =
608 map_it->second; 617 map_it->second;
609 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { 618 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
610 continue; 619 continue;
611 } 620 }
612 621
613 ServerPrefMap::iterator it = server_pref_map.find(server); 622 ServerPrefMap::iterator it = server_pref_map.find(server);
614 if (it == server_pref_map.end()) { 623 if (it == server_pref_map.end()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 completion.Run(); 711 completion.Run();
703 } 712 }
704 713
705 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 714 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
707 if (!setting_prefs_) 716 if (!setting_prefs_)
708 ScheduleUpdateCacheOnUI(); 717 ScheduleUpdateCacheOnUI();
709 } 718 }
710 719
711 } // namespace chrome_browser_net 720 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698