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> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
8 #include "blimp/net/blimp_connection.h" | 11 #include "blimp/net/blimp_connection.h" |
9 #include "blimp/net/blimp_transport.h" | 12 #include "blimp/net/blimp_transport.h" |
| 13 #include "blimp/net/message_port.h" |
10 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
11 | 15 |
12 namespace blimp { | 16 namespace blimp { |
13 | 17 |
14 EngineConnectionManager::EngineConnectionManager( | 18 EngineConnectionManager::EngineConnectionManager( |
15 ConnectionHandler* connection_handler) | 19 ConnectionHandler* connection_handler) |
16 : connection_handler_(connection_handler) { | 20 : connection_handler_(connection_handler) { |
17 DCHECK(connection_handler_); | 21 DCHECK(connection_handler_); |
18 } | 22 } |
19 | 23 |
20 EngineConnectionManager::~EngineConnectionManager() {} | 24 EngineConnectionManager::~EngineConnectionManager() {} |
21 | 25 |
22 void EngineConnectionManager::AddTransport( | 26 void EngineConnectionManager::AddTransport( |
23 std::unique_ptr<BlimpTransport> transport) { | 27 std::unique_ptr<BlimpTransport> transport) { |
24 BlimpTransport* transport_ptr = transport.get(); | 28 BlimpTransport* transport_ptr = transport.get(); |
25 transports_.push_back(std::move(transport)); | 29 transports_.push_back(std::move(transport)); |
26 Connect(transport_ptr); | 30 Connect(transport_ptr); |
27 } | 31 } |
28 | 32 |
29 void EngineConnectionManager::Connect(BlimpTransport* transport) { | 33 void EngineConnectionManager::Connect(BlimpTransport* transport) { |
30 transport->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, | 34 transport->Connect(base::Bind(&EngineConnectionManager::OnConnectResult, |
31 base::Unretained(this), | 35 base::Unretained(this), |
32 base::Unretained(transport))); | 36 base::Unretained(transport))); |
33 } | 37 } |
34 | 38 |
35 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, | 39 void EngineConnectionManager::OnConnectResult(BlimpTransport* transport, |
36 int result) { | 40 int result) { |
37 // Expects engine transport to be reliably, thus |result| is always net::OK. | 41 CHECK_EQ(net::OK, result) << "Transport failure:" << transport->GetName(); |
38 CHECK(result == net::OK) << "Transport failure:" << transport->GetName(); | 42 connection_handler_->HandleConnection( |
39 connection_handler_->HandleConnection(transport->TakeConnection()); | 43 base::MakeUnique<BlimpConnection>(transport->TakeMessagePort())); |
40 Connect(transport); | 44 Connect(transport); |
41 } | 45 } |
42 | 46 |
43 } // namespace blimp | 47 } // namespace blimp |
OLD | NEW |