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

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: 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_(new BrowserConnectionHandler),
19 network_observer_(std::move(network_observer)),
20 connection_statistics_(std::move(statistics)) {
21 DCHECK(connection_statistics_);
22 }
23
24 ClientNetworkComponents::~ClientNetworkComponents() {}
25
26 void ClientNetworkComponents::Initialize() {
27 DCHECK(!connection_manager_);
28 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.
29 }
30
31 void ClientNetworkComponents::ConnectWithAssignment(
32 const Assignment& assignment) {
33 DCHECK(connection_manager_);
34
35 connection_manager_->set_client_token(assignment.client_token);
36 const char* transport_type = "UNKNOWN";
37 switch (assignment.transport_protocol) {
38 case Assignment::SSL:
39 DCHECK(assignment.cert);
40 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport(
41 assignment.engine_endpoint, std::move(assignment.cert),
42 connection_statistics_.get(), nullptr)));
43 transport_type = "SSL";
44 break;
45 case Assignment::TCP:
46 connection_manager_->AddTransport(base::WrapUnique(new TCPClientTransport(
47 assignment.engine_endpoint, connection_statistics_.get(), nullptr)));
48 transport_type = "TCP";
49 break;
50 case Assignment::UNKNOWN:
51 LOG(FATAL) << "Unknown transport type.";
52 break;
53 }
54
55 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " ("
56 << transport_type << ")";
57
58 connection_manager_->Connect();
59 }
60
61 BrowserConnectionHandler*
62 ClientNetworkComponents::GetBrowserConnectionHandler() {
63 return connection_handler_.get();
64 }
65
66 void ClientNetworkComponents::DropCurrentConnection() {
67 connection_handler_->DropCurrentConnection();
68 }
69
70 void ClientNetworkComponents::HandleConnection(
71 std::unique_ptr<BlimpConnection> connection) {
72 VLOG(1) << "Connection established.";
73 connection->AddConnectionErrorObserver(this);
74 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.
75 connection_handler_->HandleConnection(std::move(connection));
76 }
77
78 void ClientNetworkComponents::OnConnectionError(int result) {
79 if (result >= 0) {
80 VLOG(1) << "Disconnected with reason: " << result;
81 } else {
82 VLOG(1) << "Connection error: " << net::ErrorToString(result);
83 }
84 network_observer_->OnDisconnected(result);
85 }
86
87 } // namespace client
88 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698