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 | |
10 #include "base/callback.h" | 8 #include "base/callback.h" |
11 #include "base/macros.h" | 9 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
13 #include "blimp/net/blimp_net_export.h" | 11 #include "blimp/net/blimp_net_export.h" |
14 #include "blimp/net/blimp_transport.h" | 12 #include "blimp/net/blimp_transport.h" |
15 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
16 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
17 | 15 |
18 namespace net { | 16 namespace net { |
19 class ClientSocketFactory; | |
20 class NetLog; | 17 class NetLog; |
21 class StreamSocket; | 18 class StreamSocket; |
22 } // namespace net | 19 } // namespace net |
23 | 20 |
24 namespace blimp { | 21 namespace blimp { |
25 | 22 |
26 class BlimpConnection; | 23 class BlimpConnection; |
27 | 24 |
28 // BlimpTransport which creates a TCP connection to one of the specified | 25 // BlimpTransport which creates a TCP connection to one of the specified |
29 // |addresses| on each call to Connect(). | 26 // |addresses| on each call to Connect(). |
30 class BLIMP_NET_EXPORT TCPClientTransport : public BlimpTransport { | 27 class BLIMP_NET_EXPORT TCPClientTransport : public BlimpTransport { |
31 public: | 28 public: |
32 TCPClientTransport(const net::IPEndPoint& ip_endpoint, net::NetLog* net_log); | 29 TCPClientTransport(const net::AddressList& addresses, net::NetLog* net_log); |
33 ~TCPClientTransport() override; | 30 ~TCPClientTransport() override; |
34 | 31 |
35 void SetClientSocketFactoryForTest(net::ClientSocketFactory* factory); | |
36 | |
37 // BlimpTransport implementation. | 32 // BlimpTransport implementation. |
38 void Connect(const net::CompletionCallback& callback) override; | 33 void Connect(const net::CompletionCallback& callback) override; |
39 scoped_ptr<BlimpConnection> TakeConnection() override; | 34 scoped_ptr<BlimpConnection> TakeConnection() override; |
40 const char* GetName() const override; | 35 const std::string 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; | |
57 | 36 |
58 private: | 37 private: |
59 net::IPEndPoint ip_endpoint_; | 38 void OnTCPConnectComplete(int result); |
| 39 |
| 40 net::AddressList addresses_; |
60 net::NetLog* net_log_; | 41 net::NetLog* net_log_; |
| 42 scoped_ptr<net::StreamSocket> socket_; |
61 net::CompletionCallback connect_callback_; | 43 net::CompletionCallback connect_callback_; |
62 net::ClientSocketFactory* socket_factory_ = nullptr; | |
63 scoped_ptr<net::StreamSocket> socket_; | |
64 | 44 |
65 DISALLOW_COPY_AND_ASSIGN(TCPClientTransport); | 45 DISALLOW_COPY_AND_ASSIGN(TCPClientTransport); |
66 }; | 46 }; |
67 | 47 |
68 } // namespace blimp | 48 } // namespace blimp |
69 | 49 |
70 #endif // BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ | 50 #endif // BLIMP_NET_TCP_CLIENT_TRANSPORT_H_ |
OLD | NEW |