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