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

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: 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..c55edd30a3ee0bb6ec2cba91af77110c681d7742
--- /dev/null
+++ b/blimp/client/core/session/client_network_components.cc
@@ -0,0 +1,88 @@
+// 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_(new BrowserConnectionHandler),
+ network_observer_(std::move(network_observer)),
+ connection_statistics_(std::move(statistics)) {
+ DCHECK(connection_statistics_);
+}
+
+ClientNetworkComponents::~ClientNetworkComponents() {}
+
+void ClientNetworkComponents::Initialize() {
+ DCHECK(!connection_manager_);
+ connection_manager_ = base::WrapUnique(new ClientConnectionManager(this));
Kevin M 2016/07/29 18:56:03 base::MakeUnique
nyquist 2016/07/29 21:07:52 Done. Nice! Didn't know about this one.
+}
+
+void ClientNetworkComponents::ConnectWithAssignment(
+ const Assignment& assignment) {
+ 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::WrapUnique(new SSLClientTransport(
+ assignment.engine_endpoint, std::move(assignment.cert),
+ connection_statistics_.get(), nullptr)));
+ transport_type = "SSL";
+ break;
+ case Assignment::TCP:
+ connection_manager_->AddTransport(base::WrapUnique(new 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() {
+ return connection_handler_.get();
+}
+
+void ClientNetworkComponents::DropCurrentConnection() {
+ connection_handler_->DropCurrentConnection();
+}
+
+void ClientNetworkComponents::HandleConnection(
+ std::unique_ptr<BlimpConnection> connection) {
+ VLOG(1) << "Connection established.";
+ connection->AddConnectionErrorObserver(this);
+ network_observer_->OnConnected();
Kevin M 2016/07/29 18:56:03 Observer should be triggered at the end of the fun
nyquist 2016/07/29 21:07:52 Done.
+ connection_handler_->HandleConnection(std::move(connection));
+}
+
+void ClientNetworkComponents::OnConnectionError(int result) {
+ 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

Powered by Google App Engine
This is Rietveld 408576698