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_
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/containers/mru_cache.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/threading/non_thread_safe.h"
17 #include "base/values.h"
18 #include "net/base/host_port_pair.h"
19 #include "net/base/net_export.h"
20 #include "net/http/http_pipelined_host_capability.h"
21 #include "net/http/http_server_properties.h"
29 // The implementation for setting/retrieving the HTTP server properties.
30 class NET_EXPORT HttpServerPropertiesImpl
31 : public HttpServerProperties
,
32 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
34 HttpServerPropertiesImpl();
35 virtual ~HttpServerPropertiesImpl();
37 // Initializes |spdy_servers_table_| with the servers (host/port) from
38 // |spdy_servers| that either support SPDY or not.
39 void InitializeSpdyServers(std::vector
<std::string
>* spdy_servers
,
42 void InitializeAlternateProtocolServers(
43 AlternateProtocolMap
* alternate_protocol_servers
);
45 void InitializeSpdySettingsServers(SpdySettingsMap
* spdy_settings_map
);
47 // Initializes |pipeline_capability_map_| with the servers (host/port) from
48 // |pipeline_capability_map| that either support HTTP pipelining or not.
49 void InitializePipelineCapabilities(
50 const PipelineCapabilityMap
* pipeline_capability_map
);
52 // Get the list of servers (host/port) that support SPDY.
53 void GetSpdyServerList(base::ListValue
* spdy_server_list
) const;
55 // Returns flattened string representation of the |host_port_pair|. Used by
57 static std::string
GetFlattenedSpdyServer(
58 const net::HostPortPair
& host_port_pair
);
60 // Debugging to simulate presence of an AlternateProtocol.
61 // If we don't have an alternate protocol in the map for any given host/port
62 // pair, force this ProtocolPortPair.
63 static void ForceAlternateProtocol(const PortAlternateProtocolPair
& pair
);
64 static void DisableForcedAlternateProtocol();
66 // Changes the number of host/port pairs we remember pipelining capability
67 // for. A larger number means we're more likely to be able to pipeline
68 // immediately if a host is known good, but uses more memory. This function
69 // can only be called if |pipeline_capability_map_| is empty.
70 void SetNumPipelinedHostsToRemember(int max_size
);
72 // -----------------------------
73 // HttpServerProperties methods:
74 // -----------------------------
77 virtual void Clear() OVERRIDE
;
79 // Returns true if |server| supports SPDY.
80 virtual bool SupportsSpdy(const HostPortPair
& server
) const OVERRIDE
;
82 // Add |server| into the persistent store.
83 virtual void SetSupportsSpdy(const HostPortPair
& server
,
84 bool support_spdy
) OVERRIDE
;
86 // Returns true if |server| has an Alternate-Protocol header.
87 virtual bool HasAlternateProtocol(const HostPortPair
& server
) const OVERRIDE
;
89 // Returns the Alternate-Protocol and port for |server|.
90 // HasAlternateProtocol(server) must be true.
91 virtual PortAlternateProtocolPair
GetAlternateProtocol(
92 const HostPortPair
& server
) const OVERRIDE
;
94 // Sets the Alternate-Protocol for |server|.
95 virtual void SetAlternateProtocol(
96 const HostPortPair
& server
,
97 uint16 alternate_port
,
98 AlternateProtocol alternate_protocol
) OVERRIDE
;
100 // Sets the Alternate-Protocol for |server| to be BROKEN.
101 virtual void SetBrokenAlternateProtocol(const HostPortPair
& server
) OVERRIDE
;
103 // Returns all Alternate-Protocol mappings.
104 virtual const AlternateProtocolMap
& alternate_protocol_map() const OVERRIDE
;
106 // Gets a reference to the SettingsMap stored for a host.
107 // If no settings are stored, returns an empty SettingsMap.
108 virtual const SettingsMap
& GetSpdySettings(
109 const HostPortPair
& host_port_pair
) const OVERRIDE
;
111 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
112 // is to be persisted.
113 virtual bool SetSpdySetting(const HostPortPair
& host_port_pair
,
115 SpdySettingsFlags flags
,
116 uint32 value
) OVERRIDE
;
118 // Clears all entries in |spdy_settings_map_| for a host.
119 virtual void ClearSpdySettings(const HostPortPair
& host_port_pair
) OVERRIDE
;
121 // Clears all entries in |spdy_settings_map_|.
122 virtual void ClearAllSpdySettings() OVERRIDE
;
124 // Returns all persistent SPDY settings.
125 virtual const SpdySettingsMap
& spdy_settings_map() const OVERRIDE
;
127 virtual HttpPipelinedHostCapability
GetPipelineCapability(
128 const HostPortPair
& origin
) OVERRIDE
;
130 virtual void SetPipelineCapability(
131 const HostPortPair
& origin
,
132 HttpPipelinedHostCapability capability
) OVERRIDE
;
134 virtual void ClearPipelineCapabilities() OVERRIDE
;
136 virtual PipelineCapabilityMap
GetPipelineCapabilityMap() const OVERRIDE
;
139 typedef base::MRUCache
<
140 HostPortPair
, HttpPipelinedHostCapability
> CachedPipelineCapabilityMap
;
141 // |spdy_servers_table_| has flattened representation of servers (host/port
142 // pair) that either support or not support SPDY protocol.
143 typedef base::hash_map
<std::string
, bool> SpdyServerHostPortTable
;
144 SpdyServerHostPortTable spdy_servers_table_
;
146 AlternateProtocolMap alternate_protocol_map_
;
147 SpdySettingsMap spdy_settings_map_
;
148 scoped_ptr
<CachedPipelineCapabilityMap
> pipeline_capability_map_
;
150 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesImpl
);
155 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_IMPL_H_