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

HttpServerProperties - Don't persist if ClearAlternativeService is

called with the same origin (HostPortPair) and nothing was deleted.

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

BUG=451256
R=rch@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#333147}
parent e267d6a5
......@@ -252,8 +252,14 @@ void HttpServerPropertiesManager::ConfirmAlternativeService(
void HttpServerPropertiesManager::ClearAlternativeService(
const HostPortPair& origin) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
const AlternativeServiceMap& map =
http_server_properties_impl_->alternative_service_map();
size_t old_size = map.size();
http_server_properties_impl_->ClearAlternativeService(origin);
ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE);
size_t new_size = map.size();
// Persist only if we have deleted an entry.
if (old_size != new_size)
ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE);
}
const AlternativeServiceMap&
......
......@@ -528,6 +528,27 @@ TEST_F(HttpServerPropertiesManagerTest, GetAlternativeService) {
EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol);
}
TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeService) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
HostPortPair spdy_server_mail("mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
http_server_props_manager_->SetAlternativeService(spdy_server_mail,
alternative_service, 1.0);
ExpectScheduleUpdatePrefsOnNetworkThread();
http_server_props_manager_->ClearAlternativeService(spdy_server_mail);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->ClearAlternativeService(spdy_server_mail);
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
}
TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
......
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