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

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: Inlined all uses of BROKEN_ALT_SVC_EXPIRATION_DELAY. Unrolled loops to reduce logic in BrokenAltern… Created 3 years, 6 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/time/default_tick_clock.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "net/base/host_port_pair.h" 22 #include "net/base/host_port_pair.h"
22 #include "net/base/ip_address.h" 23 #include "net/base/ip_address.h"
23 #include "net/base/linked_hash_map.h" 24 #include "net/base/linked_hash_map.h"
24 #include "net/base/net_export.h" 25 #include "net/base/net_export.h"
26 #include "net/http/broken_alternative_services.h"
25 #include "net/http/http_server_properties.h" 27 #include "net/http/http_server_properties.h"
26 28
27 namespace base { 29 namespace base {
28 class ListValue; 30 class ListValue;
29 } 31 }
30 32
31 namespace net { 33 namespace net {
32 34
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. 35 // The implementation for setting/retrieving the HTTP server properties.
40 class NET_EXPORT HttpServerPropertiesImpl 36 class NET_EXPORT HttpServerPropertiesImpl
41 : public HttpServerProperties, 37 : public HttpServerProperties,
38 public BrokenAlternativeServices::Delegate,
42 NON_EXPORTED_BASE(public base::NonThreadSafe) { 39 NON_EXPORTED_BASE(public base::NonThreadSafe) {
43 public: 40 public:
44 HttpServerPropertiesImpl(); 41 HttpServerPropertiesImpl();
42 explicit HttpServerPropertiesImpl(
43 base::TickClock* broken_alternative_services_clock);
45 ~HttpServerPropertiesImpl() override; 44 ~HttpServerPropertiesImpl() override;
46 45
47 // Sets |spdy_servers_map_| with the servers (host/port) from 46 // Sets |spdy_servers_map_| with the servers (host/port) from
48 // |spdy_servers| that either support SPDY or not. 47 // |spdy_servers| that either support SPDY or not.
49 void SetSpdyServers(std::vector<std::string>* spdy_servers, 48 void SetSpdyServers(std::vector<std::string>* spdy_servers,
50 bool support_spdy); 49 bool support_spdy);
51 50
52 void SetAlternativeServiceServers( 51 void SetAlternativeServiceServers(
53 AlternativeServiceMap* alternate_protocol_servers); 52 AlternativeServiceMap* alternate_protocol_servers);
54 53
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const ServerNetworkStatsMap& server_network_stats_map() const override; 114 const ServerNetworkStatsMap& server_network_stats_map() const override;
116 bool SetQuicServerInfo(const QuicServerId& server_id, 115 bool SetQuicServerInfo(const QuicServerId& server_id,
117 const std::string& server_info) override; 116 const std::string& server_info) override;
118 const std::string* GetQuicServerInfo(const QuicServerId& server_id) override; 117 const std::string* GetQuicServerInfo(const QuicServerId& server_id) override;
119 const QuicServerInfoMap& quic_server_info_map() const override; 118 const QuicServerInfoMap& quic_server_info_map() const override;
120 size_t max_server_configs_stored_in_properties() const override; 119 size_t max_server_configs_stored_in_properties() const override;
121 void SetMaxServerConfigsStoredInProperties( 120 void SetMaxServerConfigsStoredInProperties(
122 size_t max_server_configs_stored_in_properties) override; 121 size_t max_server_configs_stored_in_properties) override;
123 bool IsInitialized() const override; 122 bool IsInitialized() const override;
124 123
124 // BrokenAlternativeServices::Delegate method
Zhongyi Shi 2017/05/31 18:54:15 nit: method.
wangyix1 2017/06/01 20:05:49 Done.
125 void OnExpireBrokenAlternativeService(
126 const AlternativeService& expired_alternative_service) override;
127
125 private: 128 private:
129 // TODO (wangyix): modify HttpServerPropertiesImpl unit tests so this
130 // friendness is no longer required.
126 friend class HttpServerPropertiesImplPeer; 131 friend class HttpServerPropertiesImplPeer;
127 132
128 // |spdy_servers_map_| has flattened representation of servers 133 // |spdy_servers_map_| has flattened representation of servers
129 // (scheme, host, port) that either support or not support SPDY protocol. 134 // (scheme, host, port) that either support or not support SPDY protocol.
130 typedef base::MRUCache<std::string, bool> SpdyServersMap; 135 typedef base::MRUCache<std::string, bool> SpdyServersMap;
131 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap; 136 typedef std::map<url::SchemeHostPort, url::SchemeHostPort> CanonicalHostMap;
132 typedef std::vector<std::string> CanonicalSufficList; 137 typedef std::vector<std::string> CanonicalSufficList;
133 typedef std::set<HostPortPair> Http11ServerHostPortSet; 138 typedef std::set<HostPortPair> Http11ServerHostPortSet;
134 139
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. 140 // Return the iterator for |server|, or for its canonical host, or end.
144 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator( 141 AlternativeServiceMap::const_iterator GetAlternateProtocolIterator(
145 const url::SchemeHostPort& server); 142 const url::SchemeHostPort& server);
146 143
147 // Return the canonical host for |server|, or end if none exists. 144 // Return the canonical host for |server|, or end if none exists.
148 CanonicalHostMap::const_iterator GetCanonicalHost( 145 CanonicalHostMap::const_iterator GetCanonicalHost(
149 const url::SchemeHostPort& server) const; 146 const url::SchemeHostPort& server) const;
150 147
151 // Remove the cononical host for |server|. 148 // Remove the cononical host for |server|.
152 void RemoveCanonicalHost(const url::SchemeHostPort& server); 149 void RemoveCanonicalHost(const url::SchemeHostPort& server);
153 void ExpireBrokenAlternateProtocolMappings(); 150
154 void ScheduleBrokenAlternateProtocolMappingsExpiration(); 151 base::DefaultTickClock broken_alternative_services_clock_;
152 BrokenAlternativeServices broken_alternative_services_;
155 153
156 SpdyServersMap spdy_servers_map_; 154 SpdyServersMap spdy_servers_map_;
157 Http11ServerHostPortSet http11_servers_; 155 Http11ServerHostPortSet http11_servers_;
158 156
159 AlternativeServiceMap alternative_service_map_; 157 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 158
165 IPAddress last_quic_address_; 159 IPAddress last_quic_address_;
166 ServerNetworkStatsMap server_network_stats_map_; 160 ServerNetworkStatsMap server_network_stats_map_;
167 // Contains a map of servers which could share the same alternate protocol. 161 // 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) 162 // 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. 163 // to an actual origin, which has a plausible alternate protocol mapping.
170 CanonicalHostMap canonical_host_to_origin_map_; 164 CanonicalHostMap canonical_host_to_origin_map_;
171 // Contains list of suffixes (for exmaple ".c.youtube.com", 165 // Contains list of suffixes (for exmaple ".c.youtube.com",
172 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames. 166 // ".googlevideo.com", ".googleusercontent.com") of canonical hostnames.
173 CanonicalSufficList canonical_suffixes_; 167 CanonicalSufficList canonical_suffixes_;
174 168
175 QuicServerInfoMap quic_server_info_map_; 169 QuicServerInfoMap quic_server_info_map_;
176 size_t max_server_configs_stored_in_properties_; 170 size_t max_server_configs_stored_in_properties_;
177 171
178 base::WeakPtrFactory<HttpServerPropertiesImpl> weak_ptr_factory_;
179
180 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl); 172 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl);
181 }; 173 };
182 174
183 } // namespace net 175 } // namespace net
184 176
185 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_ 177 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698