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

Unified Diff: blimp/client/session/blimp_client_session.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/session/blimp_client_session.cc
diff --git a/blimp/client/session/blimp_client_session.cc b/blimp/client/session/blimp_client_session.cc
index bc608fc26701adcdbfd42a1aca681d21db049545..5abb8fd3ad3f7d79cb6f7c3b6c66db804dca49e1 100644
--- a/blimp/client/session/blimp_client_session.cc
+++ b/blimp/client/session/blimp_client_session.cc
@@ -6,180 +6,32 @@
#include <vector>
+#include "base/bind.h"
#include "base/command_line.h"
+#include "base/location.h"
+#include "base/logging.h"
#include "base/memory/ptr_util.h"
-#include "base/numerics/safe_conversions.h"
#include "base/sequenced_task_runner.h"
-#include "base/strings/string_number_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "blimp/client/core/blimp_client_switches.h"
+#include "blimp/client/core/session/client_network_components.h"
+#include "blimp/client/core/session/cross_thread_network_event_observer.h"
#include "blimp/client/feature/ime_feature.h"
#include "blimp/client/feature/navigation_feature.h"
#include "blimp/client/feature/render_widget_feature.h"
#include "blimp/client/feature/settings_feature.h"
#include "blimp/client/feature/tab_control_feature.h"
#include "blimp/common/blob_cache/in_memory_blob_cache.h"
-#include "blimp/net/blimp_connection.h"
-#include "blimp/net/blimp_message_processor.h"
#include "blimp/net/blimp_message_thread_pipe.h"
#include "blimp/net/blob_channel/blob_channel_receiver.h"
#include "blimp/net/blob_channel/helium_blob_receiver_delegate.h"
-#include "blimp/net/browser_connection_handler.h"
-#include "blimp/net/client_connection_manager.h"
-#include "blimp/net/common.h"
-#include "blimp/net/connection_handler.h"
-#include "blimp/net/null_blimp_message_processor.h"
-#include "blimp/net/ssl_client_transport.h"
-#include "blimp/net/tcp_client_transport.h"
#include "blimp/net/thread_pipe_manager.h"
-#include "net/base/address_list.h"
-#include "net/base/ip_address.h"
-#include "net/base/ip_endpoint.h"
#include "url/gurl.h"
namespace blimp {
namespace client {
-namespace {
-
-// Posts network events to an observer across the IO/UI thread boundary.
-class CrossThreadNetworkEventObserver : public NetworkEventObserver {
- public:
- CrossThreadNetworkEventObserver(
- const base::WeakPtr<NetworkEventObserver>& target,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner)
- : target_(target), task_runner_(task_runner) {}
-
- ~CrossThreadNetworkEventObserver() override {}
-
- void OnConnected() override {
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&NetworkEventObserver::OnConnected, target_));
- }
-
- void OnDisconnected(int result) override {
- task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&NetworkEventObserver::OnDisconnected, target_, result));
- }
-
- private:
- base::WeakPtr<NetworkEventObserver> target_;
- scoped_refptr<base::SequencedTaskRunner> task_runner_;
-
- DISALLOW_COPY_AND_ASSIGN(CrossThreadNetworkEventObserver);
-};
-
-} // namespace
-
-// This class's functions and destruction are all invoked on the IO thread by
-// the BlimpClientSession.
-class ClientNetworkComponents : public ConnectionHandler,
- public ConnectionErrorObserver {
- public:
- // Can be created on any thread.
- ClientNetworkComponents(
- std::unique_ptr<NetworkEventObserver> observer,
- std::unique_ptr<BlimpConnectionStatistics> blimp_connection_statistics);
- ~ClientNetworkComponents() override;
-
- // Sets up network components.
- void Initialize();
-
- // Starts the connection to the engine using the given |assignment|.
- // It is required to first call Initialize.
- void ConnectWithAssignment(const Assignment& assignment);
-
- BrowserConnectionHandler* GetBrowserConnectionHandler();
-
- void DropCurrentConnection();
-
- private:
- // ConnectionHandler implementation.
- void HandleConnection(std::unique_ptr<BlimpConnection> connection) override;
-
- // ConnectionErrorObserver implementation.
- void OnConnectionError(int error) override;
-
- std::unique_ptr<BrowserConnectionHandler> connection_handler_;
- std::unique_ptr<ClientConnectionManager> connection_manager_;
- std::unique_ptr<NetworkEventObserver> network_observer_;
- std::unique_ptr<BlimpConnectionStatistics> connection_statistics_;
-
- DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents);
-};
-
-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));
-}
-
-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();
- 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);
-}
BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint)
: io_thread_("BlimpIOThread"),

Powered by Google App Engine
This is Rietveld 408576698