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

Unified Diff: net/http/http_server_properties_manager.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: #7. 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
Index: net/http/http_server_properties_manager.cc
diff --git a/net/http/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc
index 467c5b804545251f3a0dfde3271165d2be0c2e18..75862b2b2393abb352a197dacfba7b5e0edeb5cd 100644
--- a/net/http/http_server_properties_manager.cc
+++ b/net/http/http_server_properties_manager.cc
@@ -25,12 +25,16 @@ namespace {
// Time to wait before starting an update the http_server_properties_impl_ cache
// from preferences. Scheduling another update during this period will reset the
// timer.
-const int64_t kUpdateCacheDelayMs = 1000;
+const int64_t kUpdateCacheDelayMs = 1000; // 1 second
// Time to wait before starting an update the preferences from the
// http_server_properties_impl_ cache. Scheduling another update during this
// period will reset the timer.
-const int64_t kUpdatePrefsDelayMs = 60000;
+const int64_t kUpdatePrefsDelayMs = 60000; // 1 minute
+
+// Maximum time to wait between ScheduleUpdatePrefsOnNetworkThread() calls from
+// SetAlternativeService() and SetAlternativeServices().
+const int64_t kAlternativeServicesUpdatePrefsMs = 300000; // 5 minutes
// "version" 0 indicates, http_server_properties doesn't have "version"
// property.
@@ -81,7 +85,10 @@ HttpServerPropertiesManager::HttpServerPropertiesManager(
: pref_task_runner_(base::ThreadTaskRunnerHandle::Get()),
pref_delegate_(pref_delegate),
setting_prefs_(false),
- network_task_runner_(network_task_runner) {
+ network_task_runner_(network_task_runner),
+ last_update_prefs_from_cache_(
+ base::Time::Now() -
+ base::TimeDelta::FromSeconds(kAlternativeServicesUpdatePrefsMs)) {
Ryan Hamilton 2016/07/22 23:31:35 Should this be "FromMilliseconds()"? (Here and els
DCHECK(pref_delegate_);
pref_weak_ptr_factory_.reset(
new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
@@ -195,8 +202,12 @@ bool HttpServerPropertiesManager::SetAlternativeService(
const AlternativeService& alternative_service,
base::Time expiration) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- const bool changed = http_server_properties_impl_->SetAlternativeService(
- origin, alternative_service, expiration);
+ const bool changed =
+ http_server_properties_impl_->SetAlternativeService(
+ origin, alternative_service, expiration) ||
+ (last_update_prefs_from_cache_ +
+ base::TimeDelta::FromSeconds(kAlternativeServicesUpdatePrefsMs) <
+ base::Time::Now());
if (changed) {
ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
}
@@ -207,8 +218,12 @@ bool HttpServerPropertiesManager::SetAlternativeServices(
const url::SchemeHostPort& origin,
const AlternativeServiceInfoVector& alternative_service_info_vector) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- const bool changed = http_server_properties_impl_->SetAlternativeServices(
- origin, alternative_service_info_vector);
+ const bool changed =
+ http_server_properties_impl_->SetAlternativeServices(
+ origin, alternative_service_info_vector) ||
+ (last_update_prefs_from_cache_ +
+ base::TimeDelta::FromSeconds(kAlternativeServicesUpdatePrefsMs) <
+ base::Time::Now());
if (changed) {
ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
}
@@ -896,6 +911,7 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() {
void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(
const base::Closure& completion) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
+ last_update_prefs_from_cache_ = base::Time::Now();
// It is in MRU order.
base::ListValue* spdy_server_list = new base::ListValue;

Powered by Google App Engine
This is Rietveld 408576698