Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "base/time/default_tick_clock.h" | |
| 21 #include "base/values.h" | 20 #include "base/values.h" |
| 22 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
| 23 #include "net/base/ip_address.h" | 22 #include "net/base/ip_address.h" |
| 24 #include "net/base/linked_hash_map.h" | 23 #include "net/base/linked_hash_map.h" |
| 25 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
| 26 #include "net/http/broken_alternative_services.h" | 25 #include "net/http/broken_alternative_services.h" |
| 27 #include "net/http/http_server_properties.h" | 26 #include "net/http/http_server_properties.h" |
| 28 | 27 |
| 29 namespace base { | 28 namespace base { |
| 30 class ListValue; | 29 class ListValue; |
| 30 class TickClock; | |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 | 34 |
| 35 // The implementation for setting/retrieving the HTTP server properties. | 35 // The implementation for setting/retrieving the HTTP server properties. |
| 36 class NET_EXPORT HttpServerPropertiesImpl | 36 class NET_EXPORT HttpServerPropertiesImpl |
| 37 : public HttpServerProperties, | 37 : public HttpServerProperties, |
| 38 public BrokenAlternativeServices::Delegate { | 38 public BrokenAlternativeServices::Delegate { |
| 39 public: | 39 public: |
| 40 HttpServerPropertiesImpl(); | 40 HttpServerPropertiesImpl(); |
| 41 explicit HttpServerPropertiesImpl( | |
| 42 base::TickClock* broken_alternative_services_clock); | |
| 43 ~HttpServerPropertiesImpl() override; | 41 ~HttpServerPropertiesImpl() override; |
| 44 | 42 |
| 45 // Sets |spdy_servers_map_| with the servers (host/port) from | 43 // Sets |spdy_servers_map_| with the servers (host/port) from |
| 46 // |spdy_servers| that either support SPDY or not. | 44 // |spdy_servers| that either support SPDY or not. |
| 47 void SetSpdyServers(std::vector<std::string>* spdy_servers, | 45 void SetSpdyServers(std::vector<std::string>* spdy_servers, |
| 48 bool support_spdy); | 46 bool support_spdy); |
| 49 | 47 |
| 50 void SetAlternativeServiceServers( | 48 void SetAlternativeServiceServers( |
| 51 AlternativeServiceMap* alternate_protocol_servers); | 49 AlternativeServiceMap* alternate_protocol_servers); |
| 52 | 50 |
| 53 void SetSupportsQuic(IPAddress* last_address); | 51 void SetSupportsQuic(IPAddress* last_address); |
| 54 | 52 |
| 55 void SetServerNetworkStats(ServerNetworkStatsMap* server_network_stats_map); | 53 void SetServerNetworkStats(ServerNetworkStatsMap* server_network_stats_map); |
| 56 | 54 |
| 57 void SetQuicServerInfoMap(QuicServerInfoMap* quic_server_info_map); | 55 void SetQuicServerInfoMap(QuicServerInfoMap* quic_server_info_map); |
| 58 | 56 |
| 59 // Get the list of servers (host/port) that support SPDY. The max_size is the | 57 // Get the list of servers (host/port) that support SPDY. The max_size is the |
| 60 // number of MRU servers that support SPDY that are to be returned. | 58 // number of MRU servers that support SPDY that are to be returned. |
| 61 void GetSpdyServerList(base::ListValue* spdy_server_list, | 59 void GetSpdyServerList(base::ListValue* spdy_server_list, |
| 62 size_t max_size) const; | 60 size_t max_size) const; |
| 63 | 61 |
| 62 void AddBrokenAndRecentlyBrokenAlternativeServices( | |
| 63 std::unique_ptr<BrokenAlternativeServiceList> | |
| 64 broken_alternative_service_list, | |
| 65 std::unique_ptr<RecentlyBrokenAlternativeServices> | |
| 66 recently_broken_alternative_services); | |
| 67 | |
| 68 const BrokenAlternativeServiceList& broken_alternative_service_list() const; | |
| 69 | |
| 70 const RecentlyBrokenAlternativeServices& | |
| 71 recently_broken_alternative_services() const; | |
| 72 | |
| 64 // Returns flattened string representation of the |host_port_pair|. Used by | 73 // Returns flattened string representation of the |host_port_pair|. Used by |
| 65 // unittests. | 74 // unittests. |
| 66 static std::string GetFlattenedSpdyServer(const HostPortPair& host_port_pair); | 75 static std::string GetFlattenedSpdyServer(const HostPortPair& host_port_pair); |
| 67 | 76 |
| 68 // Returns the canonical host suffix for |host|, or nullptr if none | 77 // Returns the canonical host suffix for |host|, or nullptr if none |
| 69 // exists. | 78 // exists. |
| 70 const std::string* GetCanonicalSuffix(const std::string& host) const; | 79 const std::string* GetCanonicalSuffix(const std::string& host) const; |
| 71 | 80 |
| 72 // ----------------------------- | 81 // ----------------------------- |
| 73 // HttpServerProperties methods: | 82 // HttpServerProperties methods: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 const QuicServerInfoMap& quic_server_info_map() const override; | 126 const QuicServerInfoMap& quic_server_info_map() const override; |
| 118 size_t max_server_configs_stored_in_properties() const override; | 127 size_t max_server_configs_stored_in_properties() const override; |
| 119 void SetMaxServerConfigsStoredInProperties( | 128 void SetMaxServerConfigsStoredInProperties( |
| 120 size_t max_server_configs_stored_in_properties) override; | 129 size_t max_server_configs_stored_in_properties) override; |
| 121 bool IsInitialized() const override; | 130 bool IsInitialized() const override; |
| 122 | 131 |
| 123 // BrokenAlternativeServices::Delegate method. | 132 // BrokenAlternativeServices::Delegate method. |
| 124 void OnExpireBrokenAlternativeService( | 133 void OnExpireBrokenAlternativeService( |
| 125 const AlternativeService& expired_alternative_service) override; | 134 const AlternativeService& expired_alternative_service) override; |
| 126 | 135 |
| 136 // |clock| is unowned. | |
| 137 void SetBrokenAlternativeServicesTickClockForTesting(base::TickClock* clock); | |
|
Ryan Hamilton
2017/06/12 18:57:33
The constructor-based method for setting the clock
wangyix1
2017/06/14 00:01:25
Acknowledged. Will go back to using a TickClock* c
| |
| 138 | |
| 127 private: | 139 private: |
| 128 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this | 140 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this |
| 129 // friendness is no longer required. | 141 // friendness is no longer required. |
| 130 friend class HttpServerPropertiesImplPeer; | 142 friend class HttpServerPropertiesImplPeer; |
| 131 | 143 |
| 132 // |spdy_servers_map_| has flattened representation of servers | 144 // |spdy_servers_map_| has flattened representation of servers |
| 133 // (scheme, host, port) that either support or not support SPDY protocol. | 145 // (scheme, host, port) that either support or not support SPDY protocol. |
| 134 typedef base::MRUCache<std::string, bool> SpdyServersMap; | 146 typedef base::MRUCache<std::string, bool> SpdyServersMap; |
| 135 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap; | 147 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap; |
| 136 typedef std::vector<std::string> CanonicalSufficList; | 148 typedef std::vector<std::string> CanonicalSufficList; |
| 137 typedef std::set<HostPortPair> Http11ServerHostPortSet; | 149 typedef std::set<HostPortPair> Http11ServerHostPortSet; |
| 138 | 150 |
| 139 // Return the iterator for |server|, or for its canonical host, or end. | 151 // Return the iterator for |server|, or for its canonical host, or end. |
| 140 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator( | 152 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator( |
| 141 const url::SchemeHostPort& server); | 153 const url::SchemeHostPort& server); |
| 142 | 154 |
| 143 // Return the canonical host for |server|, or end if none exists. | 155 // Return the canonical host for |server|, or end if none exists. |
| 144 CanonicalHostMap::const_iterator GetCanonicalHost( | 156 CanonicalHostMap::const_iterator GetCanonicalHost( |
| 145 const url::SchemeHostPort& server) const; | 157 const url::SchemeHostPort& server) const; |
| 146 | 158 |
| 147 // Remove the cononical host for |server|. | 159 // Remove the cononical host for |server|. |
| 148 void RemoveCanonicalHost(const url::SchemeHostPort& server); | 160 void RemoveCanonicalHost(const url::SchemeHostPort& server); |
| 149 | 161 |
| 150 base::DefaultTickClock broken_alternative_services_clock_; | |
| 151 BrokenAlternativeServices broken_alternative_services_; | |
| 152 | |
| 153 SpdyServersMap spdy_servers_map_; | 162 SpdyServersMap spdy_servers_map_; |
| 154 Http11ServerHostPortSet http11_servers_; | 163 Http11ServerHostPortSet http11_servers_; |
| 155 | 164 |
| 156 AlternativeServiceMap alternative_service_map_; | 165 AlternativeServiceMap alternative_service_map_; |
| 157 | 166 |
| 167 BrokenAlternativeServices broken_alternative_services_; | |
| 168 | |
| 158 IPAddress last_quic_address_; | 169 IPAddress last_quic_address_; |
| 159 ServerNetworkStatsMap server_network_stats_map_; | 170 ServerNetworkStatsMap server_network_stats_map_; |
| 160 // Contains a map of servers which could share the same alternate protocol. | 171 // Contains a map of servers which could share the same alternate protocol. |
| 161 // Map from a Canonical scheme/host/port (host is some postfix of host names) | 172 // Map from a Canonical scheme/host/port (host is some postfix of host names) |
| 162 // to an actual origin, which has a plausible alternate protocol mapping. | 173 // to an actual origin, which has a plausible alternate protocol mapping. |
| 163 CanonicalHostMap canonical_host_to_origin_map_; | 174 CanonicalHostMap canonical_host_to_origin_map_; |
| 164 // Contains list of suffixes (for exmaple ".c.youtube.com", | 175 // Contains list of suffixes (for exmaple ".c.youtube.com", |
| 165 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. | 176 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. |
| 166 CanonicalSufficList canonical_suffixes_; | 177 CanonicalSufficList canonical_suffixes_; |
| 167 | 178 |
| 168 QuicServerInfoMap quic_server_info_map_; | 179 QuicServerInfoMap quic_server_info_map_; |
| 169 size_t max_server_configs_stored_in_properties_; | 180 size_t max_server_configs_stored_in_properties_; |
| 170 | 181 |
| 171 THREAD_CHECKER(thread_checker_); | 182 THREAD_CHECKER(thread_checker_); |
| 172 | 183 |
| 173 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); | 184 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); |
| 174 }; | 185 }; |
| 175 | 186 |
| 176 } // namespace net | 187 } // namespace net |
| 177 | 188 |
| 178 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ | 189 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ |
| OLD | NEW |