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