Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / jingle / glue / proxy_resolving_client_socket.h
blobe8f22ceb68713ba60a1fbc39acbaccdaf84ac1cc
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.
8 #ifndef JINGLE_GLUE_PROXY_RESOLVING_CLIENT_SOCKET_H_
9 #define JINGLE_GLUE_PROXY_RESOLVING_CLIENT_SOCKET_H_
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/log/net_log.h"
19 #include "net/proxy/proxy_info.h"
20 #include "net/proxy/proxy_service.h"
21 #include "net/socket/stream_socket.h"
22 #include "net/ssl/ssl_config_service.h"
23 #include "url/gurl.h"
25 namespace net {
26 class ClientSocketFactory;
27 class ClientSocketHandle;
28 class HttpNetworkSession;
29 class URLRequestContextGetter;
30 } // namespace net
32 // TODO(sanjeevr): Move this to net/
33 namespace jingle_glue {
35 class ProxyResolvingClientSocket : public net::StreamSocket {
36 public:
37 // Constructs a new ProxyResolvingClientSocket. |socket_factory| is
38 // the ClientSocketFactory that will be used by the underlying
39 // HttpNetworkSession. If |socket_factory| is NULL, the default
40 // socket factory (net::ClientSocketFactory::GetDefaultFactory())
41 // will be used. |dest_host_port_pair| is the destination for this
42 // socket. The hostname must be non-empty and the port must be > 0.
43 ProxyResolvingClientSocket(
44 net::ClientSocketFactory* socket_factory,
45 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
46 const net::SSLConfig& ssl_config,
47 const net::HostPortPair& dest_host_port_pair);
48 ~ProxyResolvingClientSocket() override;
50 // net::StreamSocket implementation.
51 int Read(net::IOBuffer* buf,
52 int buf_len,
53 const net::CompletionCallback& callback) override;
54 int Write(net::IOBuffer* buf,
55 int buf_len,
56 const net::CompletionCallback& callback) override;
57 int SetReceiveBufferSize(int32 size) override;
58 int SetSendBufferSize(int32 size) override;
59 int Connect(const net::CompletionCallback& callback) override;
60 void Disconnect() override;
61 bool IsConnected() const override;
62 bool IsConnectedAndIdle() const override;
63 int GetPeerAddress(net::IPEndPoint* address) const override;
64 int GetLocalAddress(net::IPEndPoint* address) const override;
65 const net::BoundNetLog& NetLog() const override;
66 void SetSubresourceSpeculation() override;
67 void SetOmniboxSpeculation() override;
68 bool WasEverUsed() const override;
69 bool UsingTCPFastOpen() const override;
70 bool WasNpnNegotiated() const override;
71 net::NextProto GetNegotiatedProtocol() const override;
72 bool GetSSLInfo(net::SSLInfo* ssl_info) override;
73 void GetConnectionAttempts(net::ConnectionAttempts* out) const override;
74 void ClearConnectionAttempts() override {}
75 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override {
78 private:
79 // Proxy resolution and connection functions.
80 void ProcessProxyResolveDone(int status);
81 void ProcessConnectDone(int status);
83 void CloseTransportSocket();
84 void RunUserConnectCallback(int status);
85 int ReconsiderProxyAfterError(int error);
86 void ReportSuccessfulProxyConnection();
88 // Callbacks passed to net APIs.
89 net::CompletionCallback proxy_resolve_callback_;
90 net::CompletionCallback connect_callback_;
92 scoped_refptr<net::HttpNetworkSession> network_session_;
94 // The transport socket.
95 scoped_ptr<net::ClientSocketHandle> transport_;
97 const net::SSLConfig ssl_config_;
98 net::ProxyService::PacRequest* pac_request_;
99 net::ProxyInfo proxy_info_;
100 const net::HostPortPair dest_host_port_pair_;
101 const GURL proxy_url_;
102 bool tried_direct_connect_fallback_;
103 net::BoundNetLog bound_net_log_;
105 // The callback passed to Connect().
106 net::CompletionCallback user_connect_callback_;
108 base::WeakPtrFactory<ProxyResolvingClientSocket> weak_factory_;
110 DISALLOW_COPY_AND_ASSIGN(ProxyResolvingClientSocket);
113 } // namespace jingle_glue
115 #endif // JINGLE_GLUE_PROXY_RESOLVING_CLIENT_SOCKET_H_