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 | 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/stream_socket.h" | 15 #include "net/socket/stream_socket.h" |
| 15 #include "net/socket/tcp_server_socket.h" | 16 #include "net/socket/tcp_server_socket.h" |
| 16 | 17 |
| 17 namespace blimp { | 18 namespace blimp { |
| 18 | 19 |
| 19 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, | 20 TCPEngineTransport::TCPEngineTransport(const net::IPEndPoint& address, |
| 20 net::NetLog* net_log) | 21 net::NetLog* net_log) |
| 21 : address_(address), net_log_(net_log) {} | 22 : address_(address), net_log_(net_log) {} |
| 22 | 23 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 52 server_socket_.reset(); | 53 server_socket_.reset(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 base::MessageLoop::current()->PostTask(FROM_HERE, | 56 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 56 base::Bind(callback, result)); | 57 base::Bind(callback, result)); |
| 57 } | 58 } |
| 58 | 59 |
| 59 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { | 60 std::unique_ptr<BlimpConnection> TCPEngineTransport::TakeConnection() { |
| 60 DCHECK(connect_callback_.is_null()); | 61 DCHECK(connect_callback_.is_null()); |
| 61 DCHECK(accepted_socket_); | 62 DCHECK(accepted_socket_); |
| 62 return base::WrapUnique( | 63 return base::WrapUnique(new StreamSocketConnection( |
| 63 new StreamSocketConnection(std::move(accepted_socket_))); | 64 std::move(accepted_socket_), new BlimpConnectionStatistics)); |
|
Kevin M
2016/05/24 21:49:01
This leaks the statistics object.
Maybe consider
| |
| 64 } | 65 } |
| 65 | 66 |
| 66 const char* TCPEngineTransport::GetName() const { | 67 const char* TCPEngineTransport::GetName() const { |
| 67 return "TCP"; | 68 return "TCP"; |
| 68 } | 69 } |
| 69 | 70 |
| 70 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { | 71 int TCPEngineTransport::GetLocalAddress(net::IPEndPoint* address) const { |
| 71 DCHECK(server_socket_); | 72 DCHECK(server_socket_); |
| 72 return server_socket_->GetLocalAddress(address); | 73 return server_socket_->GetLocalAddress(address); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void TCPEngineTransport::OnTCPConnectAccepted(int result) { | 76 void TCPEngineTransport::OnTCPConnectAccepted(int result) { |
| 76 DCHECK_NE(net::ERR_IO_PENDING, result); | 77 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 77 DCHECK(accepted_socket_); | 78 DCHECK(accepted_socket_); |
| 78 if (result != net::OK) { | 79 if (result != net::OK) { |
| 79 accepted_socket_.reset(); | 80 accepted_socket_.reset(); |
| 80 } | 81 } |
| 81 base::ResetAndReturn(&connect_callback_).Run(result); | 82 base::ResetAndReturn(&connect_callback_).Run(result); |
| 82 } | 83 } |
| 83 | 84 |
| 84 } // namespace blimp | 85 } // namespace blimp |
| OLD | NEW |