| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "blimp/common/create_blimp_message.h" |
| 9 #include "blimp/common/proto/blimp_message.pb.h" |
| 10 #include "blimp/common/protocol_version.h" |
| 8 #include "blimp/net/blimp_connection.h" | 11 #include "blimp/net/blimp_connection.h" |
| 12 #include "blimp/net/blimp_message_processor.h" |
| 9 #include "blimp/net/blimp_transport.h" | 13 #include "blimp/net/blimp_transport.h" |
| 10 #include "blimp/net/connection_handler.h" | 14 #include "blimp/net/connection_handler.h" |
| 11 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 12 | 16 |
| 13 namespace blimp { | 17 namespace blimp { |
| 14 | 18 |
| 15 ClientConnectionManager::ClientConnectionManager( | 19 ClientConnectionManager::ClientConnectionManager( |
| 16 ConnectionHandler* connection_handler) | 20 ConnectionHandler* connection_handler) |
| 17 : connection_handler_(connection_handler) { | 21 : connection_handler_(connection_handler) { |
| 18 DCHECK(connection_handler_); | 22 DCHECK(connection_handler_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 } else { | 45 } else { |
| 42 // TODO(haibinlu): add an error reporting path out for this. | 46 // TODO(haibinlu): add an error reporting path out for this. |
| 43 LOG(WARNING) << "All transports failed to connect"; | 47 LOG(WARNING) << "All transports failed to connect"; |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 | 50 |
| 47 void ClientConnectionManager::OnConnectResult(int transport_index, int result) { | 51 void ClientConnectionManager::OnConnectResult(int transport_index, int result) { |
| 48 DCHECK_NE(result, net::ERR_IO_PENDING); | 52 DCHECK_NE(result, net::ERR_IO_PENDING); |
| 49 const auto& transport = transports_[transport_index]; | 53 const auto& transport = transports_[transport_index]; |
| 50 if (result == net::OK) { | 54 if (result == net::OK) { |
| 51 connection_handler_->HandleConnection(transport->TakeConnection()); | 55 scoped_ptr<BlimpConnection> connection = transport->TakeConnection(); |
| 56 SendAuthenticationMessage(connection.get()); |
| 57 connection_handler_->HandleConnection(std::move(connection)); |
| 52 } else { | 58 } else { |
| 53 DVLOG(1) << "Transport " << transport->GetName() | 59 DVLOG(1) << "Transport " << transport->GetName() |
| 54 << " failed to connect:" << net::ErrorToString(result); | 60 << " failed to connect:" << net::ErrorToString(result); |
| 55 Connect(transport_index + 1); | 61 Connect(transport_index + 1); |
| 56 } | 62 } |
| 57 } | 63 } |
| 58 | 64 |
| 65 void ClientConnectionManager::SendAuthenticationMessage( |
| 66 BlimpConnection* connection) { |
| 67 // TODO(haibinlu): get client token. |
| 68 const char* client_token = ""; |
| 69 connection->GetOutgoingMessageProcessor()->ProcessMessage( |
| 70 CreateStartConnectionMessage(client_token, kProtocolVersion), |
| 71 net::CompletionCallback()); |
| 72 } |
| 73 |
| 59 } // namespace blimp | 74 } // namespace blimp |
| OLD | NEW |