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

Side by Side Diff: remoting/client/chromoting_client.cc

Issue 384523003: Cleanups in ChromotingClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/client_config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/chromoting_client.h" 5 #include "remoting/client/chromoting_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "remoting/base/capabilities.h" 8 #include "remoting/base/capabilities.h"
9 #include "remoting/client/audio_decode_scheduler.h" 9 #include "remoting/client/audio_decode_scheduler.h"
10 #include "remoting/client/audio_player.h" 10 #include "remoting/client/audio_player.h"
11 #include "remoting/client/client_context.h" 11 #include "remoting/client/client_context.h"
12 #include "remoting/client/client_user_interface.h" 12 #include "remoting/client/client_user_interface.h"
13 #include "remoting/client/video_renderer.h" 13 #include "remoting/client/video_renderer.h"
14 #include "remoting/proto/audio.pb.h" 14 #include "remoting/proto/audio.pb.h"
15 #include "remoting/proto/video.pb.h" 15 #include "remoting/proto/video.pb.h"
16 #include "remoting/protocol/authentication_method.h" 16 #include "remoting/protocol/authentication_method.h"
17 #include "remoting/protocol/connection_to_host.h" 17 #include "remoting/protocol/connection_to_host.h"
18 #include "remoting/protocol/host_stub.h" 18 #include "remoting/protocol/host_stub.h"
19 #include "remoting/protocol/negotiating_client_authenticator.h" 19 #include "remoting/protocol/negotiating_client_authenticator.h"
20 #include "remoting/protocol/session_config.h" 20 #include "remoting/protocol/session_config.h"
21 #include "remoting/protocol/transport.h" 21 #include "remoting/protocol/transport.h"
22 22
23 namespace remoting { 23 namespace remoting {
24 24
25 using protocol::AuthenticationMethod; 25 using protocol::AuthenticationMethod;
26 26
27 ChromotingClient::ChromotingClient( 27 ChromotingClient::ChromotingClient(
28 const ClientConfig& config,
29 ClientContext* client_context, 28 ClientContext* client_context,
30 protocol::ConnectionToHost* connection,
31 ClientUserInterface* user_interface, 29 ClientUserInterface* user_interface,
32 VideoRenderer* video_renderer, 30 VideoRenderer* video_renderer,
33 scoped_ptr<AudioPlayer> audio_player) 31 scoped_ptr<AudioPlayer> audio_player)
34 : config_(config), 32 : task_runner_(client_context->main_task_runner()),
35 task_runner_(client_context->main_task_runner()),
36 connection_(connection),
37 user_interface_(user_interface), 33 user_interface_(user_interface),
38 video_renderer_(video_renderer), 34 video_renderer_(video_renderer),
39 host_capabilities_received_(false), 35 host_capabilities_received_(false) {
40 weak_factory_(this) {
41 if (audio_player) { 36 if (audio_player) {
42 audio_decode_scheduler_.reset(new AudioDecodeScheduler( 37 audio_decode_scheduler_.reset(new AudioDecodeScheduler(
43 client_context->main_task_runner(), 38 client_context->main_task_runner(),
44 client_context->audio_decode_task_runner(), 39 client_context->audio_decode_task_runner(),
45 audio_player.Pass())); 40 audio_player.Pass()));
46 } 41 }
47 } 42 }
48 43
49 ChromotingClient::~ChromotingClient() { 44 ChromotingClient::~ChromotingClient() {
50 } 45 }
51 46
52 void ChromotingClient::Start( 47 void ChromotingClient::Start(
53 SignalStrategy* signal_strategy, 48 SignalStrategy* signal_strategy,
54 scoped_ptr<protocol::TransportFactory> transport_factory) { 49 scoped_ptr<protocol::Authenticator> authenticator,
50 scoped_ptr<protocol::TransportFactory> transport_factory,
51 const std::string& host_jid,
52 const std::string& capabilities) {
55 DCHECK(task_runner_->BelongsToCurrentThread()); 53 DCHECK(task_runner_->BelongsToCurrentThread());
56 54
57 scoped_ptr<protocol::Authenticator> authenticator( 55 local_capabilities_ = capabilities;
58 new protocol::NegotiatingClientAuthenticator(
59 config_.client_pairing_id,
60 config_.client_paired_secret,
61 config_.authentication_tag,
62 config_.fetch_secret_callback,
63 user_interface_->GetTokenFetcher(config_.host_public_key),
64 config_.authentication_methods));
65 56
66 // Create a WeakPtr to ourself for to use for all posted tasks. 57 connection_.set_client_stub(this);
67 weak_ptr_ = weak_factory_.GetWeakPtr(); 58 connection_.set_clipboard_stub(this);
59 connection_.set_video_stub(video_renderer_);
60 connection_.set_audio_stub(audio_decode_scheduler_.get());
68 61
69 connection_->set_client_stub(this); 62 connection_.Connect(signal_strategy, transport_factory.Pass(),
70 connection_->set_clipboard_stub(this); 63 authenticator.Pass(), host_jid, this);
71 connection_->set_video_stub(video_renderer_);
72 connection_->set_audio_stub(audio_decode_scheduler_.get());
73
74 connection_->Connect(signal_strategy,
75 transport_factory.Pass(),
76 authenticator.Pass(),
77 config_.host_jid,
78 config_.host_public_key,
79 this);
80 } 64 }
81 65
82 void ChromotingClient::SetCapabilities( 66 void ChromotingClient::SetCapabilities(
83 const protocol::Capabilities& capabilities) { 67 const protocol::Capabilities& capabilities) {
84 DCHECK(task_runner_->BelongsToCurrentThread()); 68 DCHECK(task_runner_->BelongsToCurrentThread());
85 69
86 // Only accept the first |protocol::Capabilities| message. 70 // Only accept the first |protocol::Capabilities| message.
87 if (host_capabilities_received_) { 71 if (host_capabilities_received_) {
88 LOG(WARNING) << "protocol::Capabilities has been received already."; 72 LOG(WARNING) << "protocol::Capabilities has been received already.";
89 return; 73 return;
90 } 74 }
91 75
92 host_capabilities_received_ = true; 76 host_capabilities_received_ = true;
93 if (capabilities.has_capabilities()) 77 if (capabilities.has_capabilities())
94 host_capabilities_ = capabilities.capabilities(); 78 host_capabilities_ = capabilities.capabilities();
95 79
96 VLOG(1) << "Host capabilities: " << host_capabilities_; 80 VLOG(1) << "Host capabilities: " << host_capabilities_;
97 81
98 // Calculate the set of capabilities enabled by both client and host and pass 82 // Calculate the set of capabilities enabled by both client and host and pass
99 // it to the webapp. 83 // it to the webapp.
100 user_interface_->SetCapabilities( 84 user_interface_->SetCapabilities(
101 IntersectCapabilities(config_.capabilities, host_capabilities_)); 85 IntersectCapabilities(local_capabilities_, host_capabilities_));
102 } 86 }
103 87
104 void ChromotingClient::SetPairingResponse( 88 void ChromotingClient::SetPairingResponse(
105 const protocol::PairingResponse& pairing_response) { 89 const protocol::PairingResponse& pairing_response) {
106 DCHECK(task_runner_->BelongsToCurrentThread()); 90 DCHECK(task_runner_->BelongsToCurrentThread());
107 91
108 user_interface_->SetPairingResponse(pairing_response); 92 user_interface_->SetPairingResponse(pairing_response);
109 } 93 }
110 94
111 void ChromotingClient::DeliverHostMessage( 95 void ChromotingClient::DeliverHostMessage(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 const protocol::TransportRoute& route) { 136 const protocol::TransportRoute& route) {
153 VLOG(0) << "Using " << protocol::TransportRoute::GetTypeString(route.type) 137 VLOG(0) << "Using " << protocol::TransportRoute::GetTypeString(route.type)
154 << " connection for " << channel_name << " channel"; 138 << " connection for " << channel_name << " channel";
155 user_interface_->OnRouteChanged(channel_name, route); 139 user_interface_->OnRouteChanged(channel_name, route);
156 } 140 }
157 141
158 void ChromotingClient::OnAuthenticated() { 142 void ChromotingClient::OnAuthenticated() {
159 DCHECK(task_runner_->BelongsToCurrentThread()); 143 DCHECK(task_runner_->BelongsToCurrentThread());
160 144
161 // Initialize the decoder. 145 // Initialize the decoder.
162 video_renderer_->Initialize(connection_->config()); 146 video_renderer_->Initialize(connection_.config());
163 if (connection_->config().is_audio_enabled()) 147 if (connection_.config().is_audio_enabled())
164 audio_decode_scheduler_->Initialize(connection_->config()); 148 audio_decode_scheduler_->Initialize(connection_.config());
165 149
166 // Do not negotiate capabilities with the host if the host does not support 150 // Do not negotiate capabilities with the host if the host does not support
167 // them. 151 // them.
168 if (!connection_->config().SupportsCapabilities()) { 152 if (!connection_.config().SupportsCapabilities()) {
169 VLOG(1) << "The host does not support any capabilities."; 153 VLOG(1) << "The host does not support any capabilities.";
170 154
171 host_capabilities_received_ = true; 155 host_capabilities_received_ = true;
172 user_interface_->SetCapabilities(host_capabilities_); 156 user_interface_->SetCapabilities(host_capabilities_);
173 } 157 }
174 } 158 }
175 159
176 void ChromotingClient::OnChannelsConnected() { 160 void ChromotingClient::OnChannelsConnected() {
177 DCHECK(task_runner_->BelongsToCurrentThread()); 161 DCHECK(task_runner_->BelongsToCurrentThread());
178 162
179 // Negotiate capabilities with the host. 163 // Negotiate capabilities with the host.
180 if (connection_->config().SupportsCapabilities()) { 164 if (connection_.config().SupportsCapabilities()) {
181 VLOG(1) << "Client capabilities: " << config_.capabilities; 165 VLOG(1) << "Client capabilities: " << local_capabilities_;
182 166
183 protocol::Capabilities capabilities; 167 protocol::Capabilities capabilities;
184 capabilities.set_capabilities(config_.capabilities); 168 capabilities.set_capabilities(local_capabilities_);
185 connection_->host_stub()->SetCapabilities(capabilities); 169 connection_.host_stub()->SetCapabilities(capabilities);
186 } 170 }
187 } 171 }
188 172
189 } // namespace remoting 173 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/client_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698