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_engine_transport.h" | 5 #include "blimp/net/tcp_engine_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/stream_socket_connection.h" | 13 #include "blimp/net/stream_socket_connection.h" |
14 #include "net/socket/stream_socket.h" | 14 #include "net/socket/stream_socket.h" |
15 #include "net/socket/tcp_server_socket.h" | 15 #include "net/socket/tcp_server_socket.h" |
16 | 16 |
17 namespace blimp { | 17 namespace blimp { |
18 | 18 |
19 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, | 19 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, |
| 20 BlimpConnectionStatistics* statistics, |
20 net::NetLog* net_log) | 21 net::NetLog* net_log) |
21 : address_(address), net_log_(net_log) {} | 22 : address_(address), |
| 23 blimp_connection_statistics_(statistics), |
| 24 net_log_(net_log) { |
| 25 DCHECK(blimp_connection_statistics_); |
| 26 } |
22 | 27 |
23 TCPEngineTransport::~TCPEngineTransport() {} | 28 TCPEngineTransport::~TCPEngineTransport() {} |
24 | 29 |
25 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { | 30 void TCPEngineTransport::Connect(const net::CompletionCallback& callback) { |
26 DCHECK(!accepted_socket_); | 31 DCHECK(!accepted_socket_); |
27 DCHECK(!callback.is_null()); | 32 DCHECK(!callback.is_null()); |
28 | 33 |
29 if (!server_socket_) { | 34 if (!server_socket_) { |
30 server_socket_.reset( | 35 server_socket_.reset( |
31 new net::TCPServerSocket(net_log_, net::NetLog::Source())); | 36 new net::TCPServerSocket(net_log_, net::NetLog::Source())); |
(...skipping 20 matching lines...) Expand all Loading... |
52 server_socket_.reset(); | 57 server_socket_.reset(); |
53 } | 58 } |
54 | 59 |
55 base::MessageLoop::current()->PostTask(FROM_HERE, | 60 base::MessageLoop::current()->PostTask(FROM_HERE, |
56 base::Bind(callback, result)); | 61 base::Bind(callback, result)); |
57 } | 62 } |
58 | 63 |
59 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { | 64 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { |
60 DCHECK(connect_callback_.is_null()); | 65 DCHECK(connect_callback_.is_null()); |
61 DCHECK(accepted_socket_); | 66 DCHECK(accepted_socket_); |
62 return base::WrapUnique( | 67 return base::WrapUnique(new StreamSocketConnection( |
63 new StreamSocketConnection(std::move(accepted_socket_))); | 68 std::move(accepted_socket_), blimp_connection_statistics_)); |
64 } | 69 } |
65 | 70 |
66 const char* TCPEngineTransport::GetName() const { | 71 const char* TCPEngineTransport::GetName() const { |
67 return "TCP"; | 72 return "TCP"; |
68 } | 73 } |
69 | 74 |
70 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { | 75 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { |
71 DCHECK(server_socket_); | 76 DCHECK(server_socket_); |
72 return server_socket_->GetLocalAddress(address); | 77 return server_socket_->GetLocalAddress(address); |
73 } | 78 } |
74 | 79 |
75 void TCPEngineTransport::OnTCPConnectAccepted(int result) { | 80 void TCPEngineTransport::OnTCPConnectAccepted(int result) { |
76 DCHECK_NE(net::ERR_IO_PENDING, result); | 81 DCHECK_NE(net::ERR_IO_PENDING, result); |
77 DCHECK(accepted_socket_); | 82 DCHECK(accepted_socket_); |
78 if (result != net::OK) { | 83 if (result != net::OK) { |
79 accepted_socket_.reset(); | 84 accepted_socket_.reset(); |
80 } | 85 } |
81 base::ResetAndReturn(&connect_callback_).Run(result); | 86 base::ResetAndReturn(&connect_callback_).Run(result); |
82 } | 87 } |
83 | 88 |
84 } // namespace blimp | 89 } // namespace blimp |
OLD | NEW |