| 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/engine_connection_manager.h" | 5 #include "blimp/net/engine_connection_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "blimp/net/blimp_connection.h" | 11 #include "blimp/net/blimp_connection.h" |
| 12 #include "blimp/net/blimp_transport.h" | 12 #include "blimp/net/blimp_transport.h" |
| 13 #include "blimp/net/message_port.h" | 13 #include "blimp/net/message_port.h" |
| 14 #include "blimp/net/grpc_engine_transport.h" |
| 14 #include "blimp/net/tcp_engine_transport.h" | 15 #include "blimp/net/tcp_engine_transport.h" |
| 15 #include "net/base/ip_address.h" | 16 #include "net/base/ip_address.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 | 18 |
| 18 namespace blimp { | 19 namespace blimp { |
| 19 | 20 |
| 20 EngineConnectionManager::EngineConnectionManager( | 21 EngineConnectionManager::EngineConnectionManager( |
| 21 ConnectionHandler* connection_handler, | 22 ConnectionHandler* connection_handler, |
| 22 net::NetLog* net_log) | 23 net::NetLog* net_log) |
| 23 : connection_handler_(connection_handler), net_log_(net_log) { | 24 : connection_handler_(connection_handler), net_log_(net_log) { |
| 24 DCHECK(connection_handler_); | 25 DCHECK(connection_handler_); |
| 25 } | 26 } |
| 26 | 27 |
| 27 EngineConnectionManager::~EngineConnectionManager() {} | 28 EngineConnectionManager::~EngineConnectionManager() {} |
| 28 | 29 |
| 29 void EngineConnectionManager::ConnectTransport( | 30 void EngineConnectionManager::ConnectTransport( |
| 30 net::IPEndPoint* ip_endpoint, | 31 net::IPEndPoint* ip_endpoint, |
| 31 EngineTransportType transport_type) { | 32 EngineTransportType transport_type) { |
| 32 switch (transport_type) { | 33 switch (transport_type) { |
| 33 case EngineTransportType::TCP: { | 34 case EngineTransportType::TCP: { |
| 34 transport_ = base::MakeUnique<TCPEngineTransport>(*ip_endpoint, net_log_); | 35 transport_ = base::MakeUnique<TCPEngineTransport>(*ip_endpoint, net_log_); |
| 35 break; | 36 break; |
| 36 } | 37 } |
| 37 | 38 |
| 38 case EngineTransportType::GRPC: { | 39 case EngineTransportType::GRPC: { |
| 39 NOTIMPLEMENTED(); | 40 transport_ = |
| 40 // TODO(perumaal): Unimplemented as yet. | 41 base::MakeUnique<GrpcEngineTransport>(ip_endpoint->ToString()); |
| 41 // transport_ = | |
| 42 // base::MakeUnique<GrpcEngineTransport>(ip_endpoint.ToString()); | |
| 43 break; | 42 break; |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 | 45 |
| 47 transport_->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, | 46 transport_->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, |
| 48 base::Unretained(this), | 47 base::Unretained(this), |
| 49 base::Unretained(transport_.get()))); | 48 base::Unretained(transport_.get()))); |
| 50 transport_->GetLocalAddress(ip_endpoint); | 49 transport_->GetLocalAddress(ip_endpoint); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, | 52 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, |
| 54 int result) { | 53 int result) { |
| 55 CHECK_EQ(net::OK, result) << "Transport failure:" << transport->GetName(); | 54 CHECK_EQ(net::OK, result) << "Transport failure:" << transport->GetName(); |
| 56 connection_handler_->HandleConnection(transport->MakeConnection()); | 55 connection_handler_->HandleConnection(transport->MakeConnection()); |
| 57 } | 56 } |
| 58 | 57 |
| 59 } // namespace blimp | 58 } // namespace blimp |
| OLD | NEW |