Commit e267d6a5 authored by rtenneti's avatar rtenneti Committed by Commit bot

HttpServerProperties - Don't persist if SetSupportsSpdy is called with

the same origin (HostPortPair) and value (supports_spdy).

This change reduces the number of times SetSupportsSpdy tries to persist
HttpServerProperties to disk (currently ~5% of persist calls are due to
SetSupportsSpdy).

BUG=451256
R=rch@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#333146}
parent d65e9c8f
...@@ -218,6 +218,9 @@ class NET_EXPORT HttpServerProperties { ...@@ -218,6 +218,9 @@ class NET_EXPORT HttpServerProperties {
// request prioritization. // request prioritization.
virtual bool SupportsRequestPriority(const HostPortPair& server) = 0; virtual bool SupportsRequestPriority(const HostPortPair& server) = 0;
// Returns the value set by SetSupportsSpdy(). If not set, returns false.
virtual bool GetSupportsSpdy(const HostPortPair& server) = 0;
// Add |server| into the persistent store. Should only be called from IO // Add |server| into the persistent store. Should only be called from IO
// thread. // thread.
virtual void SetSupportsSpdy(const HostPortPair& server, virtual void SetSupportsSpdy(const HostPortPair& server,
......
...@@ -157,9 +157,7 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority( ...@@ -157,9 +157,7 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority(
if (host_port_pair.host().empty()) if (host_port_pair.host().empty())
return false; return false;
SpdyServerHostPortMap::iterator spdy_host_port = if (GetSupportsSpdy(host_port_pair))
spdy_servers_map_.Get(host_port_pair.ToString());
if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second)
return true; return true;
const AlternativeService alternative_service = const AlternativeService alternative_service =
...@@ -167,6 +165,17 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority( ...@@ -167,6 +165,17 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority(
return alternative_service.protocol == QUIC; return alternative_service.protocol == QUIC;
} }
bool HttpServerPropertiesImpl::GetSupportsSpdy(
const HostPortPair& host_port_pair) {
DCHECK(CalledOnValidThread());
if (host_port_pair.host().empty())
return false;
SpdyServerHostPortMap::iterator spdy_host_port =
spdy_servers_map_.Get(host_port_pair.ToString());
return spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second;
}
void HttpServerPropertiesImpl::SetSupportsSpdy( void HttpServerPropertiesImpl::SetSupportsSpdy(
const HostPortPair& host_port_pair, const HostPortPair& host_port_pair,
bool support_spdy) { bool support_spdy) {
......
...@@ -81,6 +81,7 @@ class NET_EXPORT HttpServerPropertiesImpl ...@@ -81,6 +81,7 @@ class NET_EXPORT HttpServerPropertiesImpl
base::WeakPtr<HttpServerProperties> GetWeakPtr() override; base::WeakPtr<HttpServerProperties> GetWeakPtr() override;
void Clear() override; void Clear() override;
bool SupportsRequestPriority(const HostPortPair& server) override; bool SupportsRequestPriority(const HostPortPair& server) override;
bool GetSupportsSpdy(const HostPortPair& server) override;
void SetSupportsSpdy(const HostPortPair& server, bool support_spdy) override; void SetSupportsSpdy(const HostPortPair& server, bool support_spdy) override;
bool RequiresHTTP11(const HostPortPair& server) override; bool RequiresHTTP11(const HostPortPair& server) override;
void SetHTTP11Required(const HostPortPair& server) override; void SetHTTP11Required(const HostPortPair& server) override;
......
...@@ -155,11 +155,19 @@ bool HttpServerPropertiesManager::SupportsRequestPriority( ...@@ -155,11 +155,19 @@ bool HttpServerPropertiesManager::SupportsRequestPriority(
return http_server_properties_impl_->SupportsRequestPriority(server); return http_server_properties_impl_->SupportsRequestPriority(server);
} }
bool HttpServerPropertiesManager::GetSupportsSpdy(const HostPortPair& server) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
return http_server_properties_impl_->GetSupportsSpdy(server);
}
void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server, void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server,
bool support_spdy) { bool support_spdy) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
bool old_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server);
http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
bool new_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server);
if (old_support_spdy != new_support_spdy)
ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY); ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY);
} }
......
...@@ -81,6 +81,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { ...@@ -81,6 +81,7 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
base::WeakPtr<HttpServerProperties> GetWeakPtr() override; base::WeakPtr<HttpServerProperties> GetWeakPtr() override;
void Clear() override; void Clear() override;
bool SupportsRequestPriority(const HostPortPair& server) override; bool SupportsRequestPriority(const HostPortPair& server) override;
bool GetSupportsSpdy(const HostPortPair& server) override;
void SetSupportsSpdy(const HostPortPair& server, bool support_spdy) override; void SetSupportsSpdy(const HostPortPair& server, bool support_spdy) override;
bool RequiresHTTP11(const HostPortPair& server) override; bool RequiresHTTP11(const HostPortPair& server) override;
void SetHTTP11Required(const HostPortPair& server) override; void SetHTTP11Required(const HostPortPair& server) override;
......
...@@ -390,6 +390,8 @@ TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { ...@@ -390,6 +390,8 @@ TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
EXPECT_FALSE( EXPECT_FALSE(
http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
// Run the task. // Run the task.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
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