OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 SocketStream(const GURL& url, Delegate* delegate); | 94 SocketStream(const GURL& url, Delegate* delegate); |
95 | 95 |
96 // The user data allows the clients to associate data with this job. | 96 // The user data allows the clients to associate data with this job. |
97 // Multiple user data values can be stored under different keys. | 97 // Multiple user data values can be stored under different keys. |
98 // This job will TAKE OWNERSHIP of the given data pointer, and will | 98 // This job will TAKE OWNERSHIP of the given data pointer, and will |
99 // delete the object if it is changed or the job is destroyed. | 99 // delete the object if it is changed or the job is destroyed. |
100 UserData* GetUserData(const void* key) const; | 100 UserData* GetUserData(const void* key) const; |
101 void SetUserData(const void* key, UserData* data); | 101 void SetUserData(const void* key, UserData* data); |
102 | 102 |
103 const GURL& url() const { return url_; } | 103 const GURL& url() const { return url_; } |
| 104 bool is_secure() const; |
104 const AddressList& address_list() const { return addresses_; } | 105 const AddressList& address_list() const { return addresses_; } |
105 Delegate* delegate() const { return delegate_; } | 106 Delegate* delegate() const { return delegate_; } |
106 int max_pending_send_allowed() const { return max_pending_send_allowed_; } | 107 int max_pending_send_allowed() const { return max_pending_send_allowed_; } |
107 | 108 |
108 URLRequestContext* context() const { return context_.get(); } | 109 URLRequestContext* context() const { return context_.get(); } |
109 void set_context(URLRequestContext* context); | 110 void set_context(URLRequestContext* context); |
110 | 111 |
111 LoadLog* load_log() const { return load_log_; } | 112 LoadLog* load_log() const { return load_log_; } |
112 | 113 |
113 // Opens the connection on the IO thread. | 114 // Opens the connection on the IO thread. |
114 // Once the connection is established, calls delegate's OnConnected. | 115 // Once the connection is established, calls delegate's OnConnected. |
115 void Connect(); | 116 virtual void Connect(); |
116 | 117 |
117 // Requests to send |len| bytes of |data| on the connection. | 118 // Requests to send |len| bytes of |data| on the connection. |
118 // Returns true if |data| is buffered in the job. | 119 // Returns true if |data| is buffered in the job. |
119 // Returns false if size of buffered data would exceeds | 120 // Returns false if size of buffered data would exceeds |
120 // |max_pending_send_allowed_| and |data| is not sent at all. | 121 // |max_pending_send_allowed_| and |data| is not sent at all. |
121 bool SendData(const char* data, int len); | 122 virtual bool SendData(const char* data, int len); |
122 | 123 |
123 // Requests to close the connection. | 124 // Requests to close the connection. |
124 // Once the connection is closed, calls delegate's OnClose. | 125 // Once the connection is closed, calls delegate's OnClose. |
125 void Close(); | 126 virtual void Close(); |
126 | 127 |
127 // Restarts with authentication info. | 128 // Restarts with authentication info. |
128 // Should be used for response of OnAuthRequired. | 129 // Should be used for response of OnAuthRequired. |
129 void RestartWithAuth( | 130 virtual void RestartWithAuth( |
130 const std::wstring& username, | 131 const std::wstring& username, |
131 const std::wstring& password); | 132 const std::wstring& password); |
132 | 133 |
133 // Detach delegate. Call before delegate is deleted. | 134 // Detach delegate. Call before delegate is deleted. |
134 // Once delegate is detached, close the socket stream and never call delegate | 135 // Once delegate is detached, close the socket stream and never call delegate |
135 // back. | 136 // back. |
136 void DetachDelegate(); | 137 virtual void DetachDelegate(); |
137 | 138 |
138 // Sets an alternative HostResolver. For testing purposes only. | 139 // Sets an alternative HostResolver. For testing purposes only. |
139 void SetHostResolver(HostResolver* host_resolver); | 140 void SetHostResolver(HostResolver* host_resolver); |
140 | 141 |
141 // Sets an alternative ClientSocketFactory. Doesn't take ownership of | 142 // Sets an alternative ClientSocketFactory. Doesn't take ownership of |
142 // |factory|. For testing purposes only. | 143 // |factory|. For testing purposes only. |
143 void SetClientSocketFactory(ClientSocketFactory* factory); | 144 void SetClientSocketFactory(ClientSocketFactory* factory); |
144 | 145 |
| 146 protected: |
| 147 friend class base::RefCountedThreadSafe<SocketStream>; |
| 148 ~SocketStream(); |
| 149 |
| 150 Delegate* delegate_; |
| 151 |
145 private: | 152 private: |
146 class RequestHeaders : public IOBuffer { | 153 class RequestHeaders : public IOBuffer { |
147 public: | 154 public: |
148 RequestHeaders() : IOBuffer() {} | 155 RequestHeaders() : IOBuffer() {} |
149 | 156 |
150 void SetDataOffset(size_t offset) { | 157 void SetDataOffset(size_t offset) { |
151 data_ = const_cast<char*>(headers_.data()) + offset; | 158 data_ = const_cast<char*>(headers_.data()) + offset; |
152 } | 159 } |
153 | 160 |
154 std::string headers_; | 161 std::string headers_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 }; | 201 }; |
195 | 202 |
196 enum ProxyMode { | 203 enum ProxyMode { |
197 kDirectConnection, // If using a direct connection | 204 kDirectConnection, // If using a direct connection |
198 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) | 205 kTunnelProxy, // If using a tunnel (CONNECT method as HTTPS) |
199 kSOCKSProxy, // If using a SOCKS proxy | 206 kSOCKSProxy, // If using a SOCKS proxy |
200 }; | 207 }; |
201 | 208 |
202 typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; | 209 typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; |
203 friend class RequestTracker<SocketStream>; | 210 friend class RequestTracker<SocketStream>; |
204 friend class base::RefCountedThreadSafe<SocketStream>; | |
205 ~SocketStream(); | |
206 | 211 |
207 friend class WebSocketThrottleTest; | 212 friend class WebSocketThrottleTest; |
208 | 213 |
209 // Copies the given addrinfo list in |addresses_|. | 214 // Copies the given addrinfo list in |addresses_|. |
210 // Used for WebSocketThrottleTest. | 215 // Used for WebSocketThrottleTest. |
211 void CopyAddrInfo(struct addrinfo* head); | 216 void CopyAddrInfo(struct addrinfo* head); |
212 | 217 |
213 // Finishes the job. | 218 // Finishes the job. |
214 // Calls OnError and OnClose of delegate, and no more | 219 // Calls OnError and OnClose of delegate, and no more |
215 // notifications will be sent to delegate. | 220 // notifications will be sent to delegate. |
(...skipping 25 matching lines...) Expand all Loading... |
241 int DoSSLConnectComplete(int result); | 246 int DoSSLConnectComplete(int result); |
242 int DoReadWrite(int result); | 247 int DoReadWrite(int result); |
243 | 248 |
244 GURL ProxyAuthOrigin() const; | 249 GURL ProxyAuthOrigin() const; |
245 int HandleAuthChallenge(const HttpResponseHeaders* headers); | 250 int HandleAuthChallenge(const HttpResponseHeaders* headers); |
246 void DoAuthRequired(); | 251 void DoAuthRequired(); |
247 void DoRestartWithAuth(); | 252 void DoRestartWithAuth(); |
248 | 253 |
249 int HandleCertificateError(int result); | 254 int HandleCertificateError(int result); |
250 | 255 |
251 bool is_secure() const; | |
252 SSLConfigService* ssl_config_service() const; | 256 SSLConfigService* ssl_config_service() const; |
253 ProxyService* proxy_service() const; | 257 ProxyService* proxy_service() const; |
254 | 258 |
255 void GetInfoForTracker( | 259 void GetInfoForTracker( |
256 RequestTracker<SocketStream>::RecentRequestInfo* info) const; | 260 RequestTracker<SocketStream>::RecentRequestInfo* info) const; |
257 | 261 |
258 scoped_refptr<LoadLog> load_log_; | 262 scoped_refptr<LoadLog> load_log_; |
259 | 263 |
260 GURL url_; | 264 GURL url_; |
261 Delegate* delegate_; | |
262 int max_pending_send_allowed_; | 265 int max_pending_send_allowed_; |
263 scoped_refptr<URLRequestContext> context_; | 266 scoped_refptr<URLRequestContext> context_; |
264 | 267 |
265 typedef std::map<const void*, linked_ptr<UserData> > UserDataMap; | 268 typedef std::map<const void*, linked_ptr<UserData> > UserDataMap; |
266 UserDataMap user_data_; | 269 UserDataMap user_data_; |
267 | 270 |
268 State next_state_; | 271 State next_state_; |
269 scoped_refptr<HostResolver> host_resolver_; | 272 scoped_refptr<HostResolver> host_resolver_; |
270 HttpAuthHandlerFactory* http_auth_handler_factory_; | 273 HttpAuthHandlerFactory* http_auth_handler_factory_; |
271 ClientSocketFactory* factory_; | 274 ClientSocketFactory* factory_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 scoped_ptr<SocketStreamMetrics> metrics_; | 323 scoped_ptr<SocketStreamMetrics> metrics_; |
321 | 324 |
322 RequestTracker<SocketStream>::Node request_tracker_node_; | 325 RequestTracker<SocketStream>::Node request_tracker_node_; |
323 | 326 |
324 DISALLOW_COPY_AND_ASSIGN(SocketStream); | 327 DISALLOW_COPY_AND_ASSIGN(SocketStream); |
325 }; | 328 }; |
326 | 329 |
327 } // namespace net | 330 } // namespace net |
328 | 331 |
329 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 332 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
OLD | NEW |