Commit 5b3bb859 authored by rtenneti's avatar rtenneti Committed by Commit bot

HttpServerProperties - Don't persist if ConfirmAlternativeService is

called with the same origin (HostPortPair) more than once and if we
didn't change anything in  broken_alternative_services_ (in other words
the return value of IsAlternativeServiceBroken hasn't changed).

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

BUG=451256
R=rch@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#333169}
parent bd002c04
......@@ -245,8 +245,15 @@ bool HttpServerPropertiesManager::WasAlternativeServiceRecentlyBroken(
void HttpServerPropertiesManager::ConfirmAlternativeService(
const AlternativeService& alternative_service) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
bool old_value = http_server_properties_impl_->IsAlternativeServiceBroken(
alternative_service);
http_server_properties_impl_->ConfirmAlternativeService(alternative_service);
ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE);
bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken(
alternative_service);
// For persisting, we only care about the value returned by
// IsAlternativeServiceBroken. If that value changes, then call persist.
if (old_value != new_value)
ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE);
}
void HttpServerPropertiesManager::ClearAlternativeService(
......
......@@ -549,6 +549,52 @@ TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeService) {
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
}
TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
ExpectPrefsUpdate();
HostPortPair spdy_server_mail("mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
ExpectScheduleUpdatePrefsOnNetworkThread();
http_server_props_manager_->SetAlternativeService(spdy_server_mail,
alternative_service, 1.0);
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
alternative_service));
ExpectScheduleUpdatePrefsOnNetworkThread();
http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service);
EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
EXPECT_TRUE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
alternative_service));
ExpectScheduleUpdatePrefsOnNetworkThread();
http_server_props_manager_->ConfirmAlternativeService(alternative_service);
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
alternative_service));
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->ConfirmAlternativeService(alternative_service);
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
alternative_service));
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
alternative_service));
}
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