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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "blimp/client/core/session/client_network_components.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9 #include "blimp/net/ssl_client_transport.h"
10 #include "net/base/net_errors.h"
11
12 namespace blimp {
13 namespace client {
14
15 ClientNetworkComponents::ClientNetworkComponents(
16 std::unique_ptr<NetworkEventObserver> network_observer,
17 std::unique_ptr<BlimpConnectionStatistics> statistics)
18 : connection_handler_(),
19 network_observer_(std::move(network_observer)),
20 connection_statistics_(std::move(statistics)) {
21 DCHECK(connection_statistics_);
22 }
23
24 ClientNetworkComponents::~ClientNetworkComponents() {
25 DCHECK(io_thread_checker_.CalledOnValidThread());
26 }
27
28 void ClientNetworkComponents::Initialize() {
29 io_thread_checker_.DetachFromThread();
30 DCHECK(!connection_manager_);
31 connection_manager_ = base::MakeUnique<ClientConnectionManager>(this);
32 }
33
34 void ClientNetworkComponents::ConnectWithAssignment(
35 const Assignment& assignment) {
36 DCHECK(io_thread_checker_.CalledOnValidThread());
37 DCHECK(connection_manager_);
38
39 connection_manager_->set_client_token(assignment.client_token);
40 const char* transport_type = "UNKNOWN";
41 switch (assignment.transport_protocol) {
42 case Assignment::SSL:
43 DCHECK(assignment.cert);
44 connection_manager_->AddTransport(base::MakeUnique<SSLClientTransport>(
45 assignment.engine_endpoint, std::move(assignment.cert),
46 connection_statistics_.get(), nullptr));
47 transport_type = "SSL";
48 break;
49 case Assignment::TCP:
50 connection_manager_->AddTransport(base::MakeUnique<TCPClientTransport>(
51 assignment.engine_endpoint, connection_statistics_.get(), nullptr));
52 transport_type = "TCP";
53 break;
54 case Assignment::UNKNOWN:
55 LOG(FATAL) << "Unknown transport type.";
56 break;
57 }
58
59 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " ("
60 << transport_type << ")";
61
62 connection_manager_->Connect();
63 }
64
65 BrowserConnectionHandler*
66 ClientNetworkComponents::GetBrowserConnectionHandler() {
67 DCHECK(io_thread_checker_.CalledOnValidThread());
68 return &connection_handler_;
69 }
70
71 void ClientNetworkComponents::HandleConnection(
72 std::unique_ptr<BlimpConnection> connection) {
73 DCHECK(io_thread_checker_.CalledOnValidThread());
74 VLOG(1) << "Connection established.";
75 connection->AddConnectionErrorObserver(this);
76 connection_handler_.HandleConnection(std::move(connection));
77 network_observer_->OnConnected();
78 }
79
80 void ClientNetworkComponents::OnConnectionError(int result) {
81 DCHECK(io_thread_checker_.CalledOnValidThread());
82 if (result >= 0) {
83 VLOG(1) << "Disconnected with reason: " << result;
84 } else {
85 VLOG(1) << "Connection error: " << net::ErrorToString(result);
86 }
87 network_observer_->OnDisconnected(result);
88 }
89
90 } // namespace client
91 } // namespace blimp
OLDNEW
« 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