By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / net / tools / flip_server / spdy_interface.h
blob6751bf15973afdfdda601159c130a689e7e7a96f
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_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_
6 #define NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "net/spdy/buffered_spdy_framer.h"
14 #include "net/spdy/spdy_protocol.h"
15 #include "net/tools/flip_server/balsa_headers.h"
16 #include "net/tools/flip_server/balsa_visitor_interface.h"
17 #include "net/tools/flip_server/output_ordering.h"
18 #include "net/tools/flip_server/sm_connection.h"
19 #include "net/tools/flip_server/sm_interface.h"
21 namespace net {
23 class FlipAcceptor;
24 class MemoryCache;
26 class SpdySM : public BufferedSpdyFramerVisitorInterface,
27 public SMInterface {
28 public:
29 SpdySM(SMConnection* connection,
30 SMInterface* sm_http_interface,
31 EpollServer* epoll_server,
32 MemoryCache* memory_cache,
33 FlipAcceptor* acceptor);
34 virtual ~SpdySM();
36 virtual void InitSMInterface(SMInterface* sm_http_interface,
37 int32 server_idx) OVERRIDE {}
39 virtual void InitSMConnection(SMConnectionPoolInterface* connection_pool,
40 SMInterface* sm_interface,
41 EpollServer* epoll_server,
42 int fd,
43 std::string server_ip,
44 std::string server_port,
45 std::string remote_ip,
46 bool use_ssl) OVERRIDE;
48 private:
49 virtual void set_is_request() OVERRIDE {}
50 SMInterface* NewConnectionInterface();
51 SMInterface* FindOrMakeNewSMConnectionInterface(std::string server_ip,
52 std::string server_port);
53 int SpdyHandleNewStream(SpdyStreamId stream_id,
54 SpdyPriority priority,
55 const SpdyHeaderBlock& headers,
56 std::string& http_data,
57 bool* is_https_scheme);
59 // BufferedSpdyFramerVisitorInterface:
60 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE {}
61 virtual void OnStreamError(SpdyStreamId stream_id,
62 const std::string& description) OVERRIDE {}
63 // Called after all the header data for SYN_STREAM control frame is received.
64 virtual void OnSynStream(SpdyStreamId stream_id,
65 SpdyStreamId associated_stream_id,
66 SpdyPriority priority,
67 uint8 credential_slot,
68 bool fin,
69 bool unidirectional,
70 const SpdyHeaderBlock& headers) OVERRIDE;
72 // Called after all the header data for SYN_REPLY control frame is received.
73 virtual void OnSynReply(SpdyStreamId stream_id,
74 bool fin,
75 const SpdyHeaderBlock& headers) OVERRIDE;
77 // Called after all the header data for HEADERS control frame is received.
78 virtual void OnHeaders(SpdyStreamId stream_id,
79 bool fin,
80 const SpdyHeaderBlock& headers) OVERRIDE;
82 // Called when data is received.
83 // |stream_id| The stream receiving data.
84 // |data| A buffer containing the data received.
85 // |len| The length of the data buffer.
86 // When the other side has finished sending data on this stream,
87 // this method will be called with a zero-length buffer.
88 virtual void OnStreamFrameData(SpdyStreamId stream_id,
89 const char* data,
90 size_t len,
91 SpdyDataFlags flags) OVERRIDE;
93 // Called when an individual setting within a SETTINGS frame has been parsed
94 // and validated.
95 virtual void OnSetting(SpdySettingsIds id,
96 uint8 flags,
97 uint32 value) OVERRIDE {};
99 // Called when a PING frame has been parsed.
100 virtual void OnPing(uint32 unique_id) OVERRIDE {};
102 // Called when a RST_STREAM frame has been parsed.
103 virtual void OnRstStream(SpdyStreamId stream_id,
104 SpdyStatusCodes status) OVERRIDE;
106 // Called when a GOAWAY frame has been parsed.
107 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id,
108 SpdyGoAwayStatus status) OVERRIDE {};
110 // Called when a WINDOW_UPDATE frame has been parsed.
111 virtual void OnWindowUpdate(SpdyStreamId stream_id,
112 int delta_window_size) OVERRIDE {};
114 // Called after a control frame has been compressed to allow the visitor
115 // to record compression statistics.
116 virtual void OnControlFrameCompressed(
117 const SpdyControlFrame& uncompressed_frame,
118 const SpdyControlFrame& compressed_frame) OVERRIDE {};
120 public:
121 virtual size_t ProcessReadInput(const char* data, size_t len) OVERRIDE;
122 virtual size_t ProcessWriteInput(const char* data, size_t len) OVERRIDE;
123 virtual bool MessageFullyRead() const OVERRIDE;
124 virtual void SetStreamID(uint32 stream_id) OVERRIDE {}
125 virtual bool Error() const OVERRIDE;
126 virtual const char* ErrorAsString() const OVERRIDE;
127 virtual void Reset() OVERRIDE {}
128 virtual void ResetForNewInterface(int32 server_idx) OVERRIDE;
129 virtual void ResetForNewConnection() OVERRIDE;
130 // SMInterface's Cleanup is currently only called by SMConnection after a
131 // protocol message as been fully read. Spdy's SMInterface does not need
132 // to do any cleanup at this time.
133 // TODO(klindsay) This method is probably not being used properly and
134 // some logic review and method renaming is probably in order.
135 virtual void Cleanup() OVERRIDE {}
136 // Send a settings frame
137 virtual int PostAcceptHook() OVERRIDE;
138 virtual void NewStream(uint32 stream_id,
139 uint32 priority,
140 const std::string& filename) OVERRIDE;
141 void AddToOutputOrder(const MemCacheIter& mci);
142 virtual void SendEOF(uint32 stream_id) OVERRIDE;
143 virtual void SendErrorNotFound(uint32 stream_id) OVERRIDE;
144 void SendOKResponse(uint32 stream_id, std::string* output);
145 virtual size_t SendSynStream(uint32 stream_id,
146 const BalsaHeaders& headers) OVERRIDE;
147 virtual size_t SendSynReply(uint32 stream_id,
148 const BalsaHeaders& headers) OVERRIDE;
149 virtual void SendDataFrame(uint32 stream_id, const char* data, int64 len,
150 uint32 flags, bool compress) OVERRIDE;
151 BufferedSpdyFramer* spdy_framer() {
152 return buffered_spdy_framer_;
155 static std::string forward_ip_header() { return forward_ip_header_; }
156 static void set_forward_ip_header(std::string value) {
157 forward_ip_header_ = value;
160 private:
161 void SendEOFImpl(uint32 stream_id);
162 void SendErrorNotFoundImpl(uint32 stream_id);
163 void SendOKResponseImpl(uint32 stream_id, std::string* output);
164 void KillStream(uint32 stream_id);
165 void CopyHeaders(SpdyHeaderBlock& dest, const BalsaHeaders& headers);
166 size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers);
167 size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers);
168 void SendDataFrameImpl(uint32 stream_id, const char* data, int64 len,
169 SpdyDataFlags flags, bool compress);
170 void EnqueueDataFrame(DataFrame* df);
171 virtual void GetOutput() OVERRIDE;
172 private:
173 BufferedSpdyFramer* buffered_spdy_framer_;
174 bool valid_spdy_session_; // True if we have seen valid data on this session.
175 // Use this to fail fast when junk is sent to our
176 // port.
178 SMConnection* connection_;
179 OutputList* client_output_list_;
180 OutputOrdering client_output_ordering_;
181 uint32 next_outgoing_stream_id_;
182 EpollServer* epoll_server_;
183 FlipAcceptor* acceptor_;
184 MemoryCache* memory_cache_;
185 std::vector<SMInterface*> server_interface_list;
186 std::vector<int32> unused_server_interface_list;
187 typedef std::map<uint32, SMInterface*> StreamToSmif;
188 StreamToSmif stream_to_smif_;
189 bool close_on_error_;
191 static std::string forward_ip_header_;
194 } // namespace net
196 #endif // NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_