OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ | 5 #ifndef BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ |
6 #define BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ | 6 #define BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "blimp/net/blimp_net_export.h" | 13 #include "blimp/net/blimp_net_export.h" |
12 #include "blimp/net/blimp_transport.h" | 14 #include "blimp/net/blimp_transport.h" |
13 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
15 | 17 |
16 namespace net { | 18 namespace net { |
| 19 class ClientSocketFactory; |
17 class NetLog; | 20 class NetLog; |
18 class StreamSocket; | 21 class StreamSocket; |
19 } // namespace net | 22 } // namespace net |
20 | 23 |
21 namespace blimp { | 24 namespace blimp { |
22 | 25 |
23 class BlimpConnection; | 26 class BlimpConnection; |
24 | 27 |
25 // BlimpTransport which creates a TCP connection to one of the specified | 28 // BlimpTransport which creates a TCP connection to one of the specified |
26 // |addresses| on each call to Connect(). | 29 // |addresses| on each call to Connect(). |
27 class BLIMP_NET_EXPORT TCPClientTransport : public BlimpTransport { | 30 class BLIMP_NET_EXPORT TCPClientTransport : public BlimpTransport { |
28 public: | 31 public: |
29 TCPClientTransport(const net::AddressList& addresses, net::NetLog* net_log); | 32 TCPClientTransport(const net::IPEndPoint& ip_endpoint, net::NetLog* net_log); |
30 ~TCPClientTransport() override; | 33 ~TCPClientTransport() override; |
31 | 34 |
| 35 void SetClientSocketFactoryForTest(net::ClientSocketFactory* factory); |
| 36 |
32 // BlimpTransport implementation. | 37 // BlimpTransport implementation. |
33 void Connect(const net::CompletionCallback& callback) override; | 38 void Connect(const net::CompletionCallback& callback) override; |
34 scoped_ptr<BlimpConnection> TakeConnection() override; | 39 scoped_ptr<BlimpConnection> TakeConnection() override; |
35 const std::string GetName() const override; | 40 const char* GetName() const override; |
| 41 |
| 42 protected: |
| 43 // Called when the TCP connection completed. |
| 44 virtual void OnTCPConnectComplete(int result); |
| 45 |
| 46 // Called when the connection attempt completed or failed. |
| 47 // Resets |socket_| if |result| indicates a failure (!= net::OK). |
| 48 void OnConnectComplete(int result); |
| 49 |
| 50 // Methods for taking and setting |socket_|. Can be used by subclasses to |
| 51 // swap out a socket for an upgraded one, e.g. adding SSL encryption. |
| 52 scoped_ptr<net::StreamSocket> TakeSocket(); |
| 53 void SetSocket(scoped_ptr<net::StreamSocket> socket); |
| 54 |
| 55 // Gets the socket factory instance. |
| 56 net::ClientSocketFactory* socket_factory() const; |
36 | 57 |
37 private: | 58 private: |
38 void OnTCPConnectComplete(int result); | 59 net::IPEndPoint ip_endpoint_; |
39 | |
40 net::AddressList addresses_; | |
41 net::NetLog* net_log_; | 60 net::NetLog* net_log_; |
| 61 net::CompletionCallback connect_callback_; |
| 62 net::ClientSocketFactory* socket_factory_ = nullptr; |
42 scoped_ptr<net::StreamSocket> socket_; | 63 scoped_ptr<net::StreamSocket> socket_; |
43 net::CompletionCallback connect_callback_; | |
44 | 64 |
45 DISALLOW_COPY_AND_ASSIGN(TCPClientTransport); | 65 DISALLOW_COPY_AND_ASSIGN(TCPClientTransport); |
46 }; | 66 }; |
47 | 67 |
48 } // namespace blimp | 68 } // namespace blimp |
49 | 69 |
50 #endif // BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ | 70 #endif // BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ |
OLD | NEW |