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

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

Issue 1017453008: Make GetAlternateProtocol return AlternativeService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error. Created 5 years, 9 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const HostPortPair& host_port_pair) { 171 const HostPortPair& host_port_pair) {
172 DCHECK(CalledOnValidThread()); 172 DCHECK(CalledOnValidThread());
173 if (host_port_pair.host().empty()) 173 if (host_port_pair.host().empty())
174 return false; 174 return false;
175 175
176 SpdyServerHostPortMap::iterator spdy_host_port = 176 SpdyServerHostPortMap::iterator spdy_host_port =
177 spdy_servers_map_.Get(host_port_pair.ToString()); 177 spdy_servers_map_.Get(host_port_pair.ToString());
178 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) 178 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second)
179 return true; 179 return true;
180 180
181 const AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); 181 const AlternativeService alternative_service =
182 return info.protocol == QUIC; 182 GetAlternativeService(host_port_pair);
183 return alternative_service.protocol == QUIC;
183 } 184 }
184 185
185 void HttpServerPropertiesImpl::SetSupportsSpdy( 186 void HttpServerPropertiesImpl::SetSupportsSpdy(
186 const HostPortPair& host_port_pair, 187 const HostPortPair& host_port_pair,
187 bool support_spdy) { 188 bool support_spdy) {
188 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
189 if (host_port_pair.host().empty()) 190 if (host_port_pair.host().empty())
190 return; 191 return;
191 192
192 SpdyServerHostPortMap::iterator spdy_host_port = 193 SpdyServerHostPortMap::iterator spdy_host_port =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // suffix. 231 // suffix.
231 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { 232 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
232 std::string canonical_suffix = canonical_suffixes_[i]; 233 std::string canonical_suffix = canonical_suffixes_[i];
233 if (EndsWith(host, canonical_suffixes_[i], false)) { 234 if (EndsWith(host, canonical_suffixes_[i], false)) {
234 return canonical_suffix; 235 return canonical_suffix;
235 } 236 }
236 } 237 }
237 return std::string(); 238 return std::string();
238 } 239 }
239 240
240 AlternateProtocolInfo HttpServerPropertiesImpl::GetAlternateProtocol( 241 AlternativeService HttpServerPropertiesImpl::GetAlternativeService(
241 const HostPortPair& server) { 242 const HostPortPair& origin) {
242 AlternateProtocolMap::const_iterator it = 243 AlternateProtocolMap::const_iterator it =
243 GetAlternateProtocolIterator(server); 244 GetAlternateProtocolIterator(origin);
244 if (it != alternate_protocol_map_.end() && 245 if (it != alternate_protocol_map_.end() &&
245 it->second.probability >= alternate_protocol_probability_threshold_) 246 it->second.probability >= alternate_protocol_probability_threshold_)
246 return it->second; 247 return AlternativeService(it->second.protocol, origin.host(),
248 it->second.port);
247 249
248 if (g_forced_alternate_protocol) 250 if (g_forced_alternate_protocol)
249 return *g_forced_alternate_protocol; 251 return AlternativeService(g_forced_alternate_protocol->protocol,
252 origin.host(), g_forced_alternate_protocol->port);
250 253
251 AlternateProtocolInfo uninitialized_alternate_protocol; 254 AlternativeService uninitialize_alternative_service;
252 return uninitialized_alternate_protocol; 255 return uninitialize_alternative_service;
253 } 256 }
254 257
255 void HttpServerPropertiesImpl::SetAlternateProtocol( 258 void HttpServerPropertiesImpl::SetAlternateProtocol(
256 const HostPortPair& server, 259 const HostPortPair& server,
257 uint16 alternate_port, 260 uint16 alternate_port,
258 AlternateProtocol alternate_protocol, 261 AlternateProtocol alternate_protocol,
259 double alternate_probability) { 262 double alternate_probability) {
260 const AlternativeService alternative_service(alternate_protocol, 263 const AlternativeService alternative_service(alternate_protocol,
261 server.host(), alternate_port); 264 server.host(), alternate_port);
262 if (IsAlternativeServiceBroken(alternative_service)) { 265 if (IsAlternativeServiceBroken(alternative_service)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { 303 if (EndsWith(server.host(), canonical_suffixes_[i], false)) {
301 HostPortPair canonical_host(canonical_suffix, server.port()); 304 HostPortPair canonical_host(canonical_suffix, server.port());
302 canonical_host_to_origin_map_[canonical_host] = server; 305 canonical_host_to_origin_map_[canonical_host] = server;
303 break; 306 break;
304 } 307 }
305 } 308 }
306 } 309 }
307 310
308 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( 311 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
309 const HostPortPair& server) { 312 const HostPortPair& server) {
310 const AlternateProtocolInfo alternate = GetAlternateProtocol(server); 313 const AlternativeService alternative_service = GetAlternativeService(server);
311 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { 314 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) {
312 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; 315 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken.";
313 return; 316 return;
314 } 317 }
315 const AlternativeService alternative_service(alternate.protocol,
316 server.host(), alternate.port);
317 int count = ++recently_broken_alternative_services_[alternative_service]; 318 int count = ++recently_broken_alternative_services_[alternative_service];
318 base::TimeDelta delay = 319 base::TimeDelta delay =
319 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); 320 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
320 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); 321 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
321 auto result = broken_alternative_services_.insert( 322 auto result = broken_alternative_services_.insert(
322 std::make_pair(alternative_service, when)); 323 std::make_pair(alternative_service, when));
323 // Return if alternative service is already in expiration queue. 324 // Return if alternative service is already in expiration queue.
324 if (!result.second) { 325 if (!result.second) {
325 return; 326 return;
326 } 327 }
(...skipping 15 matching lines...) Expand all
342 recently_broken_alternative_services_[alternative_service] = 1; 343 recently_broken_alternative_services_[alternative_service] = 1;
343 } 344 }
344 345
345 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken( 346 bool HttpServerPropertiesImpl::IsAlternativeServiceBroken(
346 const AlternativeService& alternative_service) { 347 const AlternativeService& alternative_service) {
347 return ContainsKey(broken_alternative_services_, alternative_service); 348 return ContainsKey(broken_alternative_services_, alternative_service);
348 } 349 }
349 350
350 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( 351 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
351 const HostPortPair& server) { 352 const HostPortPair& server) {
352 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); 353 const AlternativeService alternative_service = GetAlternativeService(server);
353 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) 354 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
354 return false; 355 return false;
355 const AlternativeService alternative_service(
356 alternate_protocol.protocol, server.host(), alternate_protocol.port);
357 return ContainsKey(recently_broken_alternative_services_, 356 return ContainsKey(recently_broken_alternative_services_,
358 alternative_service); 357 alternative_service);
359 } 358 }
360 359
361 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( 360 void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
362 const HostPortPair& server) { 361 const HostPortPair& server) {
363 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); 362 const AlternativeService alternative_service = GetAlternativeService(server);
364 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) 363 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
365 return; 364 return;
366 const AlternativeService alternative_service(
367 alternate_protocol.protocol, server.host(), alternate_protocol.port);
368 broken_alternative_services_.erase(alternative_service); 365 broken_alternative_services_.erase(alternative_service);
369 recently_broken_alternative_services_.erase(alternative_service); 366 recently_broken_alternative_services_.erase(alternative_service);
370 } 367 }
371 368
372 void HttpServerPropertiesImpl::ClearAlternateProtocol( 369 void HttpServerPropertiesImpl::ClearAlternateProtocol(
373 const HostPortPair& server) { 370 const HostPortPair& server) {
374 RemoveCanonicalHost(server); 371 RemoveCanonicalHost(server);
375 372
376 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); 373 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server);
377 if (it == alternate_protocol_map_.end()) { 374 if (it == alternate_protocol_map_.end()) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 552 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
556 base::MessageLoop::current()->PostDelayedTask( 553 base::MessageLoop::current()->PostDelayedTask(
557 FROM_HERE, 554 FROM_HERE,
558 base::Bind( 555 base::Bind(
559 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 556 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
560 weak_ptr_factory_.GetWeakPtr()), 557 weak_ptr_factory_.GetWeakPtr()),
561 delay); 558 delay);
562 } 559 }
563 560
564 } // namespace net 561 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698