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