OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // This StreamSocket implementation wraps a ClientSocketHandle that is created | |
6 // from the client socket pool after resolving proxies. | |
7 | |
8 #ifndef JINGLE_NOTIFIER_BASE_PROXY_RESOLVING_CLIENT_SOCKET_H_ | |
9 #define JINGLE_NOTIFIER_BASE_PROXY_RESOLVING_CLIENT_SOCKET_H_ | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "net/base/completion_callback.h" | |
16 #include "net/base/host_port_pair.h" | |
17 #include "net/base/net_errors.h" | |
18 #include "net/base/net_log.h" | |
19 #include "net/base/ssl_config_service.h" | |
20 #include "net/proxy/proxy_info.h" | |
21 #include "net/proxy/proxy_service.h" | |
22 #include "net/socket/stream_socket.h" | |
23 | |
24 namespace net { | |
25 class ClientSocketFactory; | |
26 class ClientSocketHandle; | |
27 class HttpNetworkSession; | |
28 class URLRequestContextGetter; | |
29 } // namespace net | |
30 | |
31 // TODO(sanjeevr): Move this to net/ | |
32 namespace notifier { | |
33 | |
34 class ProxyResolvingClientSocket : public net::StreamSocket { | |
35 public: | |
36 // Constructs a new ProxyResolvingClientSocket. |socket_factory| is | |
37 // the ClientSocketFactory that will be used by the underlying | |
38 // HttpNetworkSession. If |socket_factory| is NULL, the default | |
39 // socket factory (net::ClientSocketFactory::GetDefaultFactory()) | |
40 // will be used. |dest_host_port_pair| is the destination for this | |
41 // socket. The hostname must be non-empty and the port must be > 0. | |
42 ProxyResolvingClientSocket( | |
43 net::ClientSocketFactory* socket_factory, | |
44 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | |
45 const net::SSLConfig& ssl_config, | |
46 const net::HostPortPair& dest_host_port_pair); | |
47 virtual ~ProxyResolvingClientSocket(); | |
48 | |
49 // net::StreamSocket implementation. | |
50 virtual int Read(net::IOBuffer* buf, int buf_len, | |
51 const net::CompletionCallback& callback) OVERRIDE; | |
52 virtual int Write(net::IOBuffer* buf, int buf_len, | |
53 const net::CompletionCallback& callback) OVERRIDE; | |
54 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | |
55 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | |
56 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | |
57 virtual void Disconnect() OVERRIDE; | |
58 virtual bool IsConnected() const OVERRIDE; | |
59 virtual bool IsConnectedAndIdle() const OVERRIDE; | |
60 virtual int GetPeerAddress(net::IPEndPoint* address) const OVERRIDE; | |
61 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; | |
62 virtual const net::BoundNetLog& NetLog() const OVERRIDE; | |
63 virtual void SetSubresourceSpeculation() OVERRIDE; | |
64 virtual void SetOmniboxSpeculation() OVERRIDE; | |
65 virtual bool WasEverUsed() const OVERRIDE; | |
66 virtual bool UsingTCPFastOpen() const OVERRIDE; | |
67 virtual int64 NumBytesRead() const OVERRIDE; | |
68 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | |
69 virtual bool WasNpnNegotiated() const OVERRIDE; | |
70 virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE; | |
71 virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE; | |
72 | |
73 private: | |
74 // Proxy resolution and connection functions. | |
75 void ProcessProxyResolveDone(int status); | |
76 void ProcessConnectDone(int status); | |
77 | |
78 void CloseTransportSocket(); | |
79 void RunUserConnectCallback(int status); | |
80 int ReconsiderProxyAfterError(int error); | |
81 void ReportSuccessfulProxyConnection(); | |
82 | |
83 // Callbacks passed to net APIs. | |
84 net::CompletionCallback proxy_resolve_callback_; | |
85 net::CompletionCallback connect_callback_; | |
86 | |
87 scoped_refptr<net::HttpNetworkSession> network_session_; | |
88 | |
89 // The transport socket. | |
90 scoped_ptr<net::ClientSocketHandle> transport_; | |
91 | |
92 const net::SSLConfig ssl_config_; | |
93 net::ProxyService::PacRequest* pac_request_; | |
94 net::ProxyInfo proxy_info_; | |
95 net::HostPortPair dest_host_port_pair_; | |
96 bool tried_direct_connect_fallback_; | |
97 net::BoundNetLog bound_net_log_; | |
98 base::WeakPtrFactory<ProxyResolvingClientSocket> weak_factory_; | |
99 | |
100 // The callback passed to Connect(). | |
101 net::CompletionCallback user_connect_callback_; | |
102 }; | |
103 | |
104 } // namespace notifier | |
105 | |
106 #endif // JINGLE_NOTIFIER_BASE_PROXY_RESOLVING_CLIENT_SOCKET_H_ | |
OLD | NEW |