| 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 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ | 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ |
| 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ | 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
| 20 #include "net/base/linked_hash_map.h" |
| 20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
| 21 #include "net/http/http_server_properties.h" | 22 #include "net/http/http_server_properties.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class ListValue; | 25 class ListValue; |
| 25 } | 26 } |
| 26 | 27 |
| 28 namespace BASE_HASH_NAMESPACE { |
| 29 |
| 30 template <> |
| 31 struct hash<net::AlternativeService> { |
| 32 size_t operator()(const net::AlternativeService& entry) const { |
| 33 return entry.protocol ^ hash<std::string>()(entry.host) ^ entry.port; |
| 34 } |
| 35 }; |
| 36 |
| 37 } // namespace BASE_HASH_NAMESPACE |
| 38 |
| 27 namespace net { | 39 namespace net { |
| 28 | 40 |
| 29 // The implementation for setting/retrieving the HTTP server properties. | 41 // The implementation for setting/retrieving the HTTP server properties. |
| 30 class NET_EXPORT HttpServerPropertiesImpl | 42 class NET_EXPORT HttpServerPropertiesImpl |
| 31 : public HttpServerProperties, | 43 : public HttpServerProperties, |
| 32 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 44 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 33 public: | 45 public: |
| 34 HttpServerPropertiesImpl(); | 46 HttpServerPropertiesImpl(); |
| 35 ~HttpServerPropertiesImpl() override; | 47 ~HttpServerPropertiesImpl() override; |
| 36 | 48 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const ServerNetworkStatsMap& server_network_stats_map() const override; | 122 const ServerNetworkStatsMap& server_network_stats_map() const override; |
| 111 | 123 |
| 112 private: | 124 private: |
| 113 // |spdy_servers_map_| has flattened representation of servers (host, port) | 125 // |spdy_servers_map_| has flattened representation of servers (host, port) |
| 114 // that either support or not support SPDY protocol. | 126 // that either support or not support SPDY protocol. |
| 115 typedef base::MRUCache<std::string, bool> SpdyServerHostPortMap; | 127 typedef base::MRUCache<std::string, bool> SpdyServerHostPortMap; |
| 116 typedef std::map<HostPortPair, HostPortPair> CanonicalHostMap; | 128 typedef std::map<HostPortPair, HostPortPair> CanonicalHostMap; |
| 117 typedef std::vector<std::string> CanonicalSufficList; | 129 typedef std::vector<std::string> CanonicalSufficList; |
| 118 typedef std::set<HostPortPair> Http11ServerHostPortSet; | 130 typedef std::set<HostPortPair> Http11ServerHostPortSet; |
| 119 | 131 |
| 120 // Broken alternative service with expiration time. | 132 // Linked hash map from AlternativeService to expiration time. This container |
| 121 struct BrokenAlternateProtocolEntryWithTime { | 133 // is a queue with O(1) enqueue and dequeue, and a hash_map with O(1) lookup |
| 122 BrokenAlternateProtocolEntryWithTime( | 134 // at the same time. |
| 123 const AlternativeService& alternative_service, | 135 typedef linked_hash_map<AlternativeService, base::TimeTicks> |
| 124 base::TimeTicks when) | 136 BrokenAlternativeServices; |
| 125 : alternative_service(alternative_service), when(when) {} | 137 // Map to the number of times each alternative service has been marked broken. |
| 126 | 138 typedef std::map<AlternativeService, int> RecentlyBrokenAlternativeServices; |
| 127 AlternativeService alternative_service; | |
| 128 base::TimeTicks when; | |
| 129 }; | |
| 130 // Deque of BrokenAlternateProtocolEntryWithTime items, ordered by expiration | |
| 131 // time. | |
| 132 typedef std::deque<BrokenAlternateProtocolEntryWithTime> | |
| 133 BrokenAlternateProtocolList; | |
| 134 // Map from (server, alternate protocol and port) to the number of | |
| 135 // times that alternate protocol has been marked broken for that server. | |
| 136 typedef std::map<AlternativeService, int> BrokenAlternateProtocolMap; | |
| 137 | 139 |
| 138 // Return the iterator for |server|, or for its canonical host, or end. | 140 // Return the iterator for |server|, or for its canonical host, or end. |
| 139 AlternateProtocolMap::const_iterator GetAlternateProtocolIterator( | 141 AlternateProtocolMap::const_iterator GetAlternateProtocolIterator( |
| 140 const HostPortPair& server); | 142 const HostPortPair& server); |
| 141 | 143 |
| 142 // Return the canonical host for |server|, or end if none exists. | 144 // Return the canonical host for |server|, or end if none exists. |
| 143 CanonicalHostMap::const_iterator GetCanonicalHost(HostPortPair server) const; | 145 CanonicalHostMap::const_iterator GetCanonicalHost(HostPortPair server) const; |
| 144 | 146 |
| 145 void RemoveCanonicalHost(const HostPortPair& server); | 147 void RemoveCanonicalHost(const HostPortPair& server); |
| 146 void ExpireBrokenAlternateProtocolMappings(); | 148 void ExpireBrokenAlternateProtocolMappings(); |
| 147 void ScheduleBrokenAlternateProtocolMappingsExpiration(); | 149 void ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 148 | 150 |
| 149 SpdyServerHostPortMap spdy_servers_map_; | 151 SpdyServerHostPortMap spdy_servers_map_; |
| 150 Http11ServerHostPortSet http11_servers_; | 152 Http11ServerHostPortSet http11_servers_; |
| 151 | 153 |
| 152 AlternateProtocolMap alternate_protocol_map_; | 154 AlternateProtocolMap alternate_protocol_map_; |
| 153 BrokenAlternateProtocolList broken_alternate_protocol_list_; | 155 BrokenAlternativeServices broken_alternative_services_; |
| 154 BrokenAlternateProtocolMap broken_alternate_protocol_map_; | 156 // Class invariant: Every alternative service in broken_alternative_services_ |
| 157 // must also be in recently_broken_alternative_services_. |
| 158 RecentlyBrokenAlternativeServices recently_broken_alternative_services_; |
| 155 | 159 |
| 156 IPAddressNumber last_quic_address_; | 160 IPAddressNumber last_quic_address_; |
| 157 SpdySettingsMap spdy_settings_map_; | 161 SpdySettingsMap spdy_settings_map_; |
| 158 ServerNetworkStatsMap server_network_stats_map_; | 162 ServerNetworkStatsMap server_network_stats_map_; |
| 159 // Contains a map of servers which could share the same alternate protocol. | 163 // Contains a map of servers which could share the same alternate protocol. |
| 160 // Map from a Canonical host/port (host is some postfix of host names) to an | 164 // Map from a Canonical host/port (host is some postfix of host names) to an |
| 161 // actual origin, which has a plausible alternate protocol mapping. | 165 // actual origin, which has a plausible alternate protocol mapping. |
| 162 CanonicalHostMap canonical_host_to_origin_map_; | 166 CanonicalHostMap canonical_host_to_origin_map_; |
| 163 // Contains list of suffixes (for exmaple ".c.youtube.com", | 167 // Contains list of suffixes (for exmaple ".c.youtube.com", |
| 164 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. | 168 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. |
| 165 CanonicalSufficList canonical_suffixes_; | 169 CanonicalSufficList canonical_suffixes_; |
| 166 | 170 |
| 167 double alternate_protocol_probability_threshold_; | 171 double alternate_protocol_probability_threshold_; |
| 168 | 172 |
| 169 base::WeakPtrFactory<HttpServerPropertiesImpl> weak_ptr_factory_; | 173 base::WeakPtrFactory<HttpServerPropertiesImpl> weak_ptr_factory_; |
| 170 | 174 |
| 171 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); | 175 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); |
| 172 }; | 176 }; |
| 173 | 177 |
| 174 } // namespace net | 178 } // namespace net |
| 175 | 179 |
| 176 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ | 180 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ |
| OLD | NEW |