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

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

Issue 2898983006: Fix and refactor HttpServerPropertiesImpl's alternative services brokenness expiration behavior (Closed)
Patch Set: Created 3 years, 7 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 #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/non_thread_safe.h" 19 #include "base/threading/non_thread_safe.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "net/base/host_port_pair.h" 21 #include "net/base/host_port_pair.h"
22 #include "net/base/ip_address.h" 22 #include "net/base/ip_address.h"
23 #include "net/base/linked_hash_map.h" 23 #include "net/base/linked_hash_map.h"
24 #include "net/base/net_export.h" 24 #include "net/base/net_export.h"
25 #include "net/http/http_broken_alternative_services_manager.h"
25 #include "net/http/http_server_properties.h" 26 #include "net/http/http_server_properties.h"
26 27
27 namespace base { 28 namespace base {
28 class ListValue; 29 class ListValue;
29 } 30 }
30 31
31 namespace net { 32 namespace net {
32 33
33 struct AlternativeServiceHash {
34 size_t operator()(const net::AlternativeService& entry) const {
35 return entry.protocol ^ std::hash<std::string>()(entry.host) ^ entry.port;
36 }
37 };
38
39 // The implementation for setting/retrieving the HTTP server properties. 34 // The implementation for setting/retrieving the HTTP server properties.
40 class NET_EXPORT HttpServerPropertiesImpl 35 class NET_EXPORT HttpServerPropertiesImpl
41 : public HttpServerProperties, 36 : public HttpServerProperties,
37 public HttpBrokenAlternativeServicesManager::Delegate,
42 NON_EXPORTED_BASE(public base::NonThreadSafe) { 38 NON_EXPORTED_BASE(public base::NonThreadSafe) {
43 public: 39 public:
44 HttpServerPropertiesImpl(); 40 HttpServerPropertiesImpl();
41 explicit HttpServerPropertiesImpl(
42 HttpBrokenAlternativeServicesManager::Clock* clock);
45 ~HttpServerPropertiesImpl() override; 43 ~HttpServerPropertiesImpl() override;
46 44
47 // Sets |spdy_servers_map_| with the servers (host/port) from 45 // Sets |spdy_servers_map_| with the servers (host/port) from
48 // |spdy_servers| that either support SPDY or not. 46 // |spdy_servers| that either support SPDY or not.
49 void SetSpdyServers(std::vector<std::string>* spdy_servers, 47 void SetSpdyServers(std::vector<std::string>* spdy_servers,
50 bool support_spdy); 48 bool support_spdy);
51 49
52 void SetAlternativeServiceServers( 50 void SetAlternativeServiceServers(
53 AlternativeServiceMap* alternate_protocol_servers); 51 AlternativeServiceMap* alternate_protocol_servers);
54 52
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const ServerNetworkStatsMap& server_network_stats_map() const override; 113 const ServerNetworkStatsMap& server_network_stats_map() const override;
116 bool SetQuicServerInfo(const QuicServerId& server_id, 114 bool SetQuicServerInfo(const QuicServerId& server_id,
117 const std::string& server_info) override; 115 const std::string& server_info) override;
118 const std::string* GetQuicServerInfo(const QuicServerId& server_id) override; 116 const std::string* GetQuicServerInfo(const QuicServerId& server_id) override;
119 const QuicServerInfoMap& quic_server_info_map() const override; 117 const QuicServerInfoMap& quic_server_info_map() const override;
120 size_t max_server_configs_stored_in_properties() const override; 118 size_t max_server_configs_stored_in_properties() const override;
121 void SetMaxServerConfigsStoredInProperties( 119 void SetMaxServerConfigsStoredInProperties(
122 size_t max_server_configs_stored_in_properties) override; 120 size_t max_server_configs_stored_in_properties) override;
123 bool IsInitialized() const override; 121 bool IsInitialized() const override;
124 122
123 // HttpBrokenAlternativeServicesManager::Delegate method
124 void OnExpireBrokenAlternativeService(
125 const AlternativeService& expired_alternative_service) override;
126
125 private: 127 private:
126 friend class HttpServerPropertiesImplPeer; 128 friend class HttpServerPropertiesImplPeer;
127 129
128 // |spdy_servers_map_| has flattened representation of servers 130 // |spdy_servers_map_| has flattened representation of servers
129 // (scheme, host, port) that either support or not support SPDY protocol. 131 // (scheme, host, port) that either support or not support SPDY protocol.
130 typedef base::MRUCache<std::string, bool> SpdyServersMap; 132 typedef base::MRUCache<std::string, bool> SpdyServersMap;
131 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap; 133 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap;
132 typedef std::vector<std::string> CanonicalSufficList; 134 typedef std::vector<std::string> CanonicalSufficList;
133 typedef std::set<HostPortPair> Http11ServerHostPortSet; 135 typedef std::set<HostPortPair> Http11ServerHostPortSet;
134 136
135 // Linked hash map from AlternativeService to expiration time. This container
136 // is a queue with O(1) enqueue and dequeue, and a hash_map with O(1) lookup
137 // at the same time.
138 typedef linked_hash_map<AlternativeService,
139 base::TimeTicks,
140 AlternativeServiceHash>
141 BrokenAlternativeServices;
142
143 // Return the iterator for |server|, or for its canonical host, or end. 137 // Return the iterator for |server|, or for its canonical host, or end.
144 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator( 138 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator(
145 const url::SchemeHostPort& server); 139 const url::SchemeHostPort& server);
146 140
147 // Return the canonical host for |server|, or end if none exists. 141 // Return the canonical host for |server|, or end if none exists.
148 CanonicalHostMap::const_iterator GetCanonicalHost( 142 CanonicalHostMap::const_iterator GetCanonicalHost(
149 const url::SchemeHostPort& server) const; 143 const url::SchemeHostPort& server) const;
150 144
151 // Remove the cononical host for |server|. 145 // Remove the cononical host for |server|.
152 void RemoveCanonicalHost(const url::SchemeHostPort& server); 146 void RemoveCanonicalHost(const url::SchemeHostPort& server);
153 void ExpireBrokenAlternateProtocolMappings(); 147
154 void ScheduleBrokenAlternateProtocolMappingsExpiration(); 148 HttpBrokenAlternativeServicesManager broken_alternative_services_;
155 149
156 SpdyServersMap spdy_servers_map_; 150 SpdyServersMap spdy_servers_map_;
157 Http11ServerHostPortSet http11_servers_; 151 Http11ServerHostPortSet http11_servers_;
158 152
159 AlternativeServiceMap alternative_service_map_; 153 AlternativeServiceMap alternative_service_map_;
160 BrokenAlternativeServices broken_alternative_services_;
161 // Class invariant: Every alternative service in broken_alternative_services_
162 // must also be in recently_broken_alternative_services_.
163 RecentlyBrokenAlternativeServices recently_broken_alternative_services_;
164 154
165 IPAddress last_quic_address_; 155 IPAddress last_quic_address_;
166 ServerNetworkStatsMap server_network_stats_map_; 156 ServerNetworkStatsMap server_network_stats_map_;
167 // Contains a map of servers which could share the same alternate protocol. 157 // Contains a map of servers which could share the same alternate protocol.
168 // Map from a Canonical scheme/host/port (host is some postfix of host names) 158 // Map from a Canonical scheme/host/port (host is some postfix of host names)
169 // to an actual origin, which has a plausible alternate protocol mapping. 159 // to an actual origin, which has a plausible alternate protocol mapping.
170 CanonicalHostMap canonical_host_to_origin_map_; 160 CanonicalHostMap canonical_host_to_origin_map_;
171 // Contains list of suffixes (for exmaple ".c.youtube.com", 161 // Contains list of suffixes (for exmaple ".c.youtube.com",
172 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. 162 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames.
173 CanonicalSufficList canonical_suffixes_; 163 CanonicalSufficList canonical_suffixes_;
174 164
175 QuicServerInfoMap quic_server_info_map_; 165 QuicServerInfoMap quic_server_info_map_;
176 size_t max_server_configs_stored_in_properties_; 166 size_t max_server_configs_stored_in_properties_;
177 167
178 base::WeakPtrFactory<HttpServerPropertiesImpl> weak_ptr_factory_;
179
180 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); 168 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl);
181 }; 169 };
182 170
183 } // namespace net 171 } // namespace net
184 172
185 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ 173 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698