Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / net / http / http_server_properties.h
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.
4
5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_
7
8 #include <map>
9 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/net_export.h"
15 #include "net/http/http_pipelined_host_capability.h"
16 #include "net/socket/next_proto.h"
17 #include "net/spdy/spdy_framer.h"  // TODO(willchan): Reconsider this.
18
19 namespace net {
20
21 enum AlternateProtocol {
22   DEPRECATED_NPN_SPDY_2 = 0,
23   ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
24   NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
25   NPN_SPDY_3,
26   NPN_SPDY_3_1,
27   NPN_SPDY_4A2,
28   // We lump in HTTP/2 with the SPDY protocols for now.
29   NPN_HTTP2_DRAFT_04,
30   NPN_SPDY_MAXIMUM_VERSION = NPN_HTTP2_DRAFT_04,
31   QUIC,
32   ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
33   ALTERNATE_PROTOCOL_BROKEN,  // The alternate protocol is known to be broken.
34   UNINITIALIZED_ALTERNATE_PROTOCOL,
35 };
36
37 // Simply returns whether |protocol| is between
38 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
39 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
40 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
41
42 enum AlternateProtocolSize {
43   NUM_VALID_ALTERNATE_PROTOCOLS =
44     ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
45     ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
46 };
47
48 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
49 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
50     const std::string& str);
51 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
52     NextProto next_proto);
53
54 struct NET_EXPORT PortAlternateProtocolPair {
55   bool Equals(const PortAlternateProtocolPair& other) const {
56     return port == other.port && protocol == other.protocol;
57   }
58
59   std::string ToString() const;
60
61   uint16 port;
62   AlternateProtocol protocol;
63 };
64
65 typedef std::map<HostPortPair, PortAlternateProtocolPair> AlternateProtocolMap;
66 typedef std::map<HostPortPair, SettingsMap> SpdySettingsMap;
67 typedef std::map<HostPortPair,
68         HttpPipelinedHostCapability> PipelineCapabilityMap;
69
70 extern const char kAlternateProtocolHeader[];
71
72 // The interface for setting/retrieving the HTTP server properties.
73 // Currently, this class manages servers':
74 // * SPDY support (based on NPN results)
75 // * Alternate-Protocol support
76 // * Spdy Settings (like CWND ID field)
77 class NET_EXPORT HttpServerProperties {
78  public:
79   struct NetworkStats {
80     base::TimeDelta rtt;
81     uint64 bandwidth_estimate;
82   };
83
84   HttpServerProperties() {}
85   virtual ~HttpServerProperties() {}
86
87   // Gets a weak pointer for this object.
88   virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
89
90   // Deletes all data.
91   virtual void Clear() = 0;
92
93   // Returns true if |server| supports SPDY.
94   virtual bool SupportsSpdy(const HostPortPair& server) const = 0;
95
96   // Add |server| into the persistent store. Should only be called from IO
97   // thread.
98   virtual void SetSupportsSpdy(const HostPortPair& server,
99                                bool support_spdy) = 0;
100
101   // Returns true if |server| has an Alternate-Protocol header.
102   virtual bool HasAlternateProtocol(const HostPortPair& server) const = 0;
103
104   // Returns the Alternate-Protocol and port for |server|.
105   // HasAlternateProtocol(server) must be true.
106   virtual PortAlternateProtocolPair GetAlternateProtocol(
107       const HostPortPair& server) const = 0;
108
109   // Sets the Alternate-Protocol for |server|.
110   virtual void SetAlternateProtocol(const HostPortPair& server,
111                                     uint16 alternate_port,
112                                     AlternateProtocol alternate_protocol) = 0;
113
114   // Sets the Alternate-Protocol for |server| to be BROKEN.
115   virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
116
117   // Returns all Alternate-Protocol mappings.
118   virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
119
120   // Gets a reference to the SettingsMap stored for a host.
121   // If no settings are stored, returns an empty SettingsMap.
122   virtual const SettingsMap& GetSpdySettings(
123       const HostPortPair& host_port_pair) const = 0;
124
125   // Saves an individual SPDY setting for a host. Returns true if SPDY setting
126   // is to be persisted.
127   virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
128                               SpdySettingsIds id,
129                               SpdySettingsFlags flags,
130                               uint32 value) = 0;
131
132   // Clears all SPDY settings for a host.
133   virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
134
135   // Clears all SPDY settings for all hosts.
136   virtual void ClearAllSpdySettings() = 0;
137
138   // Returns all persistent SPDY settings.
139   virtual const SpdySettingsMap& spdy_settings_map() const = 0;
140
141   virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
142                                      NetworkStats stats) = 0;
143
144   virtual const NetworkStats* GetServerNetworkStats(
145       const HostPortPair& host_port_pair) const = 0;
146
147   virtual HttpPipelinedHostCapability GetPipelineCapability(
148       const HostPortPair& origin) = 0;
149
150   virtual void SetPipelineCapability(
151       const HostPortPair& origin,
152       HttpPipelinedHostCapability capability) = 0;
153
154   virtual void ClearPipelineCapabilities() = 0;
155
156   virtual PipelineCapabilityMap GetPipelineCapabilityMap() const = 0;
157
158  private:
159   DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
160 };
161
162 }  // namespace net
163
164 #endif  // NET_HTTP_HTTP_SERVER_PROPERTIES_H_