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> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
20 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
21 #include "net/base/privacy_mode.h" | 21 #include "net/base/privacy_mode.h" |
22 #include "net/cookies/cookie_store.h" | |
23 #include "net/proxy/proxy_service.h" | 22 #include "net/proxy/proxy_service.h" |
24 #include "net/ssl/ssl_config_service.h" | 23 #include "net/ssl/ssl_config_service.h" |
25 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 | 27 |
29 class AuthChallengeInfo; | 28 class AuthChallengeInfo; |
30 class CertVerifier; | 29 class CertVerifier; |
31 class ClientSocketFactory; | 30 class ClientSocketFactory; |
32 class ClientSocketHandle; | 31 class ClientSocketHandle; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // cookie. | 107 // cookie. |
109 virtual bool CanSetCookie(SocketStream* request, | 108 virtual bool CanSetCookie(SocketStream* request, |
110 const GURL& url, | 109 const GURL& url, |
111 const std::string& cookie_line, | 110 const std::string& cookie_line, |
112 CookieOptions* options); | 111 CookieOptions* options); |
113 | 112 |
114 protected: | 113 protected: |
115 virtual ~Delegate() {} | 114 virtual ~Delegate() {} |
116 }; | 115 }; |
117 | 116 |
118 SocketStream(const GURL& url, Delegate* delegate, URLRequestContext* context, | 117 SocketStream(const GURL& url, Delegate* delegate); |
119 CookieStore* cookie_store); | |
120 | 118 |
121 // The user data allows the clients to associate data with this job. | 119 // The user data allows the clients to associate data with this job. |
122 // Multiple user data values can be stored under different keys. | 120 // Multiple user data values can be stored under different keys. |
123 // This job will TAKE OWNERSHIP of the given data pointer, and will | 121 // 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. | 122 // delete the object if it is changed or the job is destroyed. |
125 UserData* GetUserData(const void* key) const; | 123 UserData* GetUserData(const void* key) const; |
126 void SetUserData(const void* key, UserData* data); | 124 void SetUserData(const void* key, UserData* data); |
127 | 125 |
128 const GURL& url() const { return url_; } | 126 const GURL& url() const { return url_; } |
129 bool is_secure() const; | 127 bool is_secure() const; |
130 const AddressList& address_list() const { return addresses_; } | 128 const AddressList& address_list() const { return addresses_; } |
131 Delegate* delegate() const { return delegate_; } | 129 Delegate* delegate() const { return delegate_; } |
132 int max_pending_send_allowed() const { return max_pending_send_allowed_; } | 130 int max_pending_send_allowed() const { return max_pending_send_allowed_; } |
133 | 131 |
134 URLRequestContext* context() { return context_; } | 132 URLRequestContext* context() { return context_; } |
| 133 // There're some asynchronous operations and members that are constructed from |
| 134 // |context|. Be careful when you use this for the second time or more. |
| 135 void set_context(URLRequestContext* context); |
135 | 136 |
136 const SSLConfig& server_ssl_config() const { return server_ssl_config_; } | 137 const SSLConfig& server_ssl_config() const { return server_ssl_config_; } |
137 PrivacyMode privacy_mode() const { return privacy_mode_; } | 138 PrivacyMode privacy_mode() const { return privacy_mode_; } |
138 void CheckPrivacyMode(); | 139 void CheckPrivacyMode(); |
139 | 140 |
140 BoundNetLog* net_log() { return &net_log_; } | 141 BoundNetLog* net_log() { return &net_log_; } |
141 | 142 |
142 // Opens the connection on the IO thread. | 143 // Opens the connection on the IO thread. |
143 // Once the connection is established, calls delegate's OnConnected. | 144 // Once the connection is established, calls delegate's OnConnected. |
144 virtual void Connect(); | 145 virtual void Connect(); |
145 | 146 |
146 // Buffers |data| of |len| bytes for send and returns true if successful. | 147 // Buffers |data| of |len| bytes for send and returns true if successful. |
147 // If size of buffered data exceeds |max_pending_send_allowed_|, sends no | 148 // If size of buffered data exceeds |max_pending_send_allowed_|, sends no |
148 // data and returns false. |len| must be positive. | 149 // data and returns false. |len| must be positive. |
149 virtual bool SendData(const char* data, int len); | 150 virtual bool SendData(const char* data, int len); |
150 | 151 |
151 // Requests to close the connection. | 152 // Requests to close the connection. |
152 // Once the connection is closed, calls delegate's OnClose. | 153 // Once the connection is closed, calls delegate's OnClose. |
153 virtual void Close(); | 154 virtual void Close(); |
154 | 155 |
155 // Restarts with authentication info. | 156 // Restarts with authentication info. |
156 // Should be used for response of OnAuthRequired. | 157 // Should be used for response of OnAuthRequired. |
157 virtual void RestartWithAuth(const AuthCredentials& credentials); | 158 virtual void RestartWithAuth(const AuthCredentials& credentials); |
158 | 159 |
159 // Detach delegate. Call before delegate is deleted. | 160 // Detach delegate. Call before delegate is deleted. |
160 // Once delegate is detached, close the socket stream and never call delegate | 161 // Once delegate is detached, close the socket stream and never call delegate |
161 // back. | 162 // back. |
162 virtual void DetachDelegate(); | 163 virtual void DetachDelegate(); |
163 | 164 |
164 // Detach the context. | |
165 virtual void DetachContext(); | |
166 | |
167 const ProxyServer& proxy_server() const; | 165 const ProxyServer& proxy_server() const; |
168 | 166 |
169 // Sets an alternative ClientSocketFactory. Doesn't take ownership of | 167 // Sets an alternative ClientSocketFactory. Doesn't take ownership of |
170 // |factory|. For testing purposes only. | 168 // |factory|. For testing purposes only. |
171 void SetClientSocketFactory(ClientSocketFactory* factory); | 169 void SetClientSocketFactory(ClientSocketFactory* factory); |
172 | 170 |
173 // Cancels the connection because of an error. | 171 // Cancels the connection because of an error. |
174 // |error| is net::Error which represents the error. | 172 // |error| is net::Error which represents the error. |
175 void CancelWithError(int error); | 173 void CancelWithError(int error); |
176 | 174 |
177 // Cancels the connection because of receiving a certificate with an error. | 175 // Cancels the connection because of receiving a certificate with an error. |
178 void CancelWithSSLError(const SSLInfo& ssl_info); | 176 void CancelWithSSLError(const SSLInfo& ssl_info); |
179 | 177 |
180 // Continues to establish the connection in spite of an error. Usually this | 178 // Continues to establish the connection in spite of an error. Usually this |
181 // case happens because users allow certificate with an error by manual | 179 // case happens because users allow certificate with an error by manual |
182 // actions on alert dialog or browser cached such kinds of user actions. | 180 // actions on alert dialog or browser cached such kinds of user actions. |
183 void ContinueDespiteError(); | 181 void ContinueDespiteError(); |
184 | 182 |
185 CookieStore* cookie_store() const; | |
186 | |
187 protected: | 183 protected: |
188 friend class base::RefCountedThreadSafe<SocketStream>; | 184 friend class base::RefCountedThreadSafe<SocketStream>; |
189 virtual ~SocketStream(); | 185 virtual ~SocketStream(); |
190 | 186 |
191 Delegate* delegate_; | 187 Delegate* delegate_; |
192 | 188 |
193 private: | 189 private: |
194 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, IOPending); | 190 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, IOPending); |
195 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, SwitchAfterPending); | 191 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, SwitchAfterPending); |
196 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, | 192 FRIEND_TEST_ALL_PREFIXES(SocketStreamTest, |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 // True iff there's no error and this instance is waiting for completion of | 382 // True iff there's no error and this instance is waiting for completion of |
387 // Write operation by socket_. | 383 // Write operation by socket_. |
388 bool waiting_for_write_completion_; | 384 bool waiting_for_write_completion_; |
389 PendingDataQueue pending_write_bufs_; | 385 PendingDataQueue pending_write_bufs_; |
390 | 386 |
391 bool closing_; | 387 bool closing_; |
392 bool server_closed_; | 388 bool server_closed_; |
393 | 389 |
394 scoped_ptr<SocketStreamMetrics> metrics_; | 390 scoped_ptr<SocketStreamMetrics> metrics_; |
395 | 391 |
396 // Cookie store to use for this socket stream. | |
397 scoped_refptr<CookieStore> cookie_store_; | |
398 | |
399 DISALLOW_COPY_AND_ASSIGN(SocketStream); | 392 DISALLOW_COPY_AND_ASSIGN(SocketStream); |
400 }; | 393 }; |
401 | 394 |
402 } // namespace net | 395 } // namespace net |
403 | 396 |
404 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ | 397 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_H_ |
OLD | NEW |