Commit 4b91d834 authored by bnc's avatar bnc Committed by Commit bot

Do not persist HttpServerProperties to disk that often.

Add some heuristics to SetAlternativeServices that prevents a
ScheduleUpdatePrefsOnNetworkThread() call after each incoming Alt-Svc header,
based on the time of the last update, and the expiration times of the current
and new in-memory entries.  (Note that the current in-memory entry might be
different from the entry last persisted to disk.)

Repeated requests to the same server typically result in identical Alt-Svc
announcements, which become different when the max-age field (in seconds from
now) gets converted into a base::Time expiration time.  Alternative services do
not need to be persisted to disk with every incoming Alt-Svc header if other
fields (scheme, host, port) are identical.

BUG=554643

Review-Url: https://codereview.chromium.org/2171743002
Cr-Commit-Position: refs/heads/master@{#408273}
parent cc322ebc
...@@ -265,7 +265,8 @@ class NET_EXPORT HttpServerProperties { ...@@ -265,7 +265,8 @@ class NET_EXPORT HttpServerProperties {
// Set a single alternative service for |origin|. Previous alternative // Set a single alternative service for |origin|. Previous alternative
// services for |origin| are discarded. // services for |origin| are discarded.
// |alternative_service.host| may be empty. // |alternative_service.host| may be empty.
// Return true if |alternative_service_map_| is changed. // Return true if |alternative_service_map_| has changed significantly enough
// that it should be persisted to disk.
virtual bool SetAlternativeService( virtual bool SetAlternativeService(
const url::SchemeHostPort& origin, const url::SchemeHostPort& origin,
const AlternativeService& alternative_service, const AlternativeService& alternative_service,
...@@ -274,7 +275,9 @@ class NET_EXPORT HttpServerProperties { ...@@ -274,7 +275,9 @@ class NET_EXPORT HttpServerProperties {
// Set alternative services for |origin|. Previous alternative services for // Set alternative services for |origin|. Previous alternative services for
// |origin| are discarded. // |origin| are discarded.
// Hostnames in |alternative_service_info_vector| may be empty. // Hostnames in |alternative_service_info_vector| may be empty.
// Return true if |alternative_service_map_| is changed. // |alternative_service_info_vector| may be empty.
// Return true if |alternative_service_map_| has changed significantly enough
// that it should be persisted to disk.
virtual bool SetAlternativeServices( virtual bool SetAlternativeServices(
const url::SchemeHostPort& origin, const url::SchemeHostPort& origin,
const AlternativeServiceInfoVector& alternative_service_info_vector) = 0; const AlternativeServiceInfoVector& alternative_service_info_vector) = 0;
......
...@@ -413,8 +413,27 @@ bool HttpServerPropertiesImpl::SetAlternativeServices( ...@@ -413,8 +413,27 @@ bool HttpServerPropertiesImpl::SetAlternativeServices(
if (it != alternative_service_map_.end()) { if (it != alternative_service_map_.end()) {
DCHECK(!it->second.empty()); DCHECK(!it->second.empty());
if (it->second.size() == alternative_service_info_vector.size()) { if (it->second.size() == alternative_service_info_vector.size()) {
changed = !std::equal(it->second.begin(), it->second.end(), const base::Time now = base::Time::Now();
alternative_service_info_vector.begin()); changed = false;
auto new_it = alternative_service_info_vector.begin();
for (const auto& old : it->second) {
// Persist to disk immediately if new entry has different scheme, host,
// or port.
if (old.alternative_service != new_it->alternative_service) {
changed = true;
break;
}
// Also persist to disk if new expiration it more that twice as far or
// less than half as far in the future.
base::Time old_time = old.expiration;
base::Time new_time = new_it->expiration;
if (new_time - now > 2 * (old_time - now) ||
2 * (new_time - now) < (old_time - now)) {
changed = true;
break;
}
++new_it;
}
} }
} }
......
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