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

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

Issue 253903002: SPDY - persist 300 most recently used servers that support SPDY to preferences file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Persist 300 MRU servers that support SPDY Created 6 years, 7 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 46 // Persist 200 MRU AlternateProtocolHostPortPairs.
47 const int kMaxAlternateProtocolHostsToPersist = 200; 47 const int kMaxAlternateProtocolHostsToPersist = 200;
48 48
49 // Persist 200 MRU SpdySettingsHostPortPairs. 49 // Persist 200 MRU SpdySettingsHostPortPairs.
50 const int kMaxSpdySettingsHostsToPersist = 200; 50 const int kMaxSpdySettingsHostsToPersist = 200;
51 51
52 // Persist 300 MRU SupportsSpdyServerHostPortPairs.
53 const int kMaxSupportsSpdyServerHostsToPersist = 300;
54
52 } // namespace 55 } // namespace
53 56
54 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
55 // HttpServerPropertiesManager 58 // HttpServerPropertiesManager
56 59
57 HttpServerPropertiesManager::HttpServerPropertiesManager( 60 HttpServerPropertiesManager::HttpServerPropertiesManager(
58 PrefService* pref_service) 61 PrefService* pref_service)
59 : pref_service_(pref_service), 62 : pref_service_(pref_service),
60 setting_prefs_(false) { 63 setting_prefs_(false) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 135 }
133 136
134 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { 137 void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
136 139
137 http_server_properties_impl_->Clear(); 140 http_server_properties_impl_->Clear();
138 UpdatePrefsFromCacheOnIO(completion); 141 UpdatePrefsFromCacheOnIO(completion);
139 } 142 }
140 143
141 bool HttpServerPropertiesManager::SupportsSpdy( 144 bool HttpServerPropertiesManager::SupportsSpdy(
142 const net::HostPortPair& server) const { 145 const net::HostPortPair& server) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
144 return http_server_properties_impl_->SupportsSpdy(server); 147 return http_server_properties_impl_->SupportsSpdy(server);
145 } 148 }
146 149
147 void HttpServerPropertiesManager::SetSupportsSpdy( 150 void HttpServerPropertiesManager::SetSupportsSpdy(
148 const net::HostPortPair& server, 151 const net::HostPortPair& server,
149 bool support_spdy) { 152 bool support_spdy) {
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
151 154
152 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); 155 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 330
328 // The properties for a given server is in 331 // The properties for a given server is in
329 // http_server_properties_dict["servers"][server]. 332 // http_server_properties_dict["servers"][server].
330 const base::DictionaryValue* servers_dict = NULL; 333 const base::DictionaryValue* servers_dict = NULL;
331 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 334 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
332 "servers", &servers_dict)) { 335 "servers", &servers_dict)) {
333 DVLOG(1) << "Malformed http_server_properties for servers."; 336 DVLOG(1) << "Malformed http_server_properties for servers.";
334 return; 337 return;
335 } 338 }
336 339
337 // TODO(rtenneti): Mark entries with an LRU sequence number (date of access?),
338 // and then truncate down deleting old stuff.
339 if (version != kVersionNumber && servers_dict->size() > 300) {
340 DVLOG(1) << "Size is too large. Clearing all properties.";
341 return;
342 }
343
344 // String is host/port pair of spdy server. 340 // String is host/port pair of spdy server.
345 scoped_ptr<StringVector> spdy_servers(new StringVector); 341 scoped_ptr<StringVector> spdy_servers(new StringVector);
346 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( 342 scoped_ptr<net::SpdySettingsMap> spdy_settings_map(
347 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); 343 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist));
348 scoped_ptr<net::PipelineCapabilityMap> pipeline_capability_map( 344 scoped_ptr<net::PipelineCapabilityMap> pipeline_capability_map(
349 new net::PipelineCapabilityMap); 345 new net::PipelineCapabilityMap);
350 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( 346 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map(
351 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); 347 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist));
352 348
353 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 349 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // This is required so we can set this as the callback for a timer. 521 // This is required so we can set this as the callback for a timer.
526 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() { 522 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
527 UpdatePrefsFromCacheOnIO(base::Closure()); 523 UpdatePrefsFromCacheOnIO(base::Closure());
528 } 524 }
529 525
530 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO( 526 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
531 const base::Closure& completion) { 527 const base::Closure& completion) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
533 529
534 base::ListValue* spdy_server_list = new base::ListValue; 530 base::ListValue* spdy_server_list = new base::ListValue;
535 http_server_properties_impl_->GetSpdyServerList(spdy_server_list); 531 http_server_properties_impl_->GetSpdyServerList(
532 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist);
536 533
537 net::SpdySettingsMap* spdy_settings_map = 534 net::SpdySettingsMap* spdy_settings_map =
538 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); 535 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist);
539 const net::SpdySettingsMap& main_map = 536 const net::SpdySettingsMap& main_map =
540 http_server_properties_impl_->spdy_settings_map(); 537 http_server_properties_impl_->spdy_settings_map();
541 int count = 0; 538 int count = 0;
542 for (net::SpdySettingsMap::const_iterator it = main_map.begin(); 539 for (net::SpdySettingsMap::const_iterator it = main_map.begin();
543 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; 540 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist;
544 ++it, ++count) { 541 ++it, ++count) {
545 spdy_settings_map->Put(it->first, it->second); 542 spdy_settings_map->Put(it->first, it->second);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 net::HttpPipelinedHostCapability pipeline_capability; 595 net::HttpPipelinedHostCapability pipeline_capability;
599 }; 596 };
600 597
601 void HttpServerPropertiesManager::UpdatePrefsOnUI( 598 void HttpServerPropertiesManager::UpdatePrefsOnUI(
602 base::ListValue* spdy_server_list, 599 base::ListValue* spdy_server_list,
603 net::SpdySettingsMap* spdy_settings_map, 600 net::SpdySettingsMap* spdy_settings_map,
604 net::AlternateProtocolMap* alternate_protocol_map, 601 net::AlternateProtocolMap* alternate_protocol_map,
605 net::PipelineCapabilityMap* pipeline_capability_map, 602 net::PipelineCapabilityMap* pipeline_capability_map,
606 const base::Closure& completion) { 603 const base::Closure& completion) {
607 604
608 // TODO(rtenneti): Fix ServerPrefMap to preserve MRU order of
609 // spdy_settings_map, alternate_protocol_map and pipeline_capability_map.
610 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; 605 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
611 ServerPrefMap server_pref_map; 606 ServerPrefMap server_pref_map;
612 607
613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
614 609
615 // Add servers that support spdy to server_pref_map. 610 // Add servers that support spdy to server_pref_map.
616 std::string s; 611 std::string s;
617 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 612 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
618 list_it != spdy_server_list->end(); ++list_it) { 613 list_it != spdy_server_list->end(); ++list_it) {
619 if ((*list_it)->GetAsString(&s)) { 614 if ((*list_it)->GetAsString(&s)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 base::DictionaryValue* servers_dict = new base::DictionaryValue; 680 base::DictionaryValue* servers_dict = new base::DictionaryValue;
686 for (ServerPrefMap::const_iterator map_it = 681 for (ServerPrefMap::const_iterator map_it =
687 server_pref_map.begin(); 682 server_pref_map.begin();
688 map_it != server_pref_map.end(); ++map_it) { 683 map_it != server_pref_map.end(); ++map_it) {
689 const net::HostPortPair& server = map_it->first; 684 const net::HostPortPair& server = map_it->first;
690 const ServerPref& server_pref = map_it->second; 685 const ServerPref& server_pref = map_it->second;
691 686
692 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 687 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
693 688
694 // Save supports_spdy. 689 // Save supports_spdy.
695 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); 690 if (server_pref.supports_spdy)
691 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy);
696 692
697 // Save SPDY settings. 693 // Save SPDY settings.
698 if (server_pref.settings_map) { 694 if (server_pref.settings_map) {
699 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; 695 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue;
700 for (net::SettingsMap::const_iterator it = 696 for (net::SettingsMap::const_iterator it =
701 server_pref.settings_map->begin(); 697 server_pref.settings_map->begin();
702 it != server_pref.settings_map->end(); ++it) { 698 it != server_pref.settings_map->end(); ++it) {
703 net::SpdySettingsIds id = it->first; 699 net::SpdySettingsIds id = it->first;
704 uint32 value = it->second.second; 700 uint32 value = it->second.second;
705 std::string key = base::StringPrintf("%u", id); 701 std::string key = base::StringPrintf("%u", id);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 completion.Run(); 742 completion.Run();
747 } 743 }
748 744
749 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 745 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
750 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
751 if (!setting_prefs_) 747 if (!setting_prefs_)
752 ScheduleUpdateCacheOnUI(); 748 ScheduleUpdateCacheOnUI();
753 } 749 }
754 750
755 } // namespace chrome_browser_net 751 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/http_server_properties_manager.h ('k') | content/browser/loader/resource_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698