| Index: blimp/client/core/session/client_network_components.cc
|
| diff --git a/blimp/client/core/session/client_network_components.cc b/blimp/client/core/session/client_network_components.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..32deafd77a4683300d47b04ccc6511bfea1cbbf8
|
| --- /dev/null
|
| +++ b/blimp/client/core/session/client_network_components.cc
|
| @@ -0,0 +1,91 @@
|
| +// Copyright 2016 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/client/core/session/client_network_components.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "blimp/net/ssl_client_transport.h"
|
| +#include "net/base/net_errors.h"
|
| +
|
| +namespace blimp {
|
| +namespace client {
|
| +
|
| +ClientNetworkComponents::ClientNetworkComponents(
|
| + std::unique_ptr<NetworkEventObserver> network_observer,
|
| + std::unique_ptr<BlimpConnectionStatistics> statistics)
|
| + : connection_handler_(),
|
| + network_observer_(std::move(network_observer)),
|
| + connection_statistics_(std::move(statistics)) {
|
| + DCHECK(connection_statistics_);
|
| +}
|
| +
|
| +ClientNetworkComponents::~ClientNetworkComponents() {
|
| + DCHECK(io_thread_checker_.CalledOnValidThread());
|
| +}
|
| +
|
| +void ClientNetworkComponents::Initialize() {
|
| + io_thread_checker_.DetachFromThread();
|
| + DCHECK(!connection_manager_);
|
| + connection_manager_ = base::MakeUnique<ClientConnectionManager>(this);
|
| +}
|
| +
|
| +void ClientNetworkComponents::ConnectWithAssignment(
|
| + const Assignment& assignment) {
|
| + DCHECK(io_thread_checker_.CalledOnValidThread());
|
| + DCHECK(connection_manager_);
|
| +
|
| + connection_manager_->set_client_token(assignment.client_token);
|
| + const char* transport_type = "UNKNOWN";
|
| + switch (assignment.transport_protocol) {
|
| + case Assignment::SSL:
|
| + DCHECK(assignment.cert);
|
| + connection_manager_->AddTransport(base::MakeUnique<SSLClientTransport>(
|
| + assignment.engine_endpoint, std::move(assignment.cert),
|
| + connection_statistics_.get(), nullptr));
|
| + transport_type = "SSL";
|
| + break;
|
| + case Assignment::TCP:
|
| + connection_manager_->AddTransport(base::MakeUnique<TCPClientTransport>(
|
| + assignment.engine_endpoint, connection_statistics_.get(), nullptr));
|
| + transport_type = "TCP";
|
| + break;
|
| + case Assignment::UNKNOWN:
|
| + LOG(FATAL) << "Unknown transport type.";
|
| + break;
|
| + }
|
| +
|
| + VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " ("
|
| + << transport_type << ")";
|
| +
|
| + connection_manager_->Connect();
|
| +}
|
| +
|
| +BrowserConnectionHandler*
|
| +ClientNetworkComponents::GetBrowserConnectionHandler() {
|
| + DCHECK(io_thread_checker_.CalledOnValidThread());
|
| + return &connection_handler_;
|
| +}
|
| +
|
| +void ClientNetworkComponents::HandleConnection(
|
| + std::unique_ptr<BlimpConnection> connection) {
|
| + DCHECK(io_thread_checker_.CalledOnValidThread());
|
| + VLOG(1) << "Connection established.";
|
| + connection->AddConnectionErrorObserver(this);
|
| + connection_handler_.HandleConnection(std::move(connection));
|
| + network_observer_->OnConnected();
|
| +}
|
| +
|
| +void ClientNetworkComponents::OnConnectionError(int result) {
|
| + DCHECK(io_thread_checker_.CalledOnValidThread());
|
| + if (result >= 0) {
|
| + VLOG(1) << "Disconnected with reason: " << result;
|
| + } else {
|
| + VLOG(1) << "Connection error: " << net::ErrorToString(result);
|
| + }
|
| + network_observer_->OnDisconnected(result);
|
| +}
|
| +
|
| +} // namespace client
|
| +} // namespace blimp
|
|
|