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 "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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 19 const uint64 kBrokenAlternateProtocolDelaySecs = 300; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 23 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
24 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 24 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
25 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), | 25 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), |
26 alternate_protocol_experiment_( | |
27 ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT), | |
28 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 26 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
29 alternate_protocol_probability_threshold_(1), | 27 alternate_protocol_probability_threshold_(1), |
30 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
31 canoncial_suffixes_.push_back(".c.youtube.com"); | 29 canoncial_suffixes_.push_back(".c.youtube.com"); |
32 canoncial_suffixes_.push_back(".googlevideo.com"); | 30 canoncial_suffixes_.push_back(".googlevideo.com"); |
33 canoncial_suffixes_.push_back(".googleusercontent.com"); | 31 canoncial_suffixes_.push_back(".googleusercontent.com"); |
34 } | 32 } |
35 | 33 |
36 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 34 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
37 } | 35 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 << "] to [Port: " << alternate_port | 278 << "] to [Port: " << alternate_port |
281 << ", Protocol: " << alternate_protocol | 279 << ", Protocol: " << alternate_protocol |
282 << ", Probability: " << alternate_probability | 280 << ", Probability: " << alternate_probability |
283 << "]."; | 281 << "]."; |
284 } | 282 } |
285 } else { | 283 } else { |
286 if (alternate_probability >= alternate_protocol_probability_threshold_) { | 284 if (alternate_probability >= alternate_protocol_probability_threshold_) { |
287 // TODO(rch): Consider the case where multiple requests are started | 285 // TODO(rch): Consider the case where multiple requests are started |
288 // before the first completes. In this case, only one of the jobs | 286 // before the first completes. In this case, only one of the jobs |
289 // would reach this code, whereas all of them should should have. | 287 // would reach this code, whereas all of them should should have. |
290 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING, | 288 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
291 alternate_protocol_experiment_); | |
292 } | 289 } |
293 } | 290 } |
294 | 291 |
295 alternate_protocol_map_.Put(server, alternate); | 292 alternate_protocol_map_.Put(server, alternate); |
296 | 293 |
297 // If this host ends with a canonical suffix, then set it as the | 294 // If this host ends with a canonical suffix, then set it as the |
298 // canonical host. | 295 // canonical host. |
299 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 296 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
300 std::string canonical_suffix = canoncial_suffixes_[i]; | 297 std::string canonical_suffix = canoncial_suffixes_[i]; |
301 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 298 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 alternate_protocol_map_.Erase(it); | 351 alternate_protocol_map_.Erase(it); |
355 | 352 |
356 RemoveCanonicalHost(server); | 353 RemoveCanonicalHost(server); |
357 } | 354 } |
358 | 355 |
359 const AlternateProtocolMap& | 356 const AlternateProtocolMap& |
360 HttpServerPropertiesImpl::alternate_protocol_map() const { | 357 HttpServerPropertiesImpl::alternate_protocol_map() const { |
361 return alternate_protocol_map_; | 358 return alternate_protocol_map_; |
362 } | 359 } |
363 | 360 |
364 void HttpServerPropertiesImpl::SetAlternateProtocolExperiment( | |
365 AlternateProtocolExperiment experiment) { | |
366 alternate_protocol_experiment_ = experiment; | |
367 } | |
368 | |
369 AlternateProtocolExperiment | |
370 HttpServerPropertiesImpl::GetAlternateProtocolExperiment() const { | |
371 return alternate_protocol_experiment_; | |
372 } | |
373 | |
374 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 361 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
375 const HostPortPair& host_port_pair) { | 362 const HostPortPair& host_port_pair) { |
376 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 363 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
377 if (it == spdy_settings_map_.end()) { | 364 if (it == spdy_settings_map_.end()) { |
378 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 365 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
379 return kEmptySettingsMap; | 366 return kEmptySettingsMap; |
380 } | 367 } |
381 return it->second; | 368 return it->second; |
382 } | 369 } |
383 | 370 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 500 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
514 base::MessageLoop::current()->PostDelayedTask( | 501 base::MessageLoop::current()->PostDelayedTask( |
515 FROM_HERE, | 502 FROM_HERE, |
516 base::Bind( | 503 base::Bind( |
517 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 504 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
518 weak_ptr_factory_.GetWeakPtr()), | 505 weak_ptr_factory_.GetWeakPtr()), |
519 delay); | 506 delay); |
520 } | 507 } |
521 | 508 |
522 } // namespace net | 509 } // namespace net |
OLD | NEW |