summaryrefslogtreecommitdiffstats
path: root/blimp/net/engine_connection_manager.cc
blob: 053508e5ab8d08f379fd2be3b3711e792540b382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "blimp/net/engine_connection_manager.h"

#include "base/logging.h"
#include "blimp/net/blimp_connection.h"
#include "blimp/net/blimp_transport.h"
#include "net/base/net_errors.h"

namespace blimp {

EngineConnectionManager::EngineConnectionManager(
    ConnectionHandler* connection_handler)
    : connection_handler_(connection_handler) {
  DCHECK(connection_handler_);
}

EngineConnectionManager::~EngineConnectionManager() {}

void EngineConnectionManager::AddTransport(
    scoped_ptr<BlimpTransport> transport) {
  BlimpTransport* transport_ptr = transport.get();
  transports_.push_back(std::move(transport));
  Connect(transport_ptr);
}

void EngineConnectionManager::Connect(BlimpTransport* transport) {
  transport->Connect(base::Bind(&EngineConnectionManager::OnConnectResult,
                                base::Unretained(this),
                                base::Unretained(transport)));
}

void EngineConnectionManager::OnConnectResult(BlimpTransport* transport,
                                              int result) {
  // Expects engine transport to be reliably, thus |result| is always net::OK.
  CHECK(result == net::OK) << "Transport failure:" << transport->GetName();
  connection_handler_->HandleConnection(transport->TakeConnection());
  Connect(transport);
}

}  // namespace blimp