| 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/client_connection_manager.h" | 5 #include "blimp/net/client_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/common/create_blimp_message.h" | 11 #include "blimp/common/create_blimp_message.h" |
| 9 #include "blimp/common/proto/blimp_message.pb.h" | 12 #include "blimp/common/proto/blimp_message.pb.h" |
| 10 #include "blimp/common/protocol_version.h" | 13 #include "blimp/common/protocol_version.h" |
| 11 #include "blimp/net/blimp_connection.h" | 14 #include "blimp/net/blimp_connection.h" |
| 12 #include "blimp/net/blimp_message_processor.h" | 15 #include "blimp/net/blimp_message_processor.h" |
| 13 #include "blimp/net/blimp_transport.h" | 16 #include "blimp/net/blimp_transport.h" |
| 14 #include "blimp/net/browser_connection_handler.h" | 17 #include "blimp/net/browser_connection_handler.h" |
| 15 #include "blimp/net/connection_handler.h" | 18 #include "blimp/net/connection_handler.h" |
| 19 #include "blimp/net/message_port.h" |
| 16 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 17 | 21 |
| 18 namespace blimp { | 22 namespace blimp { |
| 19 | 23 |
| 20 ClientConnectionManager::ClientConnectionManager( | 24 ClientConnectionManager::ClientConnectionManager( |
| 21 ConnectionHandler* connection_handler) | 25 ConnectionHandler* connection_handler) |
| 22 : connection_handler_(connection_handler), weak_factory_(this) { | 26 : connection_handler_(connection_handler), weak_factory_(this) { |
| 23 DCHECK(connection_handler_); | 27 DCHECK(connection_handler_); |
| 24 } | 28 } |
| 25 | 29 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 } else { | 51 } else { |
| 48 // TODO(haibinlu): add an error reporting path out for this. | 52 // TODO(haibinlu): add an error reporting path out for this. |
| 49 LOG(WARNING) << "All transports failed to connect"; | 53 LOG(WARNING) << "All transports failed to connect"; |
| 50 } | 54 } |
| 51 } | 55 } |
| 52 | 56 |
| 53 void ClientConnectionManager::OnConnectResult(int transport_index, int result) { | 57 void ClientConnectionManager::OnConnectResult(int transport_index, int result) { |
| 54 DCHECK_NE(result, net::ERR_IO_PENDING); | 58 DCHECK_NE(result, net::ERR_IO_PENDING); |
| 55 const auto& transport = transports_[transport_index]; | 59 const auto& transport = transports_[transport_index]; |
| 56 if (result == net::OK) { | 60 if (result == net::OK) { |
| 57 std::unique_ptr<BlimpConnection> connection = transport->TakeConnection(); | 61 std::unique_ptr<BlimpConnection> connection = |
| 62 base::MakeUnique<BlimpConnection>(transport->TakeMessagePort()); |
| 58 connection->AddConnectionErrorObserver(this); | 63 connection->AddConnectionErrorObserver(this); |
| 59 SendAuthenticationMessage(std::move(connection)); | 64 SendAuthenticationMessage(std::move(connection)); |
| 60 } else { | 65 } else { |
| 61 DVLOG(1) << "Transport " << transport->GetName() | 66 DVLOG(1) << "Transport " << transport->GetName() |
| 62 << " failed to connect:" << net::ErrorToString(result); | 67 << " failed to connect:" << net::ErrorToString(result); |
| 63 Connect(transport_index + 1); | 68 Connect(transport_index + 1); |
| 64 } | 69 } |
| 65 } | 70 } |
| 66 | 71 |
| 67 void ClientConnectionManager::SendAuthenticationMessage( | 72 void ClientConnectionManager::SendAuthenticationMessage( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 86 } | 91 } |
| 87 connection_handler_->HandleConnection(std::move(connection)); | 92 connection_handler_->HandleConnection(std::move(connection)); |
| 88 } | 93 } |
| 89 | 94 |
| 90 void ClientConnectionManager::OnConnectionError(int error) { | 95 void ClientConnectionManager::OnConnectionError(int error) { |
| 91 // TODO(kmarshall): implement reconnection logic. | 96 // TODO(kmarshall): implement reconnection logic. |
| 92 VLOG(0) << "Connection dropped, error=" << error; | 97 VLOG(0) << "Connection dropped, error=" << error; |
| 93 } | 98 } |
| 94 | 99 |
| 95 } // namespace blimp | 100 } // namespace blimp |
| OLD | NEW |