| Index: blimp/net/client_connection_manager.cc
|
| diff --git a/blimp/net/client_connection_manager.cc b/blimp/net/client_connection_manager.cc
|
| index 06266965d6e1e9b5fda8ef9993069ee4bb1caf44..7ffc77a235214f662ee9c7b35069fc7225cbe12b 100644
|
| --- a/blimp/net/client_connection_manager.cc
|
| +++ b/blimp/net/client_connection_manager.cc
|
| @@ -11,6 +11,7 @@
|
| #include "blimp/net/blimp_connection.h"
|
| #include "blimp/net/blimp_message_processor.h"
|
| #include "blimp/net/blimp_transport.h"
|
| +#include "blimp/net/browser_connection_handler.h"
|
| #include "blimp/net/connection_handler.h"
|
| #include "net/base/net_errors.h"
|
|
|
| @@ -18,7 +19,7 @@ namespace blimp {
|
|
|
| ClientConnectionManager::ClientConnectionManager(
|
| ConnectionHandler* connection_handler)
|
| - : connection_handler_(connection_handler) {
|
| + : connection_handler_(connection_handler), weak_factory_(this) {
|
| DCHECK(connection_handler_);
|
| }
|
|
|
| @@ -38,6 +39,7 @@ void ClientConnectionManager::Connect() {
|
| }
|
|
|
| void ClientConnectionManager::Connect(int transport_index) {
|
| + DVLOG(1) << "ClientConnectionManager::Connect(" << transport_index << ")";
|
| if (static_cast<size_t>(transport_index) < transports_.size()) {
|
| transports_[transport_index]->Connect(
|
| base::Bind(&ClientConnectionManager::OnConnectResult,
|
| @@ -53,8 +55,8 @@ void ClientConnectionManager::OnConnectResult(int transport_index, int result) {
|
| const auto& transport = transports_[transport_index];
|
| if (result == net::OK) {
|
| scoped_ptr<BlimpConnection> connection = transport->TakeConnection();
|
| - SendAuthenticationMessage(connection.get());
|
| - connection_handler_->HandleConnection(std::move(connection));
|
| + connection->AddConnectionErrorObserver(this);
|
| + SendAuthenticationMessage(std::move(connection));
|
| } else {
|
| DVLOG(1) << "Transport " << transport->GetName()
|
| << " failed to connect:" << net::ErrorToString(result);
|
| @@ -63,12 +65,32 @@ void ClientConnectionManager::OnConnectResult(int transport_index, int result) {
|
| }
|
|
|
| void ClientConnectionManager::SendAuthenticationMessage(
|
| - BlimpConnection* connection) {
|
| - // TODO(haibinlu): get client token.
|
| - const char* client_token = "";
|
| + scoped_ptr<BlimpConnection> connection) {
|
| + DVLOG(1) << "Sending authentication message.";
|
| connection->GetOutgoingMessageProcessor()->ProcessMessage(
|
| - CreateStartConnectionMessage(client_token, kProtocolVersion),
|
| - net::CompletionCallback());
|
| + CreateStartConnectionMessage(client_token_, kProtocolVersion),
|
| + base::Bind(&ClientConnectionManager::OnAuthenticationMessageSent,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Passed(std::move(connection))));
|
| +}
|
| +
|
| +void ClientConnectionManager::OnAuthenticationMessageSent(
|
| + scoped_ptr<BlimpConnection> connection,
|
| + int result) {
|
| + DVLOG(1) << "AuthenticationMessageSent, result=" << result;
|
| + if (result != net::OK) {
|
| + // If a write error occurred, just throw away |connection|.
|
| + // We don't need to propagate the error code here because the connection
|
| + // will already have done so via the ErrorObserver object.
|
| + return;
|
| + }
|
| + connection_handler_->HandleConnection(std::move(connection));
|
| +}
|
| +
|
| +void ClientConnectionManager::OnConnectionError(int error) {
|
| + // TODO(kmarshall): Replace this with actual reconnection logic.
|
| + VLOG(0) << "Connection dropped, error=" << error;
|
| + Connect();
|
| }
|
|
|
| } // namespace blimp
|
|
|