OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 5 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
6 #define NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 6 #define NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 virtual void OnClose(SocketStream* socket) = 0; | 72 virtual void OnClose(SocketStream* socket) = 0; |
73 | 73 |
74 // Called when proxy authentication required. | 74 // Called when proxy authentication required. |
75 // The delegate should call RestartWithAuth() if credential for |auth_info| | 75 // The delegate should call RestartWithAuth() if credential for |auth_info| |
76 // is found in password database, or call Close() to close the connection. | 76 // is found in password database, or call Close() to close the connection. |
77 virtual void OnAuthRequired(SocketStream* socket, | 77 virtual void OnAuthRequired(SocketStream* socket, |
78 AuthChallengeInfo* auth_info) { | 78 AuthChallengeInfo* auth_info) { |
79 // By default, no credential is available and close the connection. | 79 // By default, no credential is available and close the connection. |
80 socket->Close(); | 80 socket->Close(); |
81 } | 81 } |
| 82 |
| 83 // Called when an error occured. |
| 84 // This is only for error reporting to the delegate. |
| 85 // |error| is net::Error. |
| 86 virtual void OnError(const SocketStream* socket, int error) {} |
82 }; | 87 }; |
83 | 88 |
84 SocketStream(const GURL& url, Delegate* delegate); | 89 SocketStream(const GURL& url, Delegate* delegate); |
85 | 90 |
86 // The user data allows the clients to associate data with this job. | 91 // The user data allows the clients to associate data with this job. |
87 // Multiple user data values can be stored under different keys. | 92 // Multiple user data values can be stored under different keys. |
88 // This job will TAKE OWNERSHIP of the given data pointer, and will | 93 // This job will TAKE OWNERSHIP of the given data pointer, and will |
89 // delete the object if it is changed or the job is destroyed. | 94 // delete the object if it is changed or the job is destroyed. |
90 UserData* GetUserData(const void* key) const; | 95 UserData* GetUserData(const void* key) const; |
91 void SetUserData(const void* key, UserData* data); | 96 void SetUserData(const void* key, UserData* data); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 STATE_TCP_CONNECT, | 169 STATE_TCP_CONNECT, |
165 STATE_TCP_CONNECT_COMPLETE, | 170 STATE_TCP_CONNECT_COMPLETE, |
166 STATE_WRITE_TUNNEL_HEADERS, | 171 STATE_WRITE_TUNNEL_HEADERS, |
167 STATE_WRITE_TUNNEL_HEADERS_COMPLETE, | 172 STATE_WRITE_TUNNEL_HEADERS_COMPLETE, |
168 STATE_READ_TUNNEL_HEADERS, | 173 STATE_READ_TUNNEL_HEADERS, |
169 STATE_READ_TUNNEL_HEADERS_COMPLETE, | 174 STATE_READ_TUNNEL_HEADERS_COMPLETE, |
170 STATE_SOCKS_CONNECT, | 175 STATE_SOCKS_CONNECT, |
171 STATE_SOCKS_CONNECT_COMPLETE, | 176 STATE_SOCKS_CONNECT_COMPLETE, |
172 STATE_SSL_CONNECT, | 177 STATE_SSL_CONNECT, |
173 STATE_SSL_CONNECT_COMPLETE, | 178 STATE_SSL_CONNECT_COMPLETE, |
174 STATE_READ_WRITE | 179 STATE_READ_WRITE, |
| 180 STATE_AUTH_REQUIRED, |
| 181 STATE_CLOSE, |
175 }; | 182 }; |
176 | 183 |
177 enum ProxyMode { | 184 enum ProxyMode { |
178 kDirectConnection, // If using a direct connection | 185 kDirectConnection, // If using a direct connection |
179 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) | 186 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) |
180 kSOCKSProxy, // If using a SOCKS proxy | 187 kSOCKSProxy, // If using a SOCKS proxy |
181 }; | 188 }; |
182 | 189 |
183 typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; | 190 typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; |
184 friend class base::RefCountedThreadSafe<SocketStream>; | 191 friend class base::RefCountedThreadSafe<SocketStream>; |
185 ~SocketStream(); | 192 ~SocketStream(); |
186 | 193 |
187 // Finish the job. Once finished, calls OnClose of delegate, and no more | 194 // Finishes the job. |
| 195 // Calls OnError and OnClose of delegate, and no more |
188 // notifications will be sent to delegate. | 196 // notifications will be sent to delegate. |
189 void Finish(); | 197 void Finish(int result); |
190 | 198 |
191 void DidEstablishConnection(); | 199 int DidEstablishConnection(); |
192 void DidReceiveData(int result); | 200 void DidReceiveData(int result); |
193 void DidSendData(int result); | 201 void DidSendData(int result); |
194 | 202 |
195 void OnIOCompleted(int result); | 203 void OnIOCompleted(int result); |
196 void OnReadCompleted(int result); | 204 void OnReadCompleted(int result); |
197 void OnWriteCompleted(int result); | 205 void OnWriteCompleted(int result); |
198 | 206 |
199 int DoLoop(int result); | 207 void DoLoop(int result); |
200 | 208 |
201 int DoResolveProxy(); | 209 int DoResolveProxy(); |
202 int DoResolveProxyComplete(int result); | 210 int DoResolveProxyComplete(int result); |
203 int DoResolveHost(); | 211 int DoResolveHost(); |
204 int DoResolveHostComplete(int result); | 212 int DoResolveHostComplete(int result); |
205 int DoTcpConnect(); | 213 int DoTcpConnect(); |
206 int DoTcpConnectComplete(int result); | 214 int DoTcpConnectComplete(int result); |
207 int DoWriteTunnelHeaders(); | 215 int DoWriteTunnelHeaders(); |
208 int DoWriteTunnelHeadersComplete(int result); | 216 int DoWriteTunnelHeadersComplete(int result); |
209 int DoReadTunnelHeaders(); | 217 int DoReadTunnelHeaders(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int write_buf_offset_; | 288 int write_buf_offset_; |
281 int write_buf_size_; | 289 int write_buf_size_; |
282 PendingDataQueue pending_write_bufs_; | 290 PendingDataQueue pending_write_bufs_; |
283 | 291 |
284 DISALLOW_COPY_AND_ASSIGN(SocketStream); | 292 DISALLOW_COPY_AND_ASSIGN(SocketStream); |
285 }; | 293 }; |
286 | 294 |
287 } // namespace net | 295 } // namespace net |
288 | 296 |
289 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 297 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
OLD | NEW |