OLD | NEW |
---|---|
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 "net/quic/platform/api/quic_url_utils.h" | 19 #include "net/quic/platform/api/quic_url_utils.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Time to wait before starting an update the http_server_properties_impl_ cache | 26 // Time to wait before starting an update the http_server_properties_impl_ cache |
27 // from preferences. Scheduling another update during this period will be a | 27 // from preferences. Scheduling another update during this period will be a |
28 // no-op. | 28 // no-op. |
29 const int64_t kUpdateCacheDelayMs = 1000; | 29 constexpr base::TimeDelta kUpdateCacheDelay = base::TimeDelta::FromSeconds(1); |
30 | 30 |
31 // Time to wait before starting an update the preferences from the | 31 // Time to wait before starting an update the preferences from the |
32 // http_server_properties_impl_ cache. Scheduling another update during this | 32 // http_server_properties_impl_ cache. Scheduling another update during this |
33 // period will be a no-op. | 33 // period will be a no-op. |
34 const int64_t kUpdatePrefsDelayMs = 60000; | 34 constexpr base::TimeDelta kUpdatePrefsDelay = base::TimeDelta::FromSeconds(60); |
35 | 35 |
36 // "version" 0 indicates, http_server_properties doesn't have "version" | 36 // "version" 0 indicates, http_server_properties doesn't have "version" |
37 // property. | 37 // property. |
38 const int kMissingVersion = 0; | 38 const int kMissingVersion = 0; |
39 | 39 |
40 // The version number of persisted http_server_properties. | 40 // The version number of persisted http_server_properties. |
41 const int kVersionNumber = 5; | 41 const int kVersionNumber = 5; |
42 | 42 |
43 // Persist 200 MRU AlternateProtocolHostPortPairs. | 43 // Persist 200 MRU AlternateProtocolHostPortPairs. |
44 const int kMaxAlternateProtocolHostsToPersist = 200; | 44 const int kMaxAlternateProtocolHostsToPersist = 200; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 return http_server_properties_impl_->SetMaxServerConfigsStoredInProperties( | 359 return http_server_properties_impl_->SetMaxServerConfigsStoredInProperties( |
360 max_server_configs_stored_in_properties); | 360 max_server_configs_stored_in_properties); |
361 } | 361 } |
362 | 362 |
363 bool HttpServerPropertiesManager::IsInitialized() const { | 363 bool HttpServerPropertiesManager::IsInitialized() const { |
364 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 364 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
365 | 365 |
366 return is_initialized_; | 366 return is_initialized_; |
367 } | 367 } |
368 | 368 |
369 // static | |
370 base::TimeDelta HttpServerPropertiesManager::GetUpdateCacheDelayForTesting() { | |
371 return kUpdateCacheDelay; | |
Zhongyi Shi
2017/02/15 22:04:42
These methods are for unittests only right? I am n
gab
2017/02/15 22:29:16
I think it's cleaner to FastForwardBy the current
Zhongyi Shi
2017/02/16 19:35:25
Acknowledged.
| |
372 } | |
373 | |
374 // static | |
375 base::TimeDelta HttpServerPropertiesManager::GetUpdatePrefsDelayForTesting() { | |
376 return kUpdatePrefsDelay; | |
377 } | |
378 | |
369 // | 379 // |
370 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 380 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
371 // | 381 // |
372 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { | 382 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { |
373 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 383 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
374 // Do not schedule a new update if there is already one scheduled. | 384 // Do not schedule a new update if there is already one scheduled. |
375 if (pref_cache_update_timer_->IsRunning()) | 385 if (pref_cache_update_timer_->IsRunning()) |
376 return; | 386 return; |
377 | 387 |
378 pref_cache_update_timer_->Start( | 388 pref_cache_update_timer_->Start( |
379 FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs), this, | 389 FROM_HERE, kUpdateCacheDelay, this, |
380 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread); | 390 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread); |
381 } | 391 } |
382 | 392 |
383 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { | 393 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { |
384 // The preferences can only be read on the pref thread. | 394 // The preferences can only be read on the pref thread. |
385 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 395 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
386 | 396 |
387 if (!pref_delegate_->HasServerProperties()) | 397 if (!pref_delegate_->HasServerProperties()) |
388 return; | 398 return; |
389 | 399 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 // Update Preferences with data from the cached data. | 795 // Update Preferences with data from the cached data. |
786 // | 796 // |
787 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( | 797 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( |
788 Location location) { | 798 Location location) { |
789 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 799 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
790 // Do not schedule a new update if there is already one scheduled. | 800 // Do not schedule a new update if there is already one scheduled. |
791 if (network_prefs_update_timer_->IsRunning()) | 801 if (network_prefs_update_timer_->IsRunning()) |
792 return; | 802 return; |
793 | 803 |
794 network_prefs_update_timer_->Start( | 804 network_prefs_update_timer_->Start( |
795 FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs), this, | 805 FROM_HERE, kUpdatePrefsDelay, this, |
796 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread); | 806 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread); |
797 | 807 |
798 // TODO(rtenneti): Delete the following histogram after collecting some data. | 808 // TODO(rtenneti): Delete the following histogram after collecting some data. |
799 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location, | 809 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location, |
800 HttpServerPropertiesManager::NUM_LOCATIONS); | 810 HttpServerPropertiesManager::NUM_LOCATIONS); |
801 } | 811 } |
802 | 812 |
803 // This is required so we can set this as the callback for a timer. | 813 // This is required so we can set this as the callback for a timer. |
804 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { | 814 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { |
805 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); | 815 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 if (!setting_prefs_) | 1131 if (!setting_prefs_) |
1122 ScheduleUpdateCacheOnPrefThread(); | 1132 ScheduleUpdateCacheOnPrefThread(); |
1123 } | 1133 } |
1124 | 1134 |
1125 void HttpServerPropertiesManager::SetInitialized() { | 1135 void HttpServerPropertiesManager::SetInitialized() { |
1126 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 1136 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
1127 is_initialized_ = true; | 1137 is_initialized_ = true; |
1128 } | 1138 } |
1129 | 1139 |
1130 } // namespace net | 1140 } // namespace net |
OLD | NEW |