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

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

Issue 2949513005: Update param types of HttpServerPropertiesImpl setters and getters. Fix MRU order when loading (Closed)
Patch Set: Updated HttpServerPropertiesManagerTest.SingleUpdateForTwoSpdyServerPrefChanges to reflect new load… Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 27 matching lines...) Expand all
38 canonical_suffixes_.push_back(".c.youtube.com"); 38 canonical_suffixes_.push_back(".c.youtube.com");
39 canonical_suffixes_.push_back(".googlevideo.com"); 39 canonical_suffixes_.push_back(".googlevideo.com");
40 canonical_suffixes_.push_back(".googleusercontent.com"); 40 canonical_suffixes_.push_back(".googleusercontent.com");
41 } 41 }
42 42
43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { 43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
44 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 44 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
45 } 45 }
46 46
47 void HttpServerPropertiesImpl::SetSpdyServers( 47 void HttpServerPropertiesImpl::SetSpdyServers(
48 std::vector<std::string>* spdy_servers, 48 std::unique_ptr<SpdyServersMap> spdy_servers_map) {
49 bool support_spdy) {
50 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 49 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
51 if (!spdy_servers)
52 return;
53 50
54 // Add the entries from persisted data. 51 // Add the entries from persisted data.
55 SpdyServersMap spdy_servers_map(SpdyServersMap::NO_AUTO_EVICT); 52 spdy_servers_map_.Swap(*spdy_servers_map);
56 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin();
57 it != spdy_servers->rend(); ++it) {
58 spdy_servers_map.Put(*it, support_spdy);
59 }
60
61 // |spdy_servers_map| will have the memory cache.
62 spdy_servers_map_.Swap(spdy_servers_map);
63 53
64 // Add the entries from the memory cache. 54 // Add the entries from the memory cache.
65 for (SpdyServersMap::reverse_iterator it = spdy_servers_map.rbegin(); 55 for (SpdyServersMap::reverse_iterator it = spdy_servers_map->rbegin();
66 it != spdy_servers_map.rend(); ++it) { 56 it != spdy_servers_map->rend(); ++it) {
67 // Add the entry if it is not in the cache, otherwise move it to the front 57 // Add the entry if it is not in the cache, otherwise move it to the front
68 // of recency list. 58 // of recency list.
69 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) 59 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end())
70 spdy_servers_map_.Put(it->first, it->second); 60 spdy_servers_map_.Put(it->first, it->second);
71 } 61 }
72 } 62 }
73 63
74 void HttpServerPropertiesImpl::SetAlternativeServiceServers( 64 void HttpServerPropertiesImpl::SetAlternativeServiceServers(
75 AlternativeServiceMap* alternative_service_map) { 65 std::unique_ptr<AlternativeServiceMap> alternative_service_map) {
76 int32_t size_diff = 66 int32_t size_diff =
77 alternative_service_map->size() - alternative_service_map_.size(); 67 alternative_service_map->size() - alternative_service_map_.size();
78 if (size_diff > 0) { 68 if (size_diff > 0) {
79 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries", 69 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries",
80 size_diff); 70 size_diff);
81 } else { 71 } else {
82 UMA_HISTOGRAM_COUNTS( 72 UMA_HISTOGRAM_COUNTS(
83 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff); 73 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff);
84 } 74 }
85 75
86 AlternativeServiceMap new_alternative_service_map(
87 AlternativeServiceMap::NO_AUTO_EVICT);
88 // Add the entries from persisted data. 76 // Add the entries from persisted data.
89 for (AlternativeServiceMap::reverse_iterator input_it = 77 alternative_service_map_.Swap(*alternative_service_map);
90 alternative_service_map->rbegin();
91 input_it != alternative_service_map->rend(); ++input_it) {
92 DCHECK(!input_it->second.empty());
93 new_alternative_service_map.Put(input_it->first, input_it->second);
94 }
95
96 alternative_service_map_.Swap(new_alternative_service_map);
97 78
98 // Add the entries from the memory cache. 79 // Add the entries from the memory cache.
99 for (AlternativeServiceMap::reverse_iterator input_it = 80 for (auto input_it = alternative_service_map->rbegin();
100 new_alternative_service_map.rbegin(); 81 input_it != alternative_service_map->rend(); ++input_it) {
101 input_it != new_alternative_service_map.rend(); ++input_it) {
102 if (alternative_service_map_.Get(input_it->first) == 82 if (alternative_service_map_.Get(input_it->first) ==
103 alternative_service_map_.end()) { 83 alternative_service_map_.end()) {
104 alternative_service_map_.Put(input_it->first, input_it->second); 84 alternative_service_map_.Put(input_it->first, input_it->second);
105 } 85 }
106 } 86 }
107 87
108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. 88 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS.
109 const uint16_t kCanonicalPort = 443; 89 const uint16_t kCanonicalPort = 443;
110 const char* kCanonicalScheme = "https"; 90 const char* kCanonicalScheme = "https";
111 for (const std::string& canonical_suffix : canonical_suffixes_) { 91 for (const std::string& canonical_suffix : canonical_suffixes_) {
(...skipping 14 matching lines...) Expand all
126 if (base::EndsWith(it->first.host(), canonical_suffix, 106 if (base::EndsWith(it->first.host(), canonical_suffix,
127 base::CompareCase::INSENSITIVE_ASCII) && 107 base::CompareCase::INSENSITIVE_ASCII) &&
128 it->first.scheme() == canonical_server.scheme()) { 108 it->first.scheme() == canonical_server.scheme()) {
129 canonical_host_to_origin_map_[canonical_server] = it->first; 109 canonical_host_to_origin_map_[canonical_server] = it->first;
130 break; 110 break;
131 } 111 }
132 } 112 }
133 } 113 }
134 } 114 }
135 115
136 void HttpServerPropertiesImpl::SetSupportsQuic(IPAddress* last_address) { 116 void HttpServerPropertiesImpl::SetSupportsQuic(const IPAddress& last_address) {
137 if (last_address) 117 last_quic_address_ = last_address;
138 last_quic_address_ = *last_address;
139 } 118 }
140 119
141 void HttpServerPropertiesImpl::SetServerNetworkStats( 120 void HttpServerPropertiesImpl::SetServerNetworkStats(
142 ServerNetworkStatsMap* server_network_stats_map) { 121 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map) {
143 // Add the entries from persisted data. 122 // Add the entries from persisted data.
144 ServerNetworkStatsMap new_server_network_stats_map( 123 server_network_stats_map_.Swap(*server_network_stats_map);
145 ServerNetworkStatsMap::NO_AUTO_EVICT); 124
125 // Add the entries from the memory cache.
146 for (ServerNetworkStatsMap::reverse_iterator it = 126 for (ServerNetworkStatsMap::reverse_iterator it =
147 server_network_stats_map->rbegin(); 127 server_network_stats_map->rbegin();
148 it != server_network_stats_map->rend(); ++it) { 128 it != server_network_stats_map->rend(); ++it) {
149 new_server_network_stats_map.Put(it->first, it->second);
150 }
151
152 server_network_stats_map_.Swap(new_server_network_stats_map);
153
154 // Add the entries from the memory cache.
155 for (ServerNetworkStatsMap::reverse_iterator it =
156 new_server_network_stats_map.rbegin();
157 it != new_server_network_stats_map.rend(); ++it) {
158 if (server_network_stats_map_.Get(it->first) == 129 if (server_network_stats_map_.Get(it->first) ==
159 server_network_stats_map_.end()) { 130 server_network_stats_map_.end()) {
160 server_network_stats_map_.Put(it->first, it->second); 131 server_network_stats_map_.Put(it->first, it->second);
161 } 132 }
162 } 133 }
163 } 134 }
164 135
165 void HttpServerPropertiesImpl::SetQuicServerInfoMap( 136 void HttpServerPropertiesImpl::SetQuicServerInfoMap(
166 QuicServerInfoMap* quic_server_info_map) { 137 std::unique_ptr<QuicServerInfoMap> quic_server_info_map) {
167 // Add the entries from persisted data. 138 // Add the entries from persisted data.
168 QuicServerInfoMap temp_map(QuicServerInfoMap::NO_AUTO_EVICT); 139 quic_server_info_map_.Swap(*quic_server_info_map);
140
141 // Add the entries from the memory cache.
169 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin(); 142 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin();
170 it != quic_server_info_map->rend(); ++it) { 143 it != quic_server_info_map->rend(); ++it) {
171 temp_map.Put(it->first, it->second);
172 }
173
174 quic_server_info_map_.Swap(temp_map);
175
176 // Add the entries from the memory cache.
177 for (QuicServerInfoMap::reverse_iterator it = temp_map.rbegin();
178 it != temp_map.rend(); ++it) {
179 if (quic_server_info_map_.Get(it->first) == quic_server_info_map_.end()) { 144 if (quic_server_info_map_.Get(it->first) == quic_server_info_map_.end()) {
180 quic_server_info_map_.Put(it->first, it->second); 145 quic_server_info_map_.Put(it->first, it->second);
181 } 146 }
182 } 147 }
183 } 148 }
184 149
185 void HttpServerPropertiesImpl::GetSpdyServerList( 150 void HttpServerPropertiesImpl::GetSpdyServerList(
186 base::ListValue* spdy_server_list, 151 std::vector<std::string>* spdy_servers,
187 size_t max_size) const { 152 size_t max_size) const {
188 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 153 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
189 DCHECK(spdy_server_list); 154 DCHECK(spdy_servers);
190 spdy_server_list->Clear(); 155
156 spdy_servers->clear();
191 size_t count = 0; 157 size_t count = 0;
192 // Get the list of servers (scheme/host/port) that support SPDY. 158 // Get the list of servers (scheme/host/port) that support SPDY.
193 for (SpdyServersMap::const_iterator it = spdy_servers_map_.begin(); 159 for (SpdyServersMap::const_iterator it = spdy_servers_map_.begin();
194 it != spdy_servers_map_.end() && count < max_size; ++it) { 160 it != spdy_servers_map_.end() && count < max_size; ++it) {
195 const std::string spdy_server = it->first;
196 if (it->second) { 161 if (it->second) {
197 spdy_server_list->AppendString(spdy_server); 162 spdy_servers->push_back(it->first);
198 ++count; 163 ++count;
199 } 164 }
200 } 165 }
201 } 166 }
202 167
203 void HttpServerPropertiesImpl::Clear() { 168 void HttpServerPropertiesImpl::Clear() {
204 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 169 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
205 spdy_servers_map_.Clear(); 170 spdy_servers_map_.Clear();
206 alternative_service_map_.Clear(); 171 alternative_service_map_.Clear();
207 canonical_host_to_origin_map_.clear(); 172 canonical_host_to_origin_map_.clear();
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 if (map_it->second.empty()) { 660 if (map_it->second.empty()) {
696 RemoveCanonicalHost(map_it->first); 661 RemoveCanonicalHost(map_it->first);
697 map_it = alternative_service_map_.Erase(map_it); 662 map_it = alternative_service_map_.Erase(map_it);
698 continue; 663 continue;
699 } 664 }
700 ++map_it; 665 ++map_it;
701 } 666 }
702 } 667 }
703 668
704 } // namespace net 669 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698