| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // Called when a socket stream has been connected. The socket stream is | 66 // Called when a socket stream has been connected. The socket stream is |
| 67 // allowed to buffer pending send data at most |max_pending_send_allowed| | 67 // allowed to buffer pending send data at most |max_pending_send_allowed| |
| 68 // bytes. A client of the socket stream should keep track of how much | 68 // bytes. A client of the socket stream should keep track of how much |
| 69 // pending send data it has and must not call SendData() if the pending | 69 // pending send data it has and must not call SendData() if the pending |
| 70 // data goes over |max_pending_send_allowed| bytes. | 70 // data goes over |max_pending_send_allowed| bytes. |
| 71 virtual void OnConnected(SocketStream* socket, | 71 virtual void OnConnected(SocketStream* socket, |
| 72 int max_pending_send_allowed) = 0; | 72 int max_pending_send_allowed) = 0; |
| 73 | 73 |
| 74 // Called when |amount_sent| bytes of data are sent. | 74 // Called when |amount_sent| bytes of data are sent. |
| 75 virtual void OnSentData(SocketStream* socket, | 75 virtual void OnSentData(SocketStream* socket, int amount_sent) = 0; |
| 76 int amount_sent) = 0; | |
| 77 | 76 |
| 78 // Called when |len| bytes of |data| are received. | 77 // Called when |len| bytes of |data| are received. |
| 79 virtual void OnReceivedData(SocketStream* socket, | 78 virtual void OnReceivedData(SocketStream* socket, |
| 80 const char* data, int len) = 0; | 79 const char* data, |
| 80 int len) = 0; |
| 81 | 81 |
| 82 // Called when the socket stream has been closed. | 82 // Called when the socket stream has been closed. |
| 83 virtual void OnClose(SocketStream* socket) = 0; | 83 virtual void OnClose(SocketStream* socket) = 0; |
| 84 | 84 |
| 85 // Called when proxy authentication required. | 85 // Called when proxy authentication required. |
| 86 // The delegate should call RestartWithAuth() if credential for |auth_info| | 86 // The delegate should call RestartWithAuth() if credential for |auth_info| |
| 87 // is found in password database, or call Close() to close the connection. | 87 // is found in password database, or call Close() to close the connection. |
| 88 virtual void OnAuthRequired(SocketStream* socket, | 88 virtual void OnAuthRequired(SocketStream* socket, |
| 89 AuthChallengeInfo* auth_info); | 89 AuthChallengeInfo* auth_info); |
| 90 | 90 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 108 // cookie. | 108 // cookie. |
| 109 virtual bool CanSetCookie(SocketStream* request, | 109 virtual bool CanSetCookie(SocketStream* request, |
| 110 const GURL& url, | 110 const GURL& url, |
| 111 const std::string& cookie_line, | 111 const std::string& cookie_line, |
| 112 CookieOptions* options); | 112 CookieOptions* options); |
| 113 | 113 |
| 114 protected: | 114 protected: |
| 115 virtual ~Delegate() {} | 115 virtual ~Delegate() {} |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 SocketStream(const GURL& url, Delegate* delegate, URLRequestContext* context, | 118 SocketStream(const GURL& url, |
| 119 Delegate* delegate, |
| 120 URLRequestContext* context, |
| 119 CookieStore* cookie_store); | 121 CookieStore* cookie_store); |
| 120 | 122 |
| 121 // The user data allows the clients to associate data with this job. | 123 // The user data allows the clients to associate data with this job. |
| 122 // Multiple user data values can be stored under different keys. | 124 // Multiple user data values can be stored under different keys. |
| 123 // This job will TAKE OWNERSHIP of the given data pointer, and will | 125 // This job will TAKE OWNERSHIP of the given data pointer, and will |
| 124 // delete the object if it is changed or the job is destroyed. | 126 // delete the object if it is changed or the job is destroyed. |
| 125 UserData* GetUserData(const void* key) const; | 127 UserData* GetUserData(const void* key) const; |
| 126 void SetUserData(const void* key, UserData* data); | 128 void SetUserData(const void* key, UserData* data); |
| 127 | 129 |
| 128 const GURL& url() const { return url_; } | 130 const GURL& url() const { return url_; } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 194 |
| 193 private: | 195 private: |
| 194 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, IOPending); | 196 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, IOPending); |
| 195 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, SwitchAfterPending); | 197 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, SwitchAfterPending); |
| 196 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, | 198 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, |
| 197 NullContextSocketStreamShouldNotCrash); | 199 NullContextSocketStreamShouldNotCrash); |
| 198 | 200 |
| 199 friend class WebSocketThrottleTest; | 201 friend class WebSocketThrottleTest; |
| 200 | 202 |
| 201 typedef std::map<const void*, linked_ptr<UserData> > UserDataMap; | 203 typedef std::map<const void*, linked_ptr<UserData> > UserDataMap; |
| 202 typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; | 204 typedef std::deque<scoped_refptr<IOBufferWithSize> > PendingDataQueue; |
| 203 | 205 |
| 204 class RequestHeaders : public IOBuffer { | 206 class RequestHeaders : public IOBuffer { |
| 205 public: | 207 public: |
| 206 RequestHeaders() : IOBuffer() {} | 208 RequestHeaders() : IOBuffer() {} |
| 207 | 209 |
| 208 void SetDataOffset(size_t offset) { | 210 void SetDataOffset(size_t offset) { |
| 209 data_ = const_cast<char*>(headers_.data()) + offset; | 211 data_ = const_cast<char*>(headers_.data()) + offset; |
| 210 } | 212 } |
| 211 | 213 |
| 212 std::string headers_; | 214 std::string headers_; |
| 213 | 215 |
| 214 private: | 216 private: |
| 215 virtual ~RequestHeaders(); | 217 virtual ~RequestHeaders(); |
| 216 }; | 218 }; |
| 217 | 219 |
| 218 class ResponseHeaders : public IOBuffer { | 220 class ResponseHeaders : public IOBuffer { |
| 219 public: | 221 public: |
| 220 ResponseHeaders(); | 222 ResponseHeaders(); |
| 221 | 223 |
| 222 void SetDataOffset(size_t offset) { data_ = headers_.get() + offset; } | 224 void SetDataOffset(size_t offset) { data_ = headers_.get() + offset; } |
| 223 char* headers() const { return headers_.get(); } | 225 char* headers() const { return headers_.get(); } |
| 224 void Reset() { headers_.reset(); } | 226 void Reset() { headers_.reset(); } |
| 225 void Realloc(size_t new_size); | 227 void Realloc(size_t new_size); |
| 226 | 228 |
| 227 private: | 229 private: |
| 228 virtual ~ResponseHeaders(); | 230 virtual ~ResponseHeaders(); |
| 229 | 231 |
| 230 scoped_ptr<char, base::FreeDeleter> headers_; | 232 scoped_ptr<char, base::FreeDeleter> headers_; |
| 231 }; | 233 }; |
| 232 | 234 |
| 233 enum State { | 235 enum State { |
| 234 STATE_NONE, | 236 STATE_NONE, |
| 235 STATE_BEFORE_CONNECT, | 237 STATE_BEFORE_CONNECT, |
| 236 STATE_BEFORE_CONNECT_COMPLETE, | 238 STATE_BEFORE_CONNECT_COMPLETE, |
| 237 STATE_RESOLVE_PROXY, | 239 STATE_RESOLVE_PROXY, |
| 238 STATE_RESOLVE_PROXY_COMPLETE, | 240 STATE_RESOLVE_PROXY_COMPLETE, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 258 STATE_SSL_CONNECT_COMPLETE, | 260 STATE_SSL_CONNECT_COMPLETE, |
| 259 STATE_SSL_HANDLE_CERT_ERROR, | 261 STATE_SSL_HANDLE_CERT_ERROR, |
| 260 STATE_SSL_HANDLE_CERT_ERROR_COMPLETE, | 262 STATE_SSL_HANDLE_CERT_ERROR_COMPLETE, |
| 261 STATE_READ_WRITE, | 263 STATE_READ_WRITE, |
| 262 STATE_AUTH_REQUIRED, | 264 STATE_AUTH_REQUIRED, |
| 263 STATE_CLOSE, | 265 STATE_CLOSE, |
| 264 }; | 266 }; |
| 265 | 267 |
| 266 enum ProxyMode { | 268 enum ProxyMode { |
| 267 kDirectConnection, // If using a direct connection | 269 kDirectConnection, // If using a direct connection |
| 268 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) | 270 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) |
| 269 kSOCKSProxy, // If using a SOCKS proxy | 271 kSOCKSProxy, // If using a SOCKS proxy |
| 270 }; | 272 }; |
| 271 | 273 |
| 272 // Use the same number as HttpNetworkTransaction::kMaxHeaderBufSize. | 274 // Use the same number as HttpNetworkTransaction::kMaxHeaderBufSize. |
| 273 enum { kMaxTunnelResponseHeadersSize = 32768 }; // 32 kilobytes. | 275 enum { kMaxTunnelResponseHeadersSize = 32768 }; // 32 kilobytes. |
| 274 | 276 |
| 275 // Used for WebSocketThrottleTest. | 277 // Used for WebSocketThrottleTest. |
| 276 void set_addresses(const AddressList& addresses); | 278 void set_addresses(const AddressList& addresses); |
| 277 | 279 |
| 278 void DoClose(); | 280 void DoClose(); |
| 279 | 281 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 397 |
| 396 // Cookie store to use for this socket stream. | 398 // Cookie store to use for this socket stream. |
| 397 scoped_refptr<CookieStore> cookie_store_; | 399 scoped_refptr<CookieStore> cookie_store_; |
| 398 | 400 |
| 399 DISALLOW_COPY_AND_ASSIGN(SocketStream); | 401 DISALLOW_COPY_AND_ASSIGN(SocketStream); |
| 400 }; | 402 }; |
| 401 | 403 |
| 402 } // namespace net | 404 } // namespace net |
| 403 | 405 |
| 404 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 406 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
| OLD | NEW |