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 #include "blimp/net/tcp_client_transport.h" | 5 #include "blimp/net/tcp_client_transport.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "blimp/net/blimp_connection_statistics.h" |
13 #include "blimp/net/stream_socket_connection.h" | 14 #include "blimp/net/stream_socket_connection.h" |
14 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
15 #include "net/socket/stream_socket.h" | 16 #include "net/socket/stream_socket.h" |
16 #include "net/socket/tcp_client_socket.h" | 17 #include "net/socket/tcp_client_socket.h" |
17 | 18 |
18 namespace blimp { | 19 namespace blimp { |
19 | 20 |
20 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, | 21 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, |
| 22 BlimpConnectionStatistics* statistics, |
21 net::NetLog* net_log) | 23 net::NetLog* net_log) |
22 : ip_endpoint_(ip_endpoint), | 24 : ip_endpoint_(ip_endpoint), |
| 25 blimp_connection_statistics_(statistics), |
23 net_log_(net_log), | 26 net_log_(net_log), |
24 socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) {} | 27 socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { |
| 28 DCHECK(blimp_connection_statistics_); |
| 29 } |
25 | 30 |
26 TCPClientTransport::~TCPClientTransport() {} | 31 TCPClientTransport::~TCPClientTransport() {} |
27 | 32 |
28 void TCPClientTransport::SetClientSocketFactoryForTest( | 33 void TCPClientTransport::SetClientSocketFactoryForTest( |
29 net::ClientSocketFactory* factory) { | 34 net::ClientSocketFactory* factory) { |
30 DCHECK(factory); | 35 DCHECK(factory); |
31 socket_factory_ = factory; | 36 socket_factory_ = factory; |
32 } | 37 } |
33 | 38 |
34 void TCPClientTransport::Connect(const net::CompletionCallback& callback) { | 39 void TCPClientTransport::Connect(const net::CompletionCallback& callback) { |
(...skipping 10 matching lines...) Expand all Loading... |
45 if (result == net::ERR_IO_PENDING) { | 50 if (result == net::ERR_IO_PENDING) { |
46 return; | 51 return; |
47 } | 52 } |
48 | 53 |
49 OnTCPConnectComplete(result); | 54 OnTCPConnectComplete(result); |
50 } | 55 } |
51 | 56 |
52 std::unique_ptr<BlimpConnection> TCPClientTransport::TakeConnection() { | 57 std::unique_ptr<BlimpConnection> TCPClientTransport::TakeConnection() { |
53 DCHECK(connect_callback_.is_null()); | 58 DCHECK(connect_callback_.is_null()); |
54 DCHECK(socket_); | 59 DCHECK(socket_); |
55 return base::WrapUnique(new StreamSocketConnection(std::move(socket_))); | 60 return base::WrapUnique(new StreamSocketConnection( |
| 61 std::move(socket_), blimp_connection_statistics_)); |
56 } | 62 } |
57 | 63 |
58 const char* TCPClientTransport::GetName() const { | 64 const char* TCPClientTransport::GetName() const { |
59 return "TCP"; | 65 return "TCP"; |
60 } | 66 } |
61 | 67 |
62 void TCPClientTransport::OnTCPConnectComplete(int result) { | 68 void TCPClientTransport::OnTCPConnectComplete(int result) { |
63 DCHECK_NE(net::ERR_IO_PENDING, result); | 69 DCHECK_NE(net::ERR_IO_PENDING, result); |
64 OnConnectComplete(result); | 70 OnConnectComplete(result); |
65 } | 71 } |
(...skipping 12 matching lines...) Expand all Loading... |
78 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { | 84 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { |
79 DCHECK(socket); | 85 DCHECK(socket); |
80 socket_ = std::move(socket); | 86 socket_ = std::move(socket); |
81 } | 87 } |
82 | 88 |
83 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { | 89 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { |
84 return socket_factory_; | 90 return socket_factory_; |
85 } | 91 } |
86 | 92 |
87 } // namespace blimp | 93 } // namespace blimp |
OLD | NEW |