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

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

Issue 339663010: Add a probability to Alternate-Protocol support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better plumbing Created 6 years, 5 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/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); 159 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
160 ScheduleUpdatePrefsOnIO(); 160 ScheduleUpdatePrefsOnIO();
161 } 161 }
162 162
163 bool HttpServerPropertiesManager::HasAlternateProtocol( 163 bool HttpServerPropertiesManager::HasAlternateProtocol(
164 const net::HostPortPair& server) { 164 const net::HostPortPair& server) {
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
166 return http_server_properties_impl_->HasAlternateProtocol(server); 166 return http_server_properties_impl_->HasAlternateProtocol(server);
167 } 167 }
168 168
169 net::PortAlternateProtocolPair 169 net::AlternateProtocolInfo
170 HttpServerPropertiesManager::GetAlternateProtocol( 170 HttpServerPropertiesManager::GetAlternateProtocol(
171 const net::HostPortPair& server) { 171 const net::HostPortPair& server) {
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
173 return http_server_properties_impl_->GetAlternateProtocol(server); 173 return http_server_properties_impl_->GetAlternateProtocol(server);
174 } 174 }
175 175
176 void HttpServerPropertiesManager::SetAlternateProtocol( 176 void HttpServerPropertiesManager::SetAlternateProtocol(
177 const net::HostPortPair& server, 177 const net::HostPortPair& server,
178 uint16 alternate_port, 178 uint16 alternate_port,
179 net::AlternateProtocol alternate_protocol) { 179 net::AlternateProtocol alternate_protocol,
180 double alternate_probability) {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
181 http_server_properties_impl_->SetAlternateProtocol( 182 http_server_properties_impl_->SetAlternateProtocol(
182 server, alternate_port, alternate_protocol); 183 server, alternate_port, alternate_protocol, alternate_probability);
183 ScheduleUpdatePrefsOnIO(); 184 ScheduleUpdatePrefsOnIO();
184 } 185 }
185 186
186 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( 187 void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
187 const net::HostPortPair& server) { 188 const net::HostPortPair& server) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
189 http_server_properties_impl_->SetBrokenAlternateProtocol(server); 190 http_server_properties_impl_->SetBrokenAlternateProtocol(server);
190 ScheduleUpdatePrefsOnIO(); 191 ScheduleUpdatePrefsOnIO();
191 } 192 }
192 193
(...skipping 19 matching lines...) Expand all
212 } 213 }
213 214
214 const net::AlternateProtocolMap& 215 const net::AlternateProtocolMap&
215 HttpServerPropertiesManager::alternate_protocol_map() const { 216 HttpServerPropertiesManager::alternate_protocol_map() const {
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
217 return http_server_properties_impl_->alternate_protocol_map(); 218 return http_server_properties_impl_->alternate_protocol_map();
218 } 219 }
219 220
220 void HttpServerPropertiesManager::SetAlternateProtocolExperiment( 221 void HttpServerPropertiesManager::SetAlternateProtocolExperiment(
221 net::AlternateProtocolExperiment experiment) { 222 net::AlternateProtocolExperiment experiment) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ramant (doing other things) 2014/06/27 22:38:13 Thanks for adding the DCHECKs.
Ryan Hamilton 2014/06/30 19:02:34 My pleasure!
222 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment); 224 http_server_properties_impl_->SetAlternateProtocolExperiment(experiment);
223 } 225 }
224 226
227 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold(
228 double threshold) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
230 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold(
231 threshold);
232 }
233
225 net::AlternateProtocolExperiment 234 net::AlternateProtocolExperiment
226 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const { 235 HttpServerPropertiesManager::GetAlternateProtocolExperiment() const {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
227 return http_server_properties_impl_->GetAlternateProtocolExperiment(); 237 return http_server_properties_impl_->GetAlternateProtocolExperiment();
228 } 238 }
229 239
230 const net::SettingsMap& 240 const net::SettingsMap&
231 HttpServerPropertiesManager::GetSpdySettings( 241 HttpServerPropertiesManager::GetSpdySettings(
232 const net::HostPortPair& host_port_pair) { 242 const net::HostPortPair& host_port_pair) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
234 return http_server_properties_impl_->GetSpdySettings(host_port_pair); 244 return http_server_properties_impl_->GetSpdySettings(host_port_pair);
235 } 245 }
236 246
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 continue; 442 continue;
433 } 443 }
434 net::AlternateProtocol protocol = 444 net::AlternateProtocol protocol =
435 net::AlternateProtocolFromString(protocol_str); 445 net::AlternateProtocolFromString(protocol_str);
436 if (!net::IsAlternateProtocolValid(protocol)) { 446 if (!net::IsAlternateProtocolValid(protocol)) {
437 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; 447 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
438 detected_corrupted_prefs = true; 448 detected_corrupted_prefs = true;
439 continue; 449 continue;
440 } 450 }
441 451
442 net::PortAlternateProtocolPair port_alternate_protocol; 452 double probability = 1;
443 port_alternate_protocol.port = port; 453 if (port_alternate_protocol_dict->HasKey("probability") &&
444 port_alternate_protocol.protocol = protocol; 454 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
455 "probability", &probability)) {
456 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
457 detected_corrupted_prefs = true;
458 continue;
459 }
445 460
461 net::AlternateProtocolInfo port_alternate_protocol(port,
462 protocol,
463 probability);
446 alternate_protocol_map->Put(server, port_alternate_protocol); 464 alternate_protocol_map->Put(server, port_alternate_protocol);
447 ++count; 465 ++count;
448 } while (false); 466 } while (false);
449 } 467 }
450 468
451 BrowserThread::PostTask( 469 BrowserThread::PostTask(
452 BrowserThread::IO, 470 BrowserThread::IO,
453 FROM_HERE, 471 FROM_HERE,
454 base::Bind(&HttpServerPropertiesManager:: 472 base::Bind(&HttpServerPropertiesManager::
455 UpdateCacheFromPrefsOnIO, 473 UpdateCacheFromPrefsOnIO,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 FROM_HERE, 584 FROM_HERE,
567 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI, 585 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
568 ui_weak_ptr_, 586 ui_weak_ptr_,
569 base::Owned(spdy_server_list), 587 base::Owned(spdy_server_list),
570 base::Owned(spdy_settings_map), 588 base::Owned(spdy_settings_map),
571 base::Owned(alternate_protocol_map), 589 base::Owned(alternate_protocol_map),
572 completion)); 590 completion));
573 } 591 }
574 592
575 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 593 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
576 // and PortAlternateProtocolPair preferences for a server. This is used only in 594 // and AlternateProtocolInfo preferences for a server. This is used only in
577 // UpdatePrefsOnUI. 595 // UpdatePrefsOnUI.
578 struct ServerPref { 596 struct ServerPref {
579 ServerPref() 597 ServerPref()
580 : supports_spdy(false), 598 : supports_spdy(false),
581 settings_map(NULL), 599 settings_map(NULL),
582 alternate_protocol(NULL) { 600 alternate_protocol(NULL) {
583 } 601 }
584 ServerPref(bool supports_spdy, 602 ServerPref(bool supports_spdy,
585 const net::SettingsMap* settings_map, 603 const net::SettingsMap* settings_map,
586 const net::PortAlternateProtocolPair* alternate_protocol) 604 const net::AlternateProtocolInfo* alternate_protocol)
587 : supports_spdy(supports_spdy), 605 : supports_spdy(supports_spdy),
588 settings_map(settings_map), 606 settings_map(settings_map),
589 alternate_protocol(alternate_protocol) { 607 alternate_protocol(alternate_protocol) {
590 } 608 }
591 bool supports_spdy; 609 bool supports_spdy;
592 const net::SettingsMap* settings_map; 610 const net::SettingsMap* settings_map;
593 const net::PortAlternateProtocolPair* alternate_protocol; 611 const net::AlternateProtocolInfo* alternate_protocol;
594 }; 612 };
595 613
596 void HttpServerPropertiesManager::UpdatePrefsOnUI( 614 void HttpServerPropertiesManager::UpdatePrefsOnUI(
597 base::ListValue* spdy_server_list, 615 base::ListValue* spdy_server_list,
598 net::SpdySettingsMap* spdy_settings_map, 616 net::SpdySettingsMap* spdy_settings_map,
599 net::AlternateProtocolMap* alternate_protocol_map, 617 net::AlternateProtocolMap* alternate_protocol_map,
600 const base::Closure& completion) { 618 const base::Closure& completion) {
601 619
602 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; 620 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
603 ServerPrefMap server_pref_map; 621 ServerPrefMap server_pref_map;
(...skipping 29 matching lines...) Expand all
633 } else { 651 } else {
634 it->second.settings_map = &map_it->second; 652 it->second.settings_map = &map_it->second;
635 } 653 }
636 } 654 }
637 655
638 // Add AlternateProtocol servers to server_pref_map. 656 // Add AlternateProtocol servers to server_pref_map.
639 for (net::AlternateProtocolMap::const_iterator map_it = 657 for (net::AlternateProtocolMap::const_iterator map_it =
640 alternate_protocol_map->begin(); 658 alternate_protocol_map->begin();
641 map_it != alternate_protocol_map->end(); ++map_it) { 659 map_it != alternate_protocol_map->end(); ++map_it) {
642 const net::HostPortPair& server = map_it->first; 660 const net::HostPortPair& server = map_it->first;
643 const net::PortAlternateProtocolPair& port_alternate_protocol = 661 const net::AlternateProtocolInfo& port_alternate_protocol =
644 map_it->second; 662 map_it->second;
645 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { 663 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
646 continue; 664 continue;
647 } 665 }
648 666
649 ServerPrefMap::iterator it = server_pref_map.find(server); 667 ServerPrefMap::iterator it = server_pref_map.find(server);
650 if (it == server_pref_map.end()) { 668 if (it == server_pref_map.end()) {
651 ServerPref server_pref(false, NULL, &map_it->second); 669 ServerPref server_pref(false, NULL, &map_it->second);
652 server_pref_map[server] = server_pref; 670 server_pref_map[server] = server_pref;
653 } else { 671 } else {
(...skipping 27 matching lines...) Expand all
681 std::string key = base::StringPrintf("%u", id); 699 std::string key = base::StringPrintf("%u", id);
682 spdy_settings_dict->SetInteger(key, value); 700 spdy_settings_dict->SetInteger(key, value);
683 } 701 }
684 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); 702 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict);
685 } 703 }
686 704
687 // Save alternate_protocol. 705 // Save alternate_protocol.
688 if (server_pref.alternate_protocol) { 706 if (server_pref.alternate_protocol) {
689 base::DictionaryValue* port_alternate_protocol_dict = 707 base::DictionaryValue* port_alternate_protocol_dict =
690 new base::DictionaryValue; 708 new base::DictionaryValue;
691 const net::PortAlternateProtocolPair* port_alternate_protocol = 709 const net::AlternateProtocolInfo* port_alternate_protocol =
692 server_pref.alternate_protocol; 710 server_pref.alternate_protocol;
693 port_alternate_protocol_dict->SetInteger( 711 port_alternate_protocol_dict->SetInteger(
694 "port", port_alternate_protocol->port); 712 "port", port_alternate_protocol->port);
695 const char* protocol_str = 713 const char* protocol_str =
696 net::AlternateProtocolToString(port_alternate_protocol->protocol); 714 net::AlternateProtocolToString(port_alternate_protocol->protocol);
697 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); 715 port_alternate_protocol_dict->SetString("protocol_str", protocol_str);
716 port_alternate_protocol_dict->SetDouble(
717 "probability", port_alternate_protocol->probability);
698 server_pref_dict->SetWithoutPathExpansion( 718 server_pref_dict->SetWithoutPathExpansion(
699 "alternate_protocol", port_alternate_protocol_dict); 719 "alternate_protocol", port_alternate_protocol_dict);
700 } 720 }
701 721
702 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 722 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
703 } 723 }
704 724
705 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); 725 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict);
706 SetVersion(&http_server_properties_dict, kVersionNumber); 726 SetVersion(&http_server_properties_dict, kVersionNumber);
707 setting_prefs_ = true; 727 setting_prefs_ = true;
708 pref_service_->Set(prefs::kHttpServerProperties, 728 pref_service_->Set(prefs::kHttpServerProperties,
709 http_server_properties_dict); 729 http_server_properties_dict);
710 setting_prefs_ = false; 730 setting_prefs_ = false;
711 731
712 // Note that |completion| will be fired after we have written everything to 732 // Note that |completion| will be fired after we have written everything to
713 // the Preferences, but likely before these changes are serialized to disk. 733 // the Preferences, but likely before these changes are serialized to disk.
714 // This is not a problem though, as JSONPrefStore guarantees that this will 734 // This is not a problem though, as JSONPrefStore guarantees that this will
715 // happen, pretty soon, and even in the case we shut down immediately. 735 // happen, pretty soon, and even in the case we shut down immediately.
716 if (!completion.is_null()) 736 if (!completion.is_null())
717 completion.Run(); 737 completion.Run();
718 } 738 }
719 739
720 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 740 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
722 if (!setting_prefs_) 742 if (!setting_prefs_)
723 ScheduleUpdateCacheOnUI(); 743 ScheduleUpdateCacheOnUI();
724 } 744 }
725 745
726 } // namespace chrome_browser_net 746 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698