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/tcp_engine_transport.h" | |
15 #include "net/base/ip_address.h" | |
14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
15 | 17 |
16 namespace blimp { | 18 namespace blimp { |
17 | 19 |
18 EngineConnectionManager::EngineConnectionManager( | 20 EngineConnectionManager::EngineConnectionManager( |
19 ConnectionHandler* connection_handler) | 21 ConnectionHandler* connection_handler, |
20 : connection_handler_(connection_handler) { | 22 net::NetLog* net_log) |
23 : connection_handler_(connection_handler), net_log_(net_log) { | |
21 DCHECK(connection_handler_); | 24 DCHECK(connection_handler_); |
22 } | 25 } |
23 | 26 |
24 EngineConnectionManager::~EngineConnectionManager() {} | 27 EngineConnectionManager::~EngineConnectionManager() {} |
25 | 28 |
26 void EngineConnectionManager::AddTransport( | 29 void EngineConnectionManager::ConnectTransport( |
scf
2016/11/10 21:59:09
Rename to CreateAndConnectTransport?
perumaal
2016/11/11 01:50:55
Good point.
| |
27 std::unique_ptr<BlimpTransport> transport) { | 30 net::IPEndPoint* ip_endpoint, |
28 BlimpTransport* transport_ptr = transport.get(); | 31 EngineTransportType transport_type) { |
29 transports_.push_back(std::move(transport)); | 32 switch (transport_type) { |
30 Connect(transport_ptr); | 33 case EngineTransportType::TCP: { |
31 } | 34 transport_ = base::MakeUnique<TCPEngineTransport>(*ip_endpoint, net_log_); |
35 break; | |
36 } | |
32 | 37 |
33 void EngineConnectionManager::Connect(BlimpTransport* transport) { | 38 case EngineTransportType::GRPC: { |
34 transport->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, | 39 NOTIMPLEMENTED(); |
35 base::Unretained(this), | 40 // TODO(perumaal): Unimplemented as yet. |
36 base::Unretained(transport))); | 41 // transport_ = |
42 // base::MakeUnique<GrpcEngineTransport>(ip_endpoint.ToString()); | |
43 break; | |
44 } | |
45 } | |
46 | |
47 transport_->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, | |
48 base::Unretained(this), | |
49 base::Unretained(transport_.get()))); | |
Wez
2016/11/09 23:25:49
We should fix GetLocalAddress to trigger the Bind(
Wez
2016/11/10 01:25:06
Scratch that; of course we need to kick-off Connec
perumaal
2016/11/10 02:05:05
Yeah, another reason I tied the GetLocalAddress ju
| |
50 transport_->GetLocalAddress(ip_endpoint); | |
37 } | 51 } |
38 | 52 |
39 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, | 53 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, |
40 int result) { | 54 int result) { |
41 CHECK_EQ(net::OK, result) << "Transport failure:" << transport->GetName(); | 55 CHECK_EQ(net::OK, result) << "Transport failure:" << transport->GetName(); |
42 connection_handler_->HandleConnection( | 56 connection_handler_->HandleConnection(transport->MakeConnection()); |
43 base::MakeUnique<BlimpConnection>(transport->TakeMessagePort())); | |
44 Connect(transport); | |
45 } | 57 } |
46 | 58 |
47 } // namespace blimp | 59 } // namespace blimp |
OLD | NEW |