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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 14 matching lines...) Expand all
25 // Time to wait before starting an update the http_server_properties_impl_ cache 25 // Time to wait before starting an update the http_server_properties_impl_ cache
26 // from preferences. Scheduling another update during this period will reset the 26 // from preferences. Scheduling another update during this period will reset the
27 // timer. 27 // timer.
28 const int64_t kUpdateCacheDelayMs = 1000; 28 const int64_t kUpdateCacheDelayMs = 1000;
29 29
30 // Time to wait before starting an update the preferences from the 30 // Time to wait before starting an update the preferences from the
31 // http_server_properties_impl_ cache. Scheduling another update during this 31 // http_server_properties_impl_ cache. Scheduling another update during this
32 // period will reset the timer. 32 // period will reset the timer.
33 const int64_t kUpdatePrefsDelayMs = 60000; 33 const int64_t kUpdatePrefsDelayMs = 60000;
34 34
35 // Maximum time to wait between ScheduleUpdatePrefsOnNetworkThread() calls from
36 // SetAlternativeService() and SetAlternativeServices(), in seconds.
37 const int64_t kAlternativeServicesUpdatePrefsS = 3600;
Ryan Hamilton 2016/07/21 22:27:05 This is one hour, right? That seems like a LONG ti
Bence 2016/07/22 16:28:54 Well, then how about five minutes? Then I can cha
38
35 // "version" 0 indicates, http_server_properties doesn't have "version" 39 // "version" 0 indicates, http_server_properties doesn't have "version"
36 // property. 40 // property.
37 const int kMissingVersion = 0; 41 const int kMissingVersion = 0;
38 42
39 // The version number of persisted http_server_properties. 43 // The version number of persisted http_server_properties.
40 const int kVersionNumber = 5; 44 const int kVersionNumber = 5;
41 45
42 // Persist 200 MRU AlternateProtocolHostPortPairs. 46 // Persist 200 MRU AlternateProtocolHostPortPairs.
43 const int kMaxAlternateProtocolHostsToPersist = 200; 47 const int kMaxAlternateProtocolHostsToPersist = 200;
44 48
(...skipping 29 matching lines...) Expand all
74 // HttpServerPropertiesManager 78 // HttpServerPropertiesManager
75 79
76 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {} 80 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {}
77 81
78 HttpServerPropertiesManager::HttpServerPropertiesManager( 82 HttpServerPropertiesManager::HttpServerPropertiesManager(
79 PrefDelegate* pref_delegate, 83 PrefDelegate* pref_delegate,
80 scoped_refptr<base::SequencedTaskRunner> network_task_runner) 84 scoped_refptr<base::SequencedTaskRunner> network_task_runner)
81 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()), 85 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()),
82 pref_delegate_(pref_delegate), 86 pref_delegate_(pref_delegate),
83 setting_prefs_(false), 87 setting_prefs_(false),
84 network_task_runner_(network_task_runner) { 88 network_task_runner_(network_task_runner),
89 last_update_prefs_from_cache_(base::Time::Now()) {
Bence 2016/07/22 16:28:54 Oops.
85 DCHECK(pref_delegate_); 90 DCHECK(pref_delegate_);
86 pref_weak_ptr_factory_.reset( 91 pref_weak_ptr_factory_.reset(
87 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); 92 new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
88 pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr(); 93 pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr();
89 pref_cache_update_timer_.reset(new base::OneShotTimer); 94 pref_cache_update_timer_.reset(new base::OneShotTimer);
90 pref_delegate_->StartListeningForUpdates( 95 pref_delegate_->StartListeningForUpdates(
91 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, 96 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged,
92 base::Unretained(this))); 97 base::Unretained(this)));
93 } 98 }
94 99
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const url::SchemeHostPort& origin) { 193 const url::SchemeHostPort& origin) {
189 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 194 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
190 return http_server_properties_impl_->GetAlternativeServices(origin); 195 return http_server_properties_impl_->GetAlternativeServices(origin);
191 } 196 }
192 197
193 bool HttpServerPropertiesManager::SetAlternativeService( 198 bool HttpServerPropertiesManager::SetAlternativeService(
194 const url::SchemeHostPort& origin, 199 const url::SchemeHostPort& origin,
195 const AlternativeService& alternative_service, 200 const AlternativeService& alternative_service,
196 base::Time expiration) { 201 base::Time expiration) {
197 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
198 const bool changed = http_server_properties_impl_->SetAlternativeService( 203 const bool changed =
199 origin, alternative_service, expiration); 204 http_server_properties_impl_->SetAlternativeService(
205 origin, alternative_service, expiration) ||
206 (last_update_prefs_from_cache_ +
207 base::TimeDelta::FromSeconds(kAlternativeServicesUpdatePrefsS) <
208 base::Time::Now());
200 if (changed) { 209 if (changed) {
201 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 210 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
202 } 211 }
203 return changed; 212 return changed;
204 } 213 }
205 214
206 bool HttpServerPropertiesManager::SetAlternativeServices( 215 bool HttpServerPropertiesManager::SetAlternativeServices(
207 const url::SchemeHostPort& origin, 216 const url::SchemeHostPort& origin,
208 const AlternativeServiceInfoVector& alternative_service_info_vector) { 217 const AlternativeServiceInfoVector& alternative_service_info_vector) {
209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 218 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
210 const bool changed = http_server_properties_impl_->SetAlternativeServices( 219 const bool changed =
211 origin, alternative_service_info_vector); 220 http_server_properties_impl_->SetAlternativeServices(
221 origin, alternative_service_info_vector) ||
222 (last_update_prefs_from_cache_ +
223 base::TimeDelta::FromSeconds(kAlternativeServicesUpdatePrefsS) <
224 base::Time::Now());
Ryan Hamilton 2016/07/21 22:27:05 Hm. If nothing has changed, why bother persisting
Bence 2016/07/22 16:28:54 Because old_time in HttpServerPropertiesImpl is th
Ryan Hamilton 2016/07/22 23:31:35 I'm not sure this bothers me. If the user only hit
Bence 2016/07/27 16:30:55 All right then. I think you convinced me that the
212 if (changed) { 225 if (changed) {
213 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 226 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
214 } 227 }
215 return changed; 228 return changed;
216 } 229 }
217 230
218 void HttpServerPropertiesManager::MarkAlternativeServiceBroken( 231 void HttpServerPropertiesManager::MarkAlternativeServiceBroken(
219 const AlternativeService& alternative_service) { 232 const AlternativeService& alternative_service) {
220 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 233 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
221 http_server_properties_impl_->MarkAlternativeServiceBroken( 234 http_server_properties_impl_->MarkAlternativeServiceBroken(
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } 902 }
890 903
891 // This is required so we can set this as the callback for a timer. 904 // This is required so we can set this as the callback for a timer.
892 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { 905 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() {
893 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); 906 UpdatePrefsFromCacheOnNetworkThread(base::Closure());
894 } 907 }
895 908
896 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( 909 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(
897 const base::Closure& completion) { 910 const base::Closure& completion) {
898 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 911 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
912 last_update_prefs_from_cache_ = base::Time::Now();
899 913
900 // It is in MRU order. 914 // It is in MRU order.
901 base::ListValue* spdy_server_list = new base::ListValue; 915 base::ListValue* spdy_server_list = new base::ListValue;
902 http_server_properties_impl_->GetSpdyServerList( 916 http_server_properties_impl_->GetSpdyServerList(
903 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); 917 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist);
904 918
905 SpdySettingsMap* spdy_settings_map = 919 SpdySettingsMap* spdy_settings_map =
906 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist); 920 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist);
907 const SpdySettingsMap& main_map = 921 const SpdySettingsMap& main_map =
908 http_server_properties_impl_->spdy_settings_map(); 922 http_server_properties_impl_->spdy_settings_map();
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 quic_servers_dict); 1263 quic_servers_dict);
1250 } 1264 }
1251 1265
1252 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1266 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1253 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1267 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1254 if (!setting_prefs_) 1268 if (!setting_prefs_)
1255 ScheduleUpdateCacheOnPrefThread(); 1269 ScheduleUpdateCacheOnPrefThread();
1256 } 1270 }
1257 1271
1258 } // namespace net 1272 } // namespace net
OLDNEW
« net/http/http_server_properties_impl.cc ('K') | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698