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