Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: net/http/http_server_properties_impl.cc

Issue 2171743002: Do not persist HttpServerProperties to disk that often. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re: #13. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_server_properties.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_server_properties_impl.cc
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc
index 9e6e92e719d66a5dbf7711e29367b468b0117b20..90eee301a8f18621d0c805d11d187bd9cdf0de05 100644
--- a/net/http/http_server_properties_impl.cc
+++ b/net/http/http_server_properties_impl.cc
@@ -413,8 +413,27 @@ bool HttpServerPropertiesImpl::SetAlternativeServices(
if (it != alternative_service_map_.end()) {
DCHECK(!it->second.empty());
if (it->second.size() == alternative_service_info_vector.size()) {
- changed = !std::equal(it->second.begin(), it->second.end(),
- alternative_service_info_vector.begin());
+ const base::Time now = base::Time::Now();
+ 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;
+ }
}
}
« no previous file with comments | « net/http/http_server_properties.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698