OLD | NEW |
---|---|
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 Loading... | |
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 const std::vector<std::string>* spdy_servers, |
Ryan Hamilton
2017/06/20 18:25:56
I wonder if this should be a unique_ptr<SpdyServer
wangyix1
2017/06/21 18:45:32
That should work, it would reduce copying and be c
| |
49 bool support_spdy) { | 49 bool support_spdy) { |
50 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 50 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
51 if (!spdy_servers) | 51 if (!spdy_servers) |
52 return; | 52 return; |
53 | 53 |
54 // Add the entries from persisted data. | 54 // Add the entries from persisted data. |
55 SpdyServersMap spdy_servers_map(SpdyServersMap::NO_AUTO_EVICT); | 55 SpdyServersMap spdy_servers_map(SpdyServersMap::NO_AUTO_EVICT); |
56 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); | 56 for (auto it = spdy_servers->rbegin(); it != spdy_servers->rend(); ++it) { |
Zhongyi Shi
2017/06/20 22:06:18
nit: in general, we prefer to specify the explicit
wangyix1
2017/06/21 18:45:32
Done.
| |
57 it != spdy_servers->rend(); ++it) { | |
58 spdy_servers_map.Put(*it, support_spdy); | 57 spdy_servers_map.Put(*it, support_spdy); |
59 } | 58 } |
60 | 59 |
61 // |spdy_servers_map| will have the memory cache. | 60 // |spdy_servers_map| will have the memory cache. |
62 spdy_servers_map_.Swap(spdy_servers_map); | 61 spdy_servers_map_.Swap(spdy_servers_map); |
63 | 62 |
64 // Add the entries from the memory cache. | 63 // Add the entries from the memory cache. |
65 for (SpdyServersMap::reverse_iterator it = spdy_servers_map.rbegin(); | 64 for (SpdyServersMap::reverse_iterator it = spdy_servers_map.rbegin(); |
66 it != spdy_servers_map.rend(); ++it) { | 65 it != spdy_servers_map.rend(); ++it) { |
67 // Add the entry if it is not in the cache, otherwise move it to the front | 66 // Add the entry if it is not in the cache, otherwise move it to the front |
68 // of recency list. | 67 // of recency list. |
69 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) | 68 if (spdy_servers_map_.Get(it->first) == spdy_servers_map_.end()) |
70 spdy_servers_map_.Put(it->first, it->second); | 69 spdy_servers_map_.Put(it->first, it->second); |
71 } | 70 } |
72 } | 71 } |
73 | 72 |
74 void HttpServerPropertiesImpl::SetAlternativeServiceServers( | 73 void HttpServerPropertiesImpl::SetAlternativeServiceServers( |
75 AlternativeServiceMap* alternative_service_map) { | 74 std::unique_ptr<AlternativeServiceMap> alternative_service_map) { |
76 int32_t size_diff = | 75 int32_t size_diff = |
77 alternative_service_map->size() - alternative_service_map_.size(); | 76 alternative_service_map->size() - alternative_service_map_.size(); |
78 if (size_diff > 0) { | 77 if (size_diff > 0) { |
79 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries", | 78 UMA_HISTOGRAM_COUNTS("Net.AlternativeServiceServers.MorePrefsEntries", |
80 size_diff); | 79 size_diff); |
81 } else { | 80 } else { |
82 UMA_HISTOGRAM_COUNTS( | 81 UMA_HISTOGRAM_COUNTS( |
83 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff); | 82 "Net.AlternativeServiceServers.MoreOrEqualCacheEntries", -size_diff); |
84 } | 83 } |
85 | 84 |
86 AlternativeServiceMap new_alternative_service_map( | |
87 AlternativeServiceMap::NO_AUTO_EVICT); | |
88 // Add the entries from persisted data. | 85 // Add the entries from persisted data. |
89 for (AlternativeServiceMap::reverse_iterator input_it = | 86 alternative_service_map_.Swap(*alternative_service_map); |
Ryan Hamilton
2017/06/20 18:25:56
how about just:
alternative_service_map_ = std::m
wangyix1
2017/06/21 18:45:32
MRUCache doesn't allow copying. Furthermore, it's
Ryan Hamilton
2017/06/22 02:45:52
Even though it doesn't support copying, it *could*
| |
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 | 87 |
98 // Add the entries from the memory cache. | 88 // Add the entries from the memory cache. |
99 for (AlternativeServiceMap::reverse_iterator input_it = | 89 for (auto input_it = alternative_service_map->rbegin(); |
100 new_alternative_service_map.rbegin(); | 90 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) == | 91 if (alternative_service_map_.Get(input_it->first) == |
103 alternative_service_map_.end()) { | 92 alternative_service_map_.end()) { |
104 alternative_service_map_.Put(input_it->first, input_it->second); | 93 alternative_service_map_.Put(input_it->first, input_it->second); |
105 } | 94 } |
106 } | 95 } |
107 | 96 |
108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. | 97 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. |
109 const uint16_t kCanonicalPort = 443; | 98 const uint16_t kCanonicalPort = 443; |
110 const char* kCanonicalScheme = "https"; | 99 const char* kCanonicalScheme = "https"; |
111 for (const std::string& canonical_suffix : canonical_suffixes_) { | 100 for (const std::string& canonical_suffix : canonical_suffixes_) { |
(...skipping 14 matching lines...) Expand all Loading... | |
126 if (base::EndsWith(it->first.host(), canonical_suffix, | 115 if (base::EndsWith(it->first.host(), canonical_suffix, |
127 base::CompareCase::INSENSITIVE_ASCII) && | 116 base::CompareCase::INSENSITIVE_ASCII) && |
128 it->first.scheme() == canonical_server.scheme()) { | 117 it->first.scheme() == canonical_server.scheme()) { |
129 canonical_host_to_origin_map_[canonical_server] = it->first; | 118 canonical_host_to_origin_map_[canonical_server] = it->first; |
130 break; | 119 break; |
131 } | 120 } |
132 } | 121 } |
133 } | 122 } |
134 } | 123 } |
135 | 124 |
136 void HttpServerPropertiesImpl::SetSupportsQuic(IPAddress* last_address) { | 125 void HttpServerPropertiesImpl::SetSupportsQuic(const IPAddress* last_address) { |
137 if (last_address) | 126 if (last_address) |
138 last_quic_address_ = *last_address; | 127 last_quic_address_ = *last_address; |
139 } | 128 } |
140 | 129 |
141 void HttpServerPropertiesImpl::SetServerNetworkStats( | 130 void HttpServerPropertiesImpl::SetServerNetworkStats( |
142 ServerNetworkStatsMap* server_network_stats_map) { | 131 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map) { |
143 // Add the entries from persisted data. | 132 // Add the entries from persisted data. |
144 ServerNetworkStatsMap new_server_network_stats_map( | 133 server_network_stats_map_.Swap(*server_network_stats_map); |
Ryan Hamilton
2017/06/20 18:25:56
server_network_stats_map_ = std::move(*server_netw
wangyix1
2017/06/21 18:45:33
See comments for SetAlternativeServiceServers().
| |
145 ServerNetworkStatsMap::NO_AUTO_EVICT); | 134 |
135 // Add the entries from the memory cache. | |
146 for (ServerNetworkStatsMap::reverse_iterator it = | 136 for (ServerNetworkStatsMap::reverse_iterator it = |
147 server_network_stats_map->rbegin(); | 137 server_network_stats_map->rbegin(); |
148 it != server_network_stats_map->rend(); ++it) { | 138 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) == | 139 if (server_network_stats_map_.Get(it->first) == |
159 server_network_stats_map_.end()) { | 140 server_network_stats_map_.end()) { |
160 server_network_stats_map_.Put(it->first, it->second); | 141 server_network_stats_map_.Put(it->first, it->second); |
161 } | 142 } |
162 } | 143 } |
163 } | 144 } |
164 | 145 |
165 void HttpServerPropertiesImpl::SetQuicServerInfoMap( | 146 void HttpServerPropertiesImpl::SetQuicServerInfoMap( |
166 QuicServerInfoMap* quic_server_info_map) { | 147 std::unique_ptr<QuicServerInfoMap> quic_server_info_map) { |
167 // Add the entries from persisted data. | 148 // Add the entries from persisted data. |
168 QuicServerInfoMap temp_map(QuicServerInfoMap::NO_AUTO_EVICT); | 149 quic_server_info_map_.Swap(*quic_server_info_map); |
Ryan Hamilton
2017/06/20 18:25:56
quic_server_info_map_ = std::move(*quic_server_inf
wangyix1
2017/06/21 18:45:32
See comments for SetAlternativeServiceServers().
| |
150 | |
151 // Add the entries from the memory cache. | |
169 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin(); | 152 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map->rbegin(); |
170 it != quic_server_info_map->rend(); ++it) { | 153 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()) { | 154 if (quic_server_info_map_.Get(it->first) == quic_server_info_map_.end()) { |
180 quic_server_info_map_.Put(it->first, it->second); | 155 quic_server_info_map_.Put(it->first, it->second); |
181 } | 156 } |
182 } | 157 } |
183 } | 158 } |
184 | 159 |
185 void HttpServerPropertiesImpl::GetSpdyServerList( | 160 void HttpServerPropertiesImpl::GetSpdyServers( |
186 base::ListValue* spdy_server_list, | 161 std::vector<std::string>* spdy_servers, |
187 size_t max_size) const { | 162 size_t max_size) const { |
188 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 163 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
189 DCHECK(spdy_server_list); | 164 DCHECK(spdy_servers); |
190 spdy_server_list->Clear(); | 165 spdy_servers->clear(); |
191 size_t count = 0; | 166 size_t count = 0; |
192 // Get the list of servers (scheme/host/port) that support SPDY. | 167 // Get the list of servers (scheme/host/port) that support SPDY. |
193 for (SpdyServersMap::const_iterator it = spdy_servers_map_.begin(); | 168 for (SpdyServersMap::const_iterator it = spdy_servers_map_.begin(); |
194 it != spdy_servers_map_.end() && count < max_size; ++it) { | 169 it != spdy_servers_map_.end() && count < max_size; ++it) { |
195 const std::string spdy_server = it->first; | |
196 if (it->second) { | 170 if (it->second) { |
197 spdy_server_list->AppendString(spdy_server); | 171 spdy_servers->push_back(it->first); |
198 ++count; | 172 ++count; |
199 } | 173 } |
200 } | 174 } |
201 } | 175 } |
202 | 176 |
203 void HttpServerPropertiesImpl::Clear() { | 177 void HttpServerPropertiesImpl::Clear() { |
204 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 178 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
205 spdy_servers_map_.Clear(); | 179 spdy_servers_map_.Clear(); |
206 alternative_service_map_.Clear(); | 180 alternative_service_map_.Clear(); |
207 canonical_host_to_origin_map_.clear(); | 181 canonical_host_to_origin_map_.clear(); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 if (map_it->second.empty()) { | 669 if (map_it->second.empty()) { |
696 RemoveCanonicalHost(map_it->first); | 670 RemoveCanonicalHost(map_it->first); |
697 map_it = alternative_service_map_.Erase(map_it); | 671 map_it = alternative_service_map_.Erase(map_it); |
698 continue; | 672 continue; |
699 } | 673 } |
700 ++map_it; | 674 ++map_it; |
701 } | 675 } |
702 } | 676 } |
703 | 677 |
704 } // namespace net | 678 } // namespace net |
OLD | NEW |