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

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

Issue 2554723003: Always persist data to disk after 60s from the receiving update request. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 if (detected_corrupted_prefs) 772 if (detected_corrupted_prefs)
773 ScheduleUpdatePrefsOnNetworkThread(DETECTED_CORRUPTED_PREFS); 773 ScheduleUpdatePrefsOnNetworkThread(DETECTED_CORRUPTED_PREFS);
774 } 774 }
775 775
776 // 776 //
777 // Update Preferences with data from the cached data. 777 // Update Preferences with data from the cached data.
778 // 778 //
779 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( 779 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread(
780 Location location) { 780 Location location) {
781 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 781 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
782 // Cancel pending updates, if any. 782 // Cancel the new update if there's one scheduled already.
Ryan Hamilton 2016/12/06 22:24:15 This comment might be clearer if it were: // Do n
783 network_prefs_update_timer_->Stop(); 783 if (network_prefs_update_timer_->IsRunning())
784 return;
785
784 StartPrefsUpdateTimerOnNetworkThread( 786 StartPrefsUpdateTimerOnNetworkThread(
785 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs)); 787 base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs));
786 // TODO(rtenneti): Delete the following histogram after collecting some data. 788 // TODO(rtenneti): Delete the following histogram after collecting some data.
787 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location, 789 UMA_HISTOGRAM_ENUMERATION("Net.HttpServerProperties.UpdatePrefs", location,
788 HttpServerPropertiesManager::NUM_LOCATIONS); 790 HttpServerPropertiesManager::NUM_LOCATIONS);
789 } 791 }
790 792
791 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( 793 void HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread(
792 base::TimeDelta delay) { 794 base::TimeDelta delay) {
793 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 795 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 setting_prefs_ = true; 1024 setting_prefs_ = true;
1023 pref_delegate_->SetServerProperties(http_server_properties_dict); 1025 pref_delegate_->SetServerProperties(http_server_properties_dict);
1024 setting_prefs_ = false; 1026 setting_prefs_ = false;
1025 1027
1026 // Note that |completion| will be fired after we have written everything to 1028 // Note that |completion| will be fired after we have written everything to
1027 // the Preferences, but likely before these changes are serialized to disk. 1029 // the Preferences, but likely before these changes are serialized to disk.
1028 // This is not a problem though, as JSONPrefStore guarantees that this will 1030 // This is not a problem though, as JSONPrefStore guarantees that this will
1029 // happen, pretty soon, and even in the case we shut down immediately. 1031 // happen, pretty soon, and even in the case we shut down immediately.
1030 if (!completion.is_null()) 1032 if (!completion.is_null())
1031 completion.Run(); 1033 completion.Run();
1034
1035 // Reset the update timer if it's still running.
1036 if (network_prefs_update_timer_->IsRunning())
1037 network_prefs_update_timer_->Stop();
Ryan Hamilton 2016/12/06 22:24:15 I don't' think this is thread safe since this time
1032 } 1038 }
1033 1039
1034 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( 1040 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs(
1035 const AlternativeServiceInfoVector* alternative_service_info_vector, 1041 const AlternativeServiceInfoVector* alternative_service_info_vector,
1036 base::DictionaryValue* server_pref_dict) { 1042 base::DictionaryValue* server_pref_dict) {
1037 if (!alternative_service_info_vector || 1043 if (!alternative_service_info_vector ||
1038 alternative_service_info_vector->empty()) { 1044 alternative_service_info_vector->empty()) {
1039 return; 1045 return;
1040 } 1046 }
1041 std::unique_ptr<base::ListValue> alternative_service_list( 1047 std::unique_ptr<base::ListValue> alternative_service_list(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 quic_servers_dict); 1121 quic_servers_dict);
1116 } 1122 }
1117 1123
1118 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1124 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1119 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1125 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1120 if (!setting_prefs_) 1126 if (!setting_prefs_)
1121 ScheduleUpdateCacheOnPrefThread(); 1127 ScheduleUpdateCacheOnPrefThread();
1122 } 1128 }
1123 1129
1124 } // namespace net 1130 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698