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

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

Issue 2884933002: Remove raw base::DictionaryValue::SetWithoutPathExpansion (Closed)
Patch Set: Include Created 3 years, 7 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
« no previous file with comments | « ipc/ipc_message_utils_unittest.cc ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 ServerPref server_pref; 1006 ServerPref server_pref;
1007 server_pref.server_network_stats = &map_it->second; 1007 server_pref.server_network_stats = &map_it->second;
1008 server_pref_map.Put(server, server_pref); 1008 server_pref_map.Put(server, server_pref);
1009 } else { 1009 } else {
1010 it->second.server_network_stats = &map_it->second; 1010 it->second.server_network_stats = &map_it->second;
1011 } 1011 }
1012 } 1012 }
1013 1013
1014 // Persist properties to the prefs in the MRU order. 1014 // Persist properties to the prefs in the MRU order.
1015 base::DictionaryValue http_server_properties_dict; 1015 base::DictionaryValue http_server_properties_dict;
1016 base::ListValue* servers_list = new base::ListValue; 1016 auto servers_list = base::MakeUnique<base::ListValue>();
1017 for (ServerPrefMap::const_reverse_iterator map_it = server_pref_map.rbegin(); 1017 for (ServerPrefMap::const_reverse_iterator map_it = server_pref_map.rbegin();
1018 map_it != server_pref_map.rend(); ++map_it) { 1018 map_it != server_pref_map.rend(); ++map_it) {
1019 const url::SchemeHostPort server = map_it->first; 1019 const url::SchemeHostPort server = map_it->first;
1020 const ServerPref& server_pref = map_it->second; 1020 const ServerPref& server_pref = map_it->second;
1021 1021
1022 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); 1022 auto servers_dict = base::MakeUnique<base::DictionaryValue>();
1023 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>(); 1023 auto server_pref_dict = base::MakeUnique<base::DictionaryValue>();
1024 1024
1025 // Save supports_spdy. 1025 // Save supports_spdy.
1026 if (server_pref.supports_spdy) 1026 if (server_pref.supports_spdy)
1027 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); 1027 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy);
1028 SaveAlternativeServiceToServerPrefs( 1028 SaveAlternativeServiceToServerPrefs(
1029 server_pref.alternative_service_info_vector, server_pref_dict.get()); 1029 server_pref.alternative_service_info_vector, server_pref_dict.get());
1030 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, 1030 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats,
1031 server_pref_dict.get()); 1031 server_pref_dict.get());
1032 1032
1033 servers_dict->SetWithoutPathExpansion(server.Serialize(), 1033 servers_dict->SetWithoutPathExpansion(server.Serialize(),
1034 std::move(server_pref_dict)); 1034 std::move(server_pref_dict));
1035 bool value = servers_list->AppendIfNotPresent(std::move(servers_dict)); 1035 bool value = servers_list->AppendIfNotPresent(std::move(servers_dict));
1036 DCHECK(value); // Should never happen. 1036 DCHECK(value); // Should never happen.
1037 } 1037 }
1038 1038
1039 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, 1039 http_server_properties_dict.SetWithoutPathExpansion(kServersKey,
1040 servers_list); 1040 std::move(servers_list));
1041 SetVersion(&http_server_properties_dict, kVersionNumber); 1041 SetVersion(&http_server_properties_dict, kVersionNumber);
1042 1042
1043 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); 1043 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict);
1044 1044
1045 SaveQuicServerInfoMapToServerPrefs(quic_server_info_map, 1045 SaveQuicServerInfoMapToServerPrefs(quic_server_info_map,
1046 &http_server_properties_dict); 1046 &http_server_properties_dict);
1047 1047
1048 setting_prefs_ = true; 1048 setting_prefs_ = true;
1049 pref_delegate_->SetServerProperties(http_server_properties_dict); 1049 pref_delegate_->SetServerProperties(http_server_properties_dict);
1050 setting_prefs_ = false; 1050 setting_prefs_ = false;
(...skipping 30 matching lines...) Expand all
1081 kProtocolKey, NextProtoToString(alternative_service.protocol)); 1081 kProtocolKey, NextProtoToString(alternative_service.protocol));
1082 // JSON cannot store int64_t, so expiration is converted to a string. 1082 // JSON cannot store int64_t, so expiration is converted to a string.
1083 alternative_service_dict->SetString( 1083 alternative_service_dict->SetString(
1084 kExpirationKey, 1084 kExpirationKey,
1085 base::Int64ToString( 1085 base::Int64ToString(
1086 alternative_service_info.expiration.ToInternalValue())); 1086 alternative_service_info.expiration.ToInternalValue()));
1087 alternative_service_list->Append(std::move(alternative_service_dict)); 1087 alternative_service_list->Append(std::move(alternative_service_dict));
1088 } 1088 }
1089 if (alternative_service_list->GetSize() == 0) 1089 if (alternative_service_list->GetSize() == 0)
1090 return; 1090 return;
1091 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, 1091 server_pref_dict->SetWithoutPathExpansion(
1092 alternative_service_list.release()); 1092 kAlternativeServiceKey, std::move(alternative_service_list));
1093 } 1093 }
1094 1094
1095 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( 1095 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
1096 const IPAddress* last_quic_address, 1096 const IPAddress* last_quic_address,
1097 base::DictionaryValue* http_server_properties_dict) { 1097 base::DictionaryValue* http_server_properties_dict) {
1098 if (!last_quic_address || !last_quic_address->IsValid()) 1098 if (!last_quic_address || !last_quic_address->IsValid())
1099 return; 1099 return;
1100 1100
1101 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; 1101 auto supports_quic_dict = base::MakeUnique<base::DictionaryValue>();
1102 supports_quic_dict->SetBoolean(kUsedQuicKey, true); 1102 supports_quic_dict->SetBoolean(kUsedQuicKey, true);
1103 supports_quic_dict->SetString(kAddressKey, last_quic_address->ToString()); 1103 supports_quic_dict->SetString(kAddressKey, last_quic_address->ToString());
1104 http_server_properties_dict->SetWithoutPathExpansion(kSupportsQuicKey, 1104 http_server_properties_dict->SetWithoutPathExpansion(
1105 supports_quic_dict); 1105 kSupportsQuicKey, std::move(supports_quic_dict));
1106 } 1106 }
1107 1107
1108 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs( 1108 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs(
1109 const ServerNetworkStats* server_network_stats, 1109 const ServerNetworkStats* server_network_stats,
1110 base::DictionaryValue* server_pref_dict) { 1110 base::DictionaryValue* server_pref_dict) {
1111 if (!server_network_stats) 1111 if (!server_network_stats)
1112 return; 1112 return;
1113 1113
1114 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue; 1114 auto server_network_stats_dict = base::MakeUnique<base::DictionaryValue>();
1115 // Becasue JSON doesn't support int64_t, persist int64_t as a string. 1115 // Becasue JSON doesn't support int64_t, persist int64_t as a string.
1116 server_network_stats_dict->SetInteger( 1116 server_network_stats_dict->SetInteger(
1117 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue())); 1117 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue()));
1118 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist 1118 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
1119 // bandwidth_estimate. 1119 // bandwidth_estimate.
1120 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey, 1120 server_pref_dict->SetWithoutPathExpansion(
1121 server_network_stats_dict); 1121 kNetworkStatsKey, std::move(server_network_stats_dict));
1122 } 1122 }
1123 1123
1124 void HttpServerPropertiesManager::SaveQuicServerInfoMapToServerPrefs( 1124 void HttpServerPropertiesManager::SaveQuicServerInfoMapToServerPrefs(
1125 QuicServerInfoMap* quic_server_info_map, 1125 QuicServerInfoMap* quic_server_info_map,
1126 base::DictionaryValue* http_server_properties_dict) { 1126 base::DictionaryValue* http_server_properties_dict) {
1127 if (!quic_server_info_map) 1127 if (!quic_server_info_map)
1128 return; 1128 return;
1129 1129
1130 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; 1130 auto quic_servers_dict = base::MakeUnique<base::DictionaryValue>();
1131 for (const std::pair<QuicServerId, std::string>& entry : 1131 for (const std::pair<QuicServerId, std::string>& entry :
1132 *quic_server_info_map) { 1132 *quic_server_info_map) {
1133 const QuicServerId& server_id = entry.first; 1133 const QuicServerId& server_id = entry.first;
1134 base::DictionaryValue* quic_server_pref_dict = new base::DictionaryValue; 1134 auto quic_server_pref_dict = base::MakeUnique<base::DictionaryValue>();
1135 quic_server_pref_dict->SetStringWithoutPathExpansion(kServerInfoKey, 1135 quic_server_pref_dict->SetStringWithoutPathExpansion(kServerInfoKey,
1136 entry.second); 1136 entry.second);
1137 quic_servers_dict->SetWithoutPathExpansion(server_id.ToString(), 1137 quic_servers_dict->SetWithoutPathExpansion(
1138 quic_server_pref_dict); 1138 server_id.ToString(), std::move(quic_server_pref_dict));
1139 } 1139 }
1140 http_server_properties_dict->SetWithoutPathExpansion(kQuicServers, 1140 http_server_properties_dict->SetWithoutPathExpansion(
1141 quic_servers_dict); 1141 kQuicServers, std::move(quic_servers_dict));
1142 } 1142 }
1143 1143
1144 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1144 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1145 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1145 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1146 if (!setting_prefs_) 1146 if (!setting_prefs_)
1147 ScheduleUpdateCacheOnPrefThread(); 1147 ScheduleUpdateCacheOnPrefThread();
1148 } 1148 }
1149 1149
1150 void HttpServerPropertiesManager::SetInitialized() { 1150 void HttpServerPropertiesManager::SetInitialized() {
1151 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 1151 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
1152 is_initialized_ = true; 1152 is_initialized_ = true;
1153 } 1153 }
1154 1154
1155 } // namespace net 1155 } // namespace net
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils_unittest.cc ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698