Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3115)

Unified Diff: blimp/client/core/session/client_network_components.cc

Issue 2187893002: Move more client network code to //blimp/client/core/session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more explanatory comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « blimp/client/core/session/client_network_components.h ('k') | blimp/client/core/session/cross_thread_network_event_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698