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

Side by Side Diff: net/http/http_server_properties_manager.cc

Issue 2587303002: Change http_server_properties_manager to always persist data to memory after 1s (Closed)
Patch Set: Created 4 years 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "net/base/ip_address.h" 17 #include "net/base/ip_address.h"
18 #include "net/base/port_util.h" 18 #include "net/base/port_util.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace net { 21 namespace net {
22 22
23 namespace { 23 namespace {
24 24
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 be a
27 // timer. 27 // no-op.
28 const int64_t kUpdateCacheDelayMs = 1000; 28 const int64_t kUpdateCacheDelayMs = 1000;
xunjieli 2016/12/20 14:00:27 nit: The delay is 1s. Could you edit the CL descri
Zhongyi Shi 2016/12/20 20:03:38 Done.
Ryan Hamilton 2016/12/20 20:38:38 Confirming: we update net from prefs once a second
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 be a no-op.
33 const int64_t kUpdatePrefsDelayMs = 60000; 33 const int64_t kUpdatePrefsDelayMs = 60000;
34 34
35 // "version" 0 indicates, http_server_properties doesn't have "version" 35 // "version" 0 indicates, http_server_properties doesn't have "version"
36 // property. 36 // property.
37 const int kMissingVersion = 0; 37 const int kMissingVersion = 0;
38 38
39 // The version number of persisted http_server_properties. 39 // The version number of persisted http_server_properties.
40 const int kVersionNumber = 5; 40 const int kVersionNumber = 5;
41 41
42 // Persist 200 MRU AlternateProtocolHostPortPairs. 42 // Persist 200 MRU AlternateProtocolHostPortPairs.
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 350 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
351 return http_server_properties_impl_->SetMaxServerConfigsStoredInProperties( 351 return http_server_properties_impl_->SetMaxServerConfigsStoredInProperties(
352 max_server_configs_stored_in_properties); 352 max_server_configs_stored_in_properties);
353 } 353 }
354 354
355 // 355 //
356 // Update the HttpServerPropertiesImpl's cache with data from preferences. 356 // Update the HttpServerPropertiesImpl's cache with data from preferences.
357 // 357 //
358 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { 358 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() {
359 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 359 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
360 // Cancel pending updates, if any. 360 // Do not schedule a new update if there is already one scheduled.
361 pref_cache_update_timer_->Stop(); 361 if (pref_cache_update_timer_->IsRunning())
362 return;
363
362 StartCacheUpdateTimerOnPrefThread( 364 StartCacheUpdateTimerOnPrefThread(
363 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); 365 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs));
364 } 366 }
365 367
366 void HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( 368 void HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread(
367 base::TimeDelta delay) { 369 base::TimeDelta delay) {
368 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 370 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
369 pref_cache_update_timer_->Start( 371 pref_cache_update_timer_->Start(
370 FROM_HERE, 372 FROM_HERE,
371 delay, 373 delay,
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 quic_servers_dict); 1121 quic_servers_dict);
1120 } 1122 }
1121 1123
1122 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1124 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1123 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1125 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1124 if (!setting_prefs_) 1126 if (!setting_prefs_)
1125 ScheduleUpdateCacheOnPrefThread(); 1127 ScheduleUpdateCacheOnPrefThread();
1126 } 1128 }
1127 1129
1128 } // namespace net 1130 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698