Chromium Code Reviews| 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 #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/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "blimp/net/message_port.h" | 15 #include "blimp/net/message_port.h" |
| 16 #include "blimp/net/tcp_connection.h" | |
| 16 #include "net/log/net_log_source.h" | 17 #include "net/log/net_log_source.h" |
| 17 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
| 18 #include "net/socket/tcp_server_socket.h" | 19 #include "net/socket/tcp_server_socket.h" |
| 19 | 20 |
| 20 namespace blimp { | 21 namespace blimp { |
| 21 | 22 |
| 22 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, | 23 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, |
| 23 net::NetLog* net_log) | 24 net::NetLog* net_log) |
| 24 : address_(address), net_log_(net_log) {} | 25 : address_(address), net_log_(net_log) {} |
| 25 | 26 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 base::Bind(callback, result)); | 59 base::Bind(callback, result)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 std::unique_ptr<MessagePort> TCPEngineTransport::TakeMessagePort() { | 62 std::unique_ptr<MessagePort> TCPEngineTransport::TakeMessagePort() { |
| 62 DCHECK(connect_callback_.is_null()); | 63 DCHECK(connect_callback_.is_null()); |
| 63 DCHECK(accepted_socket_); | 64 DCHECK(accepted_socket_); |
| 64 return MessagePort::CreateForStreamSocketWithCompression( | 65 return MessagePort::CreateForStreamSocketWithCompression( |
| 65 std::move(accepted_socket_)); | 66 std::move(accepted_socket_)); |
| 66 } | 67 } |
| 67 | 68 |
| 69 std::unique_ptr<BlimpConnection> TCPEngineTransport::MakeConnection() { | |
|
scf
2016/11/10 21:59:10
rename to CreateConnection ?
perumaal
2016/11/11 01:50:55
We had a discussion around this before. I learnt t
| |
| 70 return base::MakeUnique<TCPConnection>(TakeMessagePort()); | |
| 71 } | |
| 72 | |
| 68 const char* TCPEngineTransport::GetName() const { | 73 const char* TCPEngineTransport::GetName() const { |
| 69 return "TCP"; | 74 return "TCP"; |
| 70 } | 75 } |
| 71 | 76 |
| 72 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { | 77 void TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { |
| 73 DCHECK(server_socket_); | 78 DCHECK(server_socket_); |
| 74 return server_socket_->GetLocalAddress(address); | 79 server_socket_->GetLocalAddress(address); |
| 75 } | 80 } |
| 76 | 81 |
| 77 void TCPEngineTransport::OnTCPConnectAccepted(int result) { | 82 void TCPEngineTransport::OnTCPConnectAccepted(int result) { |
| 78 DCHECK_NE(net::ERR_IO_PENDING, result); | 83 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 79 DCHECK(accepted_socket_); | 84 DCHECK(accepted_socket_); |
| 80 if (result != net::OK) { | 85 if (result != net::OK) { |
| 81 accepted_socket_.reset(); | 86 accepted_socket_.reset(); |
| 82 } | 87 } |
| 83 base::ResetAndReturn(&connect_callback_).Run(result); | 88 base::ResetAndReturn(&connect_callback_).Run(result); |
| 84 } | 89 } |
| 85 | 90 |
| 86 } // namespace blimp | 91 } // namespace blimp |
| OLD | NEW |