Commit 1c863aa4 authored by rtenneti's avatar rtenneti Committed by Commit bot

QUIC - Code to persist if we had talked QUIC to a server and if so what

is the address.

This code is not hooked up into QUIC code yet. Will submit that in
the next CL.

R=rch@chromium.org

Review URL: https://codereview.chromium.org/605563003

Cr-Commit-Position: refs/heads/master@{#296749}
parent 5b07d9f6
...@@ -113,9 +113,24 @@ struct NET_EXPORT AlternateProtocolInfo { ...@@ -113,9 +113,24 @@ struct NET_EXPORT AlternateProtocolInfo {
double probability; double probability;
}; };
struct NET_EXPORT SupportsQuic {
SupportsQuic() : used_quic(false) {}
SupportsQuic(bool used_quic, const std::string& address)
: used_quic(used_quic),
address(address) {}
bool Equals(const SupportsQuic& other) const {
return used_quic == other.used_quic && address == other.address;
}
bool used_quic;
std::string address;
};
typedef base::MRUCache< typedef base::MRUCache<
HostPortPair, AlternateProtocolInfo> AlternateProtocolMap; HostPortPair, AlternateProtocolInfo> AlternateProtocolMap;
typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap; typedef base::MRUCache<HostPortPair, SettingsMap> SpdySettingsMap;
typedef std::map<HostPortPair, SupportsQuic> SupportsQuicMap;
extern const char kAlternateProtocolHeader[]; extern const char kAlternateProtocolHeader[];
...@@ -213,6 +228,16 @@ class NET_EXPORT HttpServerProperties { ...@@ -213,6 +228,16 @@ class NET_EXPORT HttpServerProperties {
// Returns all persistent SPDY settings. // Returns all persistent SPDY settings.
virtual const SpdySettingsMap& spdy_settings_map() const = 0; virtual const SpdySettingsMap& spdy_settings_map() const = 0;
// TODO(rtenneti): Make SupportsQuic a global (instead of per host_port_pair).
virtual SupportsQuic GetSupportsQuic(
const HostPortPair& host_port_pair) const = 0;
virtual void SetSupportsQuic(const HostPortPair& host_port_pair,
bool used_quic,
const std::string& address) = 0;
virtual const SupportsQuicMap& supports_quic_map() const = 0;
virtual void SetServerNetworkStats(const HostPortPair& host_port_pair, virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
NetworkStats stats) = 0; NetworkStats stats) = 0;
......
...@@ -103,6 +103,15 @@ void HttpServerPropertiesImpl::InitializeSpdySettingsServers( ...@@ -103,6 +103,15 @@ void HttpServerPropertiesImpl::InitializeSpdySettingsServers(
} }
} }
void HttpServerPropertiesImpl::InitializeSupportsQuic(
SupportsQuicMap* supports_quic_map) {
for (SupportsQuicMap::reverse_iterator it = supports_quic_map->rbegin();
it != supports_quic_map->rend();
++it) {
supports_quic_map_.insert(std::make_pair(it->first, it->second));
}
}
void HttpServerPropertiesImpl::GetSpdyServerList( void HttpServerPropertiesImpl::GetSpdyServerList(
base::ListValue* spdy_server_list, base::ListValue* spdy_server_list,
size_t max_size) const { size_t max_size) const {
...@@ -158,6 +167,7 @@ void HttpServerPropertiesImpl::Clear() { ...@@ -158,6 +167,7 @@ void HttpServerPropertiesImpl::Clear() {
alternate_protocol_map_.Clear(); alternate_protocol_map_.Clear();
canonical_host_to_origin_map_.clear(); canonical_host_to_origin_map_.clear();
spdy_settings_map_.Clear(); spdy_settings_map_.Clear();
supports_quic_map_.clear();
} }
bool HttpServerPropertiesImpl::SupportsSpdy( bool HttpServerPropertiesImpl::SupportsSpdy(
...@@ -406,6 +416,29 @@ HttpServerPropertiesImpl::spdy_settings_map() const { ...@@ -406,6 +416,29 @@ HttpServerPropertiesImpl::spdy_settings_map() const {
return spdy_settings_map_; return spdy_settings_map_;
} }
SupportsQuic HttpServerPropertiesImpl::GetSupportsQuic(
const HostPortPair& host_port_pair) const {
SupportsQuicMap::const_iterator it = supports_quic_map_.find(host_port_pair);
if (it == supports_quic_map_.end()) {
CR_DEFINE_STATIC_LOCAL(SupportsQuic, kEmptySupportsQuic, ());
return kEmptySupportsQuic;
}
return it->second;
}
void HttpServerPropertiesImpl::SetSupportsQuic(
const HostPortPair& host_port_pair,
bool used_quic,
const std::string& address) {
SupportsQuic supports_quic(used_quic, address);
supports_quic_map_.insert(std::make_pair(host_port_pair, supports_quic));
}
const SupportsQuicMap&
HttpServerPropertiesImpl::supports_quic_map() const {
return supports_quic_map_;
}
void HttpServerPropertiesImpl::SetServerNetworkStats( void HttpServerPropertiesImpl::SetServerNetworkStats(
const HostPortPair& host_port_pair, const HostPortPair& host_port_pair,
NetworkStats stats) { NetworkStats stats) {
......
...@@ -42,6 +42,8 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -42,6 +42,8 @@ class NET_EXPORT HttpServerPropertiesImpl
void InitializeSpdySettingsServers(SpdySettingsMap* spdy_settings_map); void InitializeSpdySettingsServers(SpdySettingsMap* spdy_settings_map);
void InitializeSupportsQuic(SupportsQuicMap* supports_quic_map);
// Get the list of servers (host/port) that support SPDY. The max_size is the // Get the list of servers (host/port) that support SPDY. The max_size is the
// number of MRU servers that support SPDY that are to be returned. // number of MRU servers that support SPDY that are to be returned.
void GetSpdyServerList(base::ListValue* spdy_server_list, void GetSpdyServerList(base::ListValue* spdy_server_list,
...@@ -140,6 +142,17 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -140,6 +142,17 @@ class NET_EXPORT HttpServerPropertiesImpl
// Returns all persistent SPDY settings. // Returns all persistent SPDY settings.
virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE; virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE;
// Methods for SupportsQuic.
virtual SupportsQuic GetSupportsQuic(
const HostPortPair& host_port_pair) const OVERRIDE;
virtual void SetSupportsQuic(const HostPortPair& host_port_pair,
bool used_quic,
const std::string& address) OVERRIDE;
virtual const SupportsQuicMap& supports_quic_map() const OVERRIDE;
// Methods for NetworkStats.
virtual void SetServerNetworkStats(const HostPortPair& host_port_pair, virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
NetworkStats stats) OVERRIDE; NetworkStats stats) OVERRIDE;
...@@ -179,6 +192,7 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -179,6 +192,7 @@ class NET_EXPORT HttpServerPropertiesImpl
AlternateProtocolExperiment alternate_protocol_experiment_; AlternateProtocolExperiment alternate_protocol_experiment_;
SpdySettingsMap spdy_settings_map_; SpdySettingsMap spdy_settings_map_;
SupportsQuicMap supports_quic_map_;
ServerNetworkStatsMap server_network_stats_map_; ServerNetworkStatsMap server_network_stats_map_;
// Contains a map of servers which could share the same alternate protocol. // Contains a map of servers which could share the same alternate protocol.
// Map from a Canonical host/port (host is some postfix of host names) to an // Map from a Canonical host/port (host is some postfix of host names) to an
......
...@@ -679,6 +679,43 @@ TEST_F(SpdySettingsServerPropertiesTest, MRUOfGetSpdySettings) { ...@@ -679,6 +679,43 @@ TEST_F(SpdySettingsServerPropertiesTest, MRUOfGetSpdySettings) {
EXPECT_EQ(value1, flags_and_value1_ret.second); EXPECT_EQ(value1, flags_and_value1_ret.second);
} }
typedef HttpServerPropertiesImplTest SupportsQuicServerPropertiesTest;
TEST_F(SupportsQuicServerPropertiesTest, Initialize) {
HostPortPair quic_server_google("www.google.com", 443);
// Check by initializing empty SupportsQuic.
SupportsQuicMap supports_quic_map;
impl_.InitializeSupportsQuic(&supports_quic_map);
SupportsQuic supports_quic = impl_.GetSupportsQuic(quic_server_google);
EXPECT_FALSE(supports_quic.used_quic);
EXPECT_EQ("", supports_quic.address);
// Check by initializing with www.google.com:443.
SupportsQuic supports_quic1(true, "foo");
supports_quic_map.insert(std::make_pair(quic_server_google, supports_quic1));
impl_.InitializeSupportsQuic(&supports_quic_map);
SupportsQuic supports_quic2 = impl_.GetSupportsQuic(quic_server_google);
EXPECT_TRUE(supports_quic2.used_quic);
EXPECT_EQ("foo", supports_quic2.address);
}
TEST_F(SupportsQuicServerPropertiesTest, SetSupportsQuic) {
HostPortPair test_host_port_pair("foo", 80);
SupportsQuic supports_quic = impl_.GetSupportsQuic(test_host_port_pair);
EXPECT_FALSE(supports_quic.used_quic);
EXPECT_EQ("", supports_quic.address);
impl_.SetSupportsQuic(test_host_port_pair, true, "foo");
SupportsQuic supports_quic1 = impl_.GetSupportsQuic(test_host_port_pair);
EXPECT_TRUE(supports_quic1.used_quic);
EXPECT_EQ("foo", supports_quic1.address);
impl_.Clear();
SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair);
EXPECT_FALSE(supports_quic2.used_quic);
EXPECT_EQ("", supports_quic2.address);
}
} // namespace } // namespace
} // namespace net } // namespace net
...@@ -264,6 +264,29 @@ const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() ...@@ -264,6 +264,29 @@ const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map()
return http_server_properties_impl_->spdy_settings_map(); return http_server_properties_impl_->spdy_settings_map();
} }
net::SupportsQuic
HttpServerPropertiesManager::GetSupportsQuic(
const net::HostPortPair& host_port_pair) const {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
return http_server_properties_impl_->GetSupportsQuic(host_port_pair);
}
void HttpServerPropertiesManager::SetSupportsQuic(
const net::HostPortPair& host_port_pair,
bool used_quic,
const std::string& address) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
http_server_properties_impl_->SetSupportsQuic(
host_port_pair, used_quic, address);
ScheduleUpdatePrefsOnNetworkThread();
}
const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map()
const {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
return http_server_properties_impl_->supports_quic_map();
}
void HttpServerPropertiesManager::SetServerNetworkStats( void HttpServerPropertiesManager::SetServerNetworkStats(
const net::HostPortPair& host_port_pair, const net::HostPortPair& host_port_pair,
NetworkStats stats) { NetworkStats stats) {
...@@ -332,6 +355,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { ...@@ -332,6 +355,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() {
new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist));
scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map(
new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist));
scoped_ptr<net::SupportsQuicMap> supports_quic_map(
new net::SupportsQuicMap());
// TODO(rtenneti): Delete the following code after the experiment. // TODO(rtenneti): Delete the following code after the experiment.
int alternate_protocols_to_load = k200AlternateProtocolHostsToLoad; int alternate_protocols_to_load = k200AlternateProtocolHostsToLoad;
net::AlternateProtocolExperiment alternate_protocol_experiment = net::AlternateProtocolExperiment alternate_protocol_experiment =
...@@ -455,6 +480,32 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { ...@@ -455,6 +480,32 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() {
alternate_protocol_map->Put(server, port_alternate_protocol); alternate_protocol_map->Put(server, port_alternate_protocol);
++count; ++count;
} while (false); } while (false);
// Get SupportsQuic.
DCHECK(supports_quic_map->find(server) == supports_quic_map->end());
const base::DictionaryValue* supports_quic_dict = NULL;
if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
"supports_quic", &supports_quic_dict)) {
continue;
}
do {
bool used_quic = 0;
if (!supports_quic_dict->GetBooleanWithoutPathExpansion(
"used_quic", &used_quic)) {
DVLOG(1) << "Malformed SupportsQuic server: " << server_str;
detected_corrupted_prefs = true;
continue;
}
std::string address;
if (!supports_quic_dict->GetStringWithoutPathExpansion(
"address", &address)) {
DVLOG(1) << "Malformed SupportsQuic server: " << server_str;
detected_corrupted_prefs = true;
continue;
}
net::SupportsQuic supports_quic(used_quic, address);
supports_quic_map->insert(std::make_pair(server, supports_quic));
} while (false);
} }
network_task_runner_->PostTask( network_task_runner_->PostTask(
...@@ -466,6 +517,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { ...@@ -466,6 +517,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() {
base::Owned(spdy_settings_map.release()), base::Owned(spdy_settings_map.release()),
base::Owned(alternate_protocol_map.release()), base::Owned(alternate_protocol_map.release()),
alternate_protocol_experiment, alternate_protocol_experiment,
base::Owned(supports_quic_map.release()),
detected_corrupted_prefs)); detected_corrupted_prefs));
} }
...@@ -474,6 +526,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( ...@@ -474,6 +526,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
net::SpdySettingsMap* spdy_settings_map, net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map, net::AlternateProtocolMap* alternate_protocol_map,
net::AlternateProtocolExperiment alternate_protocol_experiment, net::AlternateProtocolExperiment alternate_protocol_experiment,
net::SupportsQuicMap* supports_quic_map,
bool detected_corrupted_prefs) { bool detected_corrupted_prefs) {
// Preferences have the master data because admins might have pushed new // Preferences have the master data because admins might have pushed new
// preferences. Update the cached data with new data from preferences. // preferences. Update the cached data with new data from preferences.
...@@ -496,6 +549,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( ...@@ -496,6 +549,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
http_server_properties_impl_->SetAlternateProtocolExperiment( http_server_properties_impl_->SetAlternateProtocolExperiment(
alternate_protocol_experiment); alternate_protocol_experiment);
http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map);
// Update the prefs with what we have read (delete all corrupted prefs). // Update the prefs with what we have read (delete all corrupted prefs).
if (detected_corrupted_prefs) if (detected_corrupted_prefs)
ScheduleUpdatePrefsOnNetworkThread(); ScheduleUpdatePrefsOnNetworkThread();
...@@ -569,6 +624,14 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( ...@@ -569,6 +624,14 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(
++count; ++count;
} }
net::SupportsQuicMap* supports_quic_map = new net::SupportsQuicMap();
const net::SupportsQuicMap& main_supports_quic_map =
http_server_properties_impl_->supports_quic_map();
for (net::SupportsQuicMap::const_iterator it = main_supports_quic_map.begin();
it != main_supports_quic_map.end(); ++it) {
supports_quic_map->insert(std::make_pair(it->first, it->second));
}
// Update the preferences on the pref thread. // Update the preferences on the pref thread.
pref_task_runner_->PostTask( pref_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -577,30 +640,37 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( ...@@ -577,30 +640,37 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(
base::Owned(spdy_server_list), base::Owned(spdy_server_list),
base::Owned(spdy_settings_map), base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map), base::Owned(alternate_protocol_map),
base::Owned(supports_quic_map),
completion)); completion));
} }
// A local or temporary data structure to hold |supports_spdy|, SpdySettings, // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
// and AlternateProtocolInfo preferences for a server. This is used only in // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used
// UpdatePrefsOnPrefThread. // only in UpdatePrefsOnPrefThread.
struct ServerPref { struct ServerPref {
ServerPref() ServerPref() : supports_spdy(false),
: supports_spdy(false), settings_map(NULL), alternate_protocol(NULL) {} settings_map(NULL),
alternate_protocol(NULL),
supports_quic(NULL) {}
ServerPref(bool supports_spdy, ServerPref(bool supports_spdy,
const net::SettingsMap* settings_map, const net::SettingsMap* settings_map,
const net::AlternateProtocolInfo* alternate_protocol) const net::AlternateProtocolInfo* alternate_protocol,
const net::SupportsQuic* supports_quic)
: supports_spdy(supports_spdy), : supports_spdy(supports_spdy),
settings_map(settings_map), settings_map(settings_map),
alternate_protocol(alternate_protocol) {} alternate_protocol(alternate_protocol),
supports_quic(supports_quic) {}
bool supports_spdy; bool supports_spdy;
const net::SettingsMap* settings_map; const net::SettingsMap* settings_map;
const net::AlternateProtocolInfo* alternate_protocol; const net::AlternateProtocolInfo* alternate_protocol;
const net::SupportsQuic* supports_quic;
}; };
void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
base::ListValue* spdy_server_list, base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map, net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map, net::AlternateProtocolMap* alternate_protocol_map,
net::SupportsQuicMap* supports_quic_map,
const base::Closure& completion) { const base::Closure& completion) {
typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
ServerPrefMap server_pref_map; ServerPrefMap server_pref_map;
...@@ -617,7 +687,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( ...@@ -617,7 +687,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
ServerPrefMap::iterator it = server_pref_map.find(server); ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) { if (it == server_pref_map.end()) {
ServerPref server_pref(true, NULL, NULL); ServerPref server_pref(true, NULL, NULL, NULL);
server_pref_map[server] = server_pref; server_pref_map[server] = server_pref;
} else { } else {
it->second.supports_spdy = true; it->second.supports_spdy = true;
...@@ -633,7 +703,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( ...@@ -633,7 +703,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
ServerPrefMap::iterator it = server_pref_map.find(server); ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) { if (it == server_pref_map.end()) {
ServerPref server_pref(false, &map_it->second, NULL); ServerPref server_pref(false, &map_it->second, NULL, NULL);
server_pref_map[server] = server_pref; server_pref_map[server] = server_pref;
} else { } else {
it->second.settings_map = &map_it->second; it->second.settings_map = &map_it->second;
...@@ -654,13 +724,27 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( ...@@ -654,13 +724,27 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
ServerPrefMap::iterator it = server_pref_map.find(server); ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) { if (it == server_pref_map.end()) {
ServerPref server_pref(false, NULL, &map_it->second); ServerPref server_pref(false, NULL, &map_it->second, NULL);
server_pref_map[server] = server_pref; server_pref_map[server] = server_pref;
} else { } else {
it->second.alternate_protocol = &map_it->second; it->second.alternate_protocol = &map_it->second;
} }
} }
// Add SupportsQuic servers to server_pref_map.
for (net::SupportsQuicMap::const_iterator map_it = supports_quic_map->begin();
map_it != supports_quic_map->end(); ++map_it) {
const net::HostPortPair& server = map_it->first;
ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) {
ServerPref server_pref(false, NULL, NULL, &map_it->second);
server_pref_map[server] = server_pref;
} else {
it->second.supports_quic = &map_it->second;
}
}
// Persist properties to the |path_|. // Persist properties to the |path_|.
base::DictionaryValue http_server_properties_dict; base::DictionaryValue http_server_properties_dict;
base::DictionaryValue* servers_dict = new base::DictionaryValue; base::DictionaryValue* servers_dict = new base::DictionaryValue;
...@@ -708,6 +792,16 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( ...@@ -708,6 +792,16 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
"alternate_protocol", port_alternate_protocol_dict); "alternate_protocol", port_alternate_protocol_dict);
} }
// Save supports_quic.
if (server_pref.supports_quic) {
base::DictionaryValue* supports_quic_dict = new base::DictionaryValue;
const net::SupportsQuic* supports_quic = server_pref.supports_quic;
supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic);
supports_quic_dict->SetString("address", supports_quic->address);
server_pref_dict->SetWithoutPathExpansion(
"supports_quic", supports_quic_dict);
}
servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
} }
......
...@@ -153,6 +153,16 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { ...@@ -153,6 +153,16 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
// Returns all SPDY persistent settings. // Returns all SPDY persistent settings.
virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE; virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE;
// Methods for SupportsQuic.
virtual SupportsQuic GetSupportsQuic(
const HostPortPair& host_port_pair) const OVERRIDE;
virtual void SetSupportsQuic(const HostPortPair& host_port_pair,
bool used_quic,
const std::string& address) OVERRIDE;
virtual const SupportsQuicMap& supports_quic_map() const OVERRIDE;
virtual void SetServerNetworkStats(const HostPortPair& host_port_pair, virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
NetworkStats stats) OVERRIDE; NetworkStats stats) OVERRIDE;
...@@ -185,6 +195,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { ...@@ -185,6 +195,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
SpdySettingsMap* spdy_settings_map, SpdySettingsMap* spdy_settings_map,
AlternateProtocolMap* alternate_protocol_map, AlternateProtocolMap* alternate_protocol_map,
AlternateProtocolExperiment alternate_protocol_experiment, AlternateProtocolExperiment alternate_protocol_experiment,
SupportsQuicMap* supports_quic_map,
bool detected_corrupted_prefs); bool detected_corrupted_prefs);
// These are used to delay updating the preferences when cached data in // These are used to delay updating the preferences when cached data in
...@@ -212,6 +223,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { ...@@ -212,6 +223,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
void UpdatePrefsOnPrefThread(base::ListValue* spdy_server_list, void UpdatePrefsOnPrefThread(base::ListValue* spdy_server_list,
SpdySettingsMap* spdy_settings_map, SpdySettingsMap* spdy_settings_map,
AlternateProtocolMap* alternate_protocol_map, AlternateProtocolMap* alternate_protocol_map,
SupportsQuicMap* supports_quic_map,
const base::Closure& completion); const base::Closure& completion);
private: private:
......
...@@ -67,16 +67,18 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { ...@@ -67,16 +67,18 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void());
MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&));
MOCK_METHOD5(UpdateCacheFromPrefsOnNetworkThread, MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread,
void(std::vector<std::string>* spdy_servers, void(std::vector<std::string>* spdy_servers,
net::SpdySettingsMap* spdy_settings_map, net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map, net::AlternateProtocolMap* alternate_protocol_map,
net::AlternateProtocolExperiment experiment, net::AlternateProtocolExperiment experiment,
net::SupportsQuicMap* supports_quic_map,
bool detected_corrupted_prefs)); bool detected_corrupted_prefs));
MOCK_METHOD3(UpdatePrefsOnPref, MOCK_METHOD4(UpdatePrefsOnPref,
void(base::ListValue* spdy_server_list, void(base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map, net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map)); net::AlternateProtocolMap* alternate_protocol_map,
net::SupportsQuicMap* supports_quic_map));
private: private:
DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
...@@ -155,6 +157,12 @@ TEST_F(HttpServerPropertiesManagerTest, ...@@ -155,6 +157,12 @@ TEST_F(HttpServerPropertiesManagerTest,
server_pref_dict->SetWithoutPathExpansion("alternate_protocol", server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
alternate_protocol); alternate_protocol);
// Set up SupportsQuic for www.google.com:80.
base::DictionaryValue* supports_quic = new base::DictionaryValue;
supports_quic->SetBoolean("used_quic", true);
supports_quic->SetString("address", "foo");
server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic);
// Set the server preference for www.google.com:80. // Set the server preference for www.google.com:80.
base::DictionaryValue* servers_dict = new base::DictionaryValue; base::DictionaryValue* servers_dict = new base::DictionaryValue;
servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
...@@ -173,6 +181,12 @@ TEST_F(HttpServerPropertiesManagerTest, ...@@ -173,6 +181,12 @@ TEST_F(HttpServerPropertiesManagerTest,
server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
alternate_protocol1); alternate_protocol1);
// Set up SupportsQuic for mail.google.com:80
base::DictionaryValue* supports_quic1 = new base::DictionaryValue;
supports_quic1->SetBoolean("used_quic", false);
supports_quic1->SetString("address", "bar");
server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1);
// Set the server preference for mail.google.com:80. // Set the server preference for mail.google.com:80.
servers_dict->SetWithoutPathExpansion("mail.google.com:80", servers_dict->SetWithoutPathExpansion("mail.google.com:80",
server_pref_dict1); server_pref_dict1);
...@@ -215,6 +229,17 @@ TEST_F(HttpServerPropertiesManagerTest, ...@@ -215,6 +229,17 @@ TEST_F(HttpServerPropertiesManagerTest,
net::HostPortPair::FromString("mail.google.com:80")); net::HostPortPair::FromString("mail.google.com:80"));
EXPECT_EQ(444, port_alternate_protocol.port); EXPECT_EQ(444, port_alternate_protocol.port);
EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol);
// Verify SupportsQuic.
net::SupportsQuic supports_quic2 =
http_server_props_manager_->GetSupportsQuic(
net::HostPortPair::FromString("www.google.com:80"));
EXPECT_TRUE(supports_quic2.used_quic);
EXPECT_EQ("foo", supports_quic2.address);
supports_quic2 = http_server_props_manager_->GetSupportsQuic(
net::HostPortPair::FromString("mail.google.com:80"));
EXPECT_FALSE(supports_quic2.used_quic);
EXPECT_EQ("bar", supports_quic2.address);
} }
TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
...@@ -357,6 +382,26 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { ...@@ -357,6 +382,26 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol);
} }
TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
ExpectPrefsUpdate();
net::HostPortPair quic_server_mail("mail.google.com", 80);
net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic(
quic_server_mail);
EXPECT_FALSE(supports_quic.used_quic);
EXPECT_EQ("", supports_quic.address);
http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo");
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
net::SupportsQuic supports_quic1 =
http_server_props_manager_->GetSupportsQuic(quic_server_mail);
EXPECT_TRUE(supports_quic1.used_quic);
EXPECT_EQ("foo", supports_quic1.address);
}
TEST_F(HttpServerPropertiesManagerTest, Clear) { TEST_F(HttpServerPropertiesManagerTest, Clear) {
ExpectPrefsUpdate(); ExpectPrefsUpdate();
...@@ -364,6 +409,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { ...@@ -364,6 +409,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
http_server_props_manager_->SetAlternateProtocol( http_server_props_manager_->SetAlternateProtocol(
spdy_server_mail, 443, net::NPN_SPDY_3, 1); spdy_server_mail, 443, net::NPN_SPDY_3, 1);
http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo");
const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH;
const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST;
...@@ -377,6 +423,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { ...@@ -377,6 +423,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
EXPECT_TRUE( EXPECT_TRUE(
http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic(
spdy_server_mail);
EXPECT_TRUE(supports_quic.used_quic);
EXPECT_EQ("foo", supports_quic.address);
// Check SPDY settings values. // Check SPDY settings values.
const net::SettingsMap& settings_map1_ret = const net::SettingsMap& settings_map1_ret =
...@@ -399,6 +449,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { ...@@ -399,6 +449,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
EXPECT_FALSE( EXPECT_FALSE(
http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
net::SupportsQuic supports_quic1 =
http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
EXPECT_FALSE(supports_quic1.used_quic);
EXPECT_EQ("", supports_quic1.address);
const net::SettingsMap& settings_map2_ret = const net::SettingsMap& settings_map2_ret =
http_server_props_manager_->GetSpdySettings(spdy_server_mail); http_server_props_manager_->GetSpdySettings(spdy_server_mail);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment