WebViewGuest: Add missing break statement.
[chromium-blink-merge.git] / net / http / http_server_properties_impl.h
blob389c961f491dc0e868174d8e46deed2bac98dc5a
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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "base/values.h"
17 #include "net/base/host_port_pair.h"
18 #include "net/base/net_export.h"
19 #include "net/http/http_server_properties.h"
21 namespace base {
22 class ListValue;
25 namespace net {
27 // The implementation for setting/retrieving the HTTP server properties.
28 class NET_EXPORT HttpServerPropertiesImpl
29 : public HttpServerProperties,
30 NON_EXPORTED_BASE(public base::NonThreadSafe) {
31 public:
32 HttpServerPropertiesImpl();
33 virtual ~HttpServerPropertiesImpl();
35 // Initializes |spdy_servers_map_| with the servers (host/port) from
36 // |spdy_servers| that either support SPDY or not.
37 void InitializeSpdyServers(std::vector<std::string>* spdy_servers,
38 bool support_spdy);
40 void InitializeAlternateProtocolServers(
41 AlternateProtocolMap* alternate_protocol_servers);
43 void InitializeSpdySettingsServers(SpdySettingsMap* spdy_settings_map);
45 // Get the list of servers (host/port) that support SPDY. The max_size is the
46 // number of MRU servers that support SPDY that are to be returned.
47 void GetSpdyServerList(base::ListValue* spdy_server_list,
48 size_t max_size) const;
50 // Returns flattened string representation of the |host_port_pair|. Used by
51 // unittests.
52 static std::string GetFlattenedSpdyServer(
53 const net::HostPortPair& host_port_pair);
55 // Debugging to simulate presence of an AlternateProtocol.
56 // If we don't have an alternate protocol in the map for any given host/port
57 // pair, force this ProtocolPortPair.
58 static void ForceAlternateProtocol(const PortAlternateProtocolPair& pair);
59 static void DisableForcedAlternateProtocol();
61 // Returns the canonical host suffix for |server|, or std::string() if none
62 // exists.
63 std::string GetCanonicalSuffix(const net::HostPortPair& server);
65 // -----------------------------
66 // HttpServerProperties methods:
67 // -----------------------------
69 // Gets a weak pointer for this object.
70 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() OVERRIDE;
72 // Deletes all data.
73 virtual void Clear() OVERRIDE;
75 // Returns true if |server| supports SPDY.
76 virtual bool SupportsSpdy(const HostPortPair& server) OVERRIDE;
78 // Add |server| into the persistent store.
79 virtual void SetSupportsSpdy(const HostPortPair& server,
80 bool support_spdy) OVERRIDE;
82 // Returns true if |server| has an Alternate-Protocol header.
83 virtual bool HasAlternateProtocol(const HostPortPair& server) OVERRIDE;
85 // Returns the Alternate-Protocol and port for |server|.
86 // HasAlternateProtocol(server) must be true.
87 virtual PortAlternateProtocolPair GetAlternateProtocol(
88 const HostPortPair& server) OVERRIDE;
90 // Sets the Alternate-Protocol for |server|.
91 virtual void SetAlternateProtocol(
92 const HostPortPair& server,
93 uint16 alternate_port,
94 AlternateProtocol alternate_protocol) OVERRIDE;
96 // Sets the Alternate-Protocol for |server| to be BROKEN.
97 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) OVERRIDE;
99 // Returns true if Alternate-Protocol for |server| was recently BROKEN.
100 virtual bool WasAlternateProtocolRecentlyBroken(
101 const HostPortPair& server) OVERRIDE;
103 // Confirms that Alternate-Protocol for |server| is working.
104 virtual void ConfirmAlternateProtocol(const HostPortPair& server) OVERRIDE;
106 // Clears the Alternate-Protocol for |server|.
107 virtual void ClearAlternateProtocol(const HostPortPair& server) OVERRIDE;
109 // Returns all Alternate-Protocol mappings.
110 virtual const AlternateProtocolMap& alternate_protocol_map() const OVERRIDE;
112 virtual void SetAlternateProtocolExperiment(
113 AlternateProtocolExperiment experiment) OVERRIDE;
115 virtual AlternateProtocolExperiment GetAlternateProtocolExperiment()
116 const OVERRIDE;
118 // Gets a reference to the SettingsMap stored for a host.
119 // If no settings are stored, returns an empty SettingsMap.
120 virtual const SettingsMap& GetSpdySettings(
121 const HostPortPair& host_port_pair) OVERRIDE;
123 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
124 // is to be persisted.
125 virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
126 SpdySettingsIds id,
127 SpdySettingsFlags flags,
128 uint32 value) OVERRIDE;
130 // Clears all entries in |spdy_settings_map_| for a host.
131 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) OVERRIDE;
133 // Clears all entries in |spdy_settings_map_|.
134 virtual void ClearAllSpdySettings() OVERRIDE;
136 // Returns all persistent SPDY settings.
137 virtual const SpdySettingsMap& spdy_settings_map() const OVERRIDE;
139 virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
140 NetworkStats stats) OVERRIDE;
142 virtual const NetworkStats* GetServerNetworkStats(
143 const HostPortPair& host_port_pair) const OVERRIDE;
145 private:
146 // |spdy_servers_map_| has flattened representation of servers (host, port)
147 // that either support or not support SPDY protocol.
148 typedef base::MRUCache<std::string, bool> SpdyServerHostPortMap;
149 typedef std::map<HostPortPair, NetworkStats> ServerNetworkStatsMap;
150 typedef std::map<HostPortPair, HostPortPair> CanonicalHostMap;
151 typedef std::vector<std::string> CanonicalSufficList;
152 // List of broken host:ports and the times when they can be expired.
153 struct BrokenAlternateProtocolEntry {
154 HostPortPair server;
155 base::TimeTicks when;
157 typedef std::list<BrokenAlternateProtocolEntry>
158 BrokenAlternateProtocolList;
159 // Map from host:port to the number of times alternate protocol has
160 // been marked broken.
161 typedef std::map<HostPortPair, int> BrokenAlternateProtocolMap;
163 // Return the canonical host for |server|, or end if none exists.
164 CanonicalHostMap::const_iterator GetCanonicalHost(HostPortPair server) const;
166 void ExpireBrokenAlternateProtocolMappings();
167 void ScheduleBrokenAlternateProtocolMappingsExpiration();
169 SpdyServerHostPortMap spdy_servers_map_;
171 AlternateProtocolMap alternate_protocol_map_;
172 BrokenAlternateProtocolList broken_alternate_protocol_list_;
173 BrokenAlternateProtocolMap broken_alternate_protocol_map_;
174 AlternateProtocolExperiment alternate_protocol_experiment_;
176 SpdySettingsMap spdy_settings_map_;
177 ServerNetworkStatsMap server_network_stats_map_;
178 // Contains a map of servers which could share the same alternate protocol.
179 // Map from a Canonical host/port (host is some postfix of host names) to an
180 // actual origin, which has a plausible alternate protocol mapping.
181 CanonicalHostMap canonical_host_to_origin_map_;
182 // Contains list of suffixes (for exmaple ".c.youtube.com",
183 // ".googlevideo.com", ".googleusercontent.com") of canoncial hostnames.
184 CanonicalSufficList canoncial_suffixes_;
186 base::WeakPtrFactory<HttpServerPropertiesImpl> weak_ptr_factory_;
188 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl);
191 } // namespace net
193 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_