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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "blimp/net/message_port.h" | 14 #include "blimp/net/message_port.h" |
15 #include "blimp/net/stream_socket_connection.h" | 15 #include "blimp/net/tcp_connection.h" |
16 #include "net/log/net_log_source.h" | 16 #include "net/log/net_log_source.h" |
17 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
18 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
19 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
20 | 20 |
21 namespace blimp { | 21 namespace blimp { |
22 | 22 |
23 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, | 23 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, |
24 net::NetLog* net_log) | 24 net::NetLog* net_log) |
25 : ip_endpoint_(ip_endpoint), | 25 : ip_endpoint_(ip_endpoint), |
(...skipping 25 matching lines...) Expand all Loading... |
51 | 51 |
52 OnTCPConnectComplete(result); | 52 OnTCPConnectComplete(result); |
53 } | 53 } |
54 | 54 |
55 std::unique_ptr<MessagePort> TCPClientTransport::TakeMessagePort() { | 55 std::unique_ptr<MessagePort> TCPClientTransport::TakeMessagePort() { |
56 DCHECK(connect_callback_.is_null()); | 56 DCHECK(connect_callback_.is_null()); |
57 DCHECK(socket_); | 57 DCHECK(socket_); |
58 return MessagePort::CreateForStreamSocketWithCompression(std::move(socket_)); | 58 return MessagePort::CreateForStreamSocketWithCompression(std::move(socket_)); |
59 } | 59 } |
60 | 60 |
61 const char* TCPClientTransport::GetName() const { | 61 std::unique_ptr<BlimpConnection> TCPClientTransport::MakeConnection() { |
62 return "TCP"; | 62 return base::MakeUnique<TCPConnection>(TakeMessagePort()); |
63 } | 63 } |
64 | 64 |
| 65 const char* TCPClientTransport::GetName() const { return "TCP"; } |
| 66 |
65 void TCPClientTransport::OnTCPConnectComplete(int result) { | 67 void TCPClientTransport::OnTCPConnectComplete(int result) { |
66 DCHECK_NE(net::ERR_IO_PENDING, result); | 68 DCHECK_NE(net::ERR_IO_PENDING, result); |
67 OnConnectComplete(result); | 69 OnConnectComplete(result); |
68 } | 70 } |
69 | 71 |
70 void TCPClientTransport::OnConnectComplete(int result) { | 72 void TCPClientTransport::OnConnectComplete(int result) { |
71 if (result != net::OK) { | 73 if (result != net::OK) { |
72 socket_ = nullptr; | 74 socket_ = nullptr; |
73 } | 75 } |
74 base::ResetAndReturn(&connect_callback_).Run(result); | 76 base::ResetAndReturn(&connect_callback_).Run(result); |
75 } | 77 } |
76 | 78 |
77 std::unique_ptr<net::StreamSocket> TCPClientTransport::TakeSocket() { | 79 std::unique_ptr<net::StreamSocket> TCPClientTransport::TakeSocket() { |
78 return std::move(socket_); | 80 return std::move(socket_); |
79 } | 81 } |
80 | 82 |
81 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { | 83 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { |
82 DCHECK(socket); | 84 DCHECK(socket); |
83 socket_ = std::move(socket); | 85 socket_ = std::move(socket); |
84 } | 86 } |
85 | 87 |
86 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { | 88 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { |
87 return socket_factory_; | 89 return socket_factory_; |
88 } | 90 } |
89 | 91 |
90 } // namespace blimp | 92 } // namespace blimp |
OLD | NEW |