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" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 // | 369 // |
370 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 370 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
371 // | 371 // |
372 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { | 372 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { |
373 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 373 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
374 // Do not schedule a new update if there is already one scheduled. | 374 // Do not schedule a new update if there is already one scheduled. |
375 if (pref_cache_update_timer_->IsRunning()) | 375 if (pref_cache_update_timer_->IsRunning()) |
376 return; | 376 return; |
377 | 377 |
378 StartCacheUpdateTimerOnPrefThread( | |
379 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); | |
380 } | |
381 | |
382 void HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( | |
383 base::TimeDelta delay) { | |
384 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | |
385 pref_cache_update_timer_->Start( | 378 pref_cache_update_timer_->Start( |
386 FROM_HERE, | 379 FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs), this, |
387 delay, | |
388 this, | |
389 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread); | 380 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread); |
390 } | 381 } |
391 | 382 |
392 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { | 383 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() { |
393 // The preferences can only be read on the pref thread. | 384 // The preferences can only be read on the pref thread. |
394 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 385 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
395 | 386 |
396 if (!pref_delegate_->HasServerProperties()) | 387 if (!pref_delegate_->HasServerProperties()) |
397 return; | 388 return; |
398 | 389 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 // | 784 // |
794 // Update Preferences with data from the cached data. | 785 // Update Preferences with data from the cached data. |
795 // | 786 // |
796 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( | 787 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( |
797 Location location) { | 788 Location location) { |
798 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 789 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
799 // Do not schedule a new update if there is already one scheduled. | 790 // Do not schedule a new update if there is already one scheduled. |
800 if (network_prefs_update_timer_->IsRunning()) | 791 if (network_prefs_update_timer_->IsRunning()) |
801 return; | 792 return; |
802 | 793 |
803 StartPrefsUpdateTimerOnNetworkThread( | 794 network_prefs_update_timer_->Start( |
804 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); | 795 FROM_HERE, base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs), this, |
| 796 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread); |
| 797 |
805 // TODO(rtenneti): Delete the following histogram after collecting some data. | 798 // TODO(rtenneti): Delete the following histogram after collecting some data. |
806 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location, | 799 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location, |
807 HttpServerPropertiesManager::NUM_LOCATIONS); | 800 HttpServerPropertiesManager::NUM_LOCATIONS); |
808 } | 801 } |
809 | 802 |
810 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( | |
811 base::TimeDelta delay) { | |
812 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | |
813 // This is overridden in tests to post the task without the delay. | |
814 network_prefs_update_timer_->Start( | |
815 FROM_HERE, | |
816 delay, | |
817 this, | |
818 &HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread); | |
819 } | |
820 | |
821 // This is required so we can set this as the callback for a timer. | 803 // This is required so we can set this as the callback for a timer. |
822 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { | 804 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread() { |
823 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); | 805 UpdatePrefsFromCacheOnNetworkThread(base::Closure()); |
824 } | 806 } |
825 | 807 |
826 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( | 808 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( |
827 const base::Closure& completion) { | 809 const base::Closure& completion) { |
828 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 810 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
829 | 811 |
830 // It is in MRU order. | 812 // It is in MRU order. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 if (!setting_prefs_) | 1121 if (!setting_prefs_) |
1140 ScheduleUpdateCacheOnPrefThread(); | 1122 ScheduleUpdateCacheOnPrefThread(); |
1141 } | 1123 } |
1142 | 1124 |
1143 void HttpServerPropertiesManager::SetInitialized() { | 1125 void HttpServerPropertiesManager::SetInitialized() { |
1144 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 1126 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
1145 is_initialized_ = true; | 1127 is_initialized_ = true; |
1146 } | 1128 } |
1147 | 1129 |
1148 } // namespace net | 1130 } // namespace net |
OLD | NEW |