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

Side by Side Diff: net/spdy/spdy_proxy_client_socket.h

Issue 3391029: Revert 60747 - Add a new class SpdyProxyClientSocket which implements ClientS... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_http_utils.cc ('k') | net/spdy/spdy_proxy_client_socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_
6 #define NET_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_
7 #pragma once
8
9 #include <string>
10 #include <list>
11
12 #include "base/basictypes.h"
13 #include "base/ref_counted.h"
14 #include "net/base/completion_callback.h"
15 #include "net/base/host_port_pair.h"
16 #include "net/base/net_log.h"
17 #include "net/http/http_auth_controller.h"
18 #include "net/http/http_request_headers.h"
19 #include "net/http/http_request_info.h"
20 #include "net/http/http_response_info.h"
21 #include "net/socket/client_socket.h"
22 #include "net/spdy/spdy_protocol.h"
23 #include "net/spdy/spdy_session.h"
24 #include "net/spdy/spdy_stream.h"
25
26
27 class GURL;
28
29 namespace net {
30
31 class AddressList;
32 class ClientSocketHandle;
33 class HttpStream;
34 class IOBuffer;
35 class SpdySession;
36 class SpdyStream;
37
38 class SpdyProxyClientSocket : public ClientSocket, public SpdyStream::Delegate {
39 public:
40 // Create a socket on top of the |spdy_stream| by sending a SYN_STREAM
41 // CONNECT frame for |endpoint|. After the SYN_REPLY is received,
42 // any data read/written to the socket will be transferred in data
43 // frames.
44 SpdyProxyClientSocket(SpdyStream* spdy_stream,
45 const std::string& user_agent,
46 const HostPortPair& endpoint,
47 const GURL& url,
48 const HostPortPair& proxy_server,
49 HttpAuthCache* auth_cache,
50 HttpAuthHandlerFactory* auth_handler_factory);
51
52
53 // On destruction Disconnect() is called.
54 virtual ~SpdyProxyClientSocket();
55
56 const scoped_refptr<HttpAuthController>& auth_controller() {
57 return auth_;
58 }
59
60 const HttpResponseInfo* GetConnectResponseInfo() const {
61 return response_.headers ? &response_ : NULL;
62 }
63
64 // ClientSocket methods:
65
66 virtual int Connect(CompletionCallback* callback);
67 virtual void Disconnect();
68 virtual bool IsConnected() const;
69 virtual bool IsConnectedAndIdle() const;
70 virtual const BoundNetLog& NetLog() const { return net_log_; }
71 virtual void SetSubresourceSpeculation();
72 virtual void SetOmniboxSpeculation();
73 virtual bool WasEverUsed() const;
74
75 // Socket methods:
76
77 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
78 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
79
80 virtual bool SetReceiveBufferSize(int32 size);
81 virtual bool SetSendBufferSize(int32 size);
82
83 virtual int GetPeerAddress(AddressList* address) const;
84
85 // SpdyStream::Delegate methods:
86
87 // Called when SYN frame has been sent.
88 // Returns true if no more data to be sent after SYN frame.
89 virtual bool OnSendHeadersComplete(int status);
90
91 // Called when stream is ready to send data.
92 // Returns network error code. OK when it successfully sent data.
93 virtual int OnSendBody();
94
95 // Called when data has been sent. |status| indicates network error
96 // or number of bytes has been sent.
97 // Returns true if no more data to be sent.
98 virtual bool OnSendBodyComplete(int status);
99
100 // Called when SYN_STREAM or SYN_REPLY received. |status| indicates network
101 // error. Returns network error code.
102 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response,
103 base::Time response_time,
104 int status);
105
106 // Called when data is received.
107 virtual void OnDataReceived(const char* data, int length);
108
109 // Called when data is sent.
110 virtual void OnDataSent(int length);
111
112 // Called when SpdyStream is closed.
113 virtual void OnClose(int status);
114
115 private:
116 enum State {
117 STATE_NONE,
118 STATE_GENERATE_AUTH_TOKEN,
119 STATE_GENERATE_AUTH_TOKEN_COMPLETE,
120 STATE_SEND_REQUEST,
121 STATE_SEND_REQUEST_COMPLETE,
122 STATE_READ_REPLY_COMPLETE,
123 STATE_DONE,
124 };
125
126 void OnIOComplete(int result);
127
128 int DoLoop(int last_io_result);
129 int DoGenerateAuthToken();
130 int DoGenerateAuthTokenComplete(int result);
131 int DoSendRequest();
132 int DoSendRequestComplete(int result);
133 int DoReadReplyComplete(int result);
134
135 // Populates |user_buffer_| with as much read data as possible
136 // and returns the number of bytes read.
137 int PopulateUserReadBuffer();
138
139 CompletionCallbackImpl<SpdyProxyClientSocket> io_callback_;
140 State next_state_;
141
142 // Pointer to the SPDY Stream that this sits on top of.
143 scoped_refptr<SpdyStream> spdy_stream_;
144
145 // Stores the callback to the layer above, called on completing Read() or
146 // Connect().
147 CompletionCallback* read_callback_;
148 // Stores the callback to the layer above, called on completing Write().
149 CompletionCallback* write_callback_;
150
151 // CONNECT request and response.
152 HttpRequestInfo request_;
153 HttpResponseInfo response_;
154
155 // The hostname and port of the endpoint. This is not necessarily the one
156 // specified by the URL, due to Alternate-Protocol or fixed testing ports.
157 const HostPortPair endpoint_;
158 scoped_refptr<HttpAuthController> auth_;
159
160 // We buffer the response body as it arrives asynchronously from the stream.
161 std::list<scoped_refptr<DrainableIOBuffer> > read_buffer_;
162
163 // User provided buffer for the Read() response.
164 scoped_refptr<DrainableIOBuffer> user_buffer_;
165
166 // User specified number of bytes to be written.
167 int write_buffer_len_;
168 // Number of bytes written which have not been confirmed
169 int write_bytes_outstanding_;
170
171 // True if read has ever returned zero for eof.
172 bool eof_has_been_read_;
173 // True if the transport socket has ever sent data.
174 bool was_ever_used_;
175
176 const BoundNetLog net_log_;
177
178 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocket);
179 };
180
181 } // namespace net
182
183 #endif // NET_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_utils.cc ('k') | net/spdy/spdy_proxy_client_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698