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

Side by Side Diff: remoting/host/chromoting_host.cc

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 11 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/host/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('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/host/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/host/chromoting_host_context.h" 13 #include "remoting/host/chromoting_host_context.h"
14 #include "remoting/host/desktop_environment_factory.h" 14 #include "remoting/host/desktop_environment.h"
15 #include "remoting/host/event_executor.h" 15 #include "remoting/host/event_executor.h"
16 #include "remoting/host/host_config.h" 16 #include "remoting/host/host_config.h"
17 #include "remoting/protocol/connection_to_client.h" 17 #include "remoting/protocol/connection_to_client.h"
18 #include "remoting/protocol/client_stub.h" 18 #include "remoting/protocol/client_stub.h"
19 #include "remoting/protocol/host_stub.h" 19 #include "remoting/protocol/host_stub.h"
20 #include "remoting/protocol/input_stub.h" 20 #include "remoting/protocol/input_stub.h"
21 #include "remoting/protocol/session_config.h" 21 #include "remoting/protocol/session_config.h"
22 22
23 using remoting::protocol::ConnectionToClient; 23 using remoting::protocol::ConnectionToClient;
24 using remoting::protocol::InputStub; 24 using remoting::protocol::InputStub;
(...skipping 28 matching lines...) Expand all
53 false, 53 false,
54 }; 54 };
55 55
56 } // namespace 56 } // namespace
57 57
58 ChromotingHost::ChromotingHost( 58 ChromotingHost::ChromotingHost(
59 SignalStrategy* signal_strategy, 59 SignalStrategy* signal_strategy,
60 DesktopEnvironmentFactory* desktop_environment_factory, 60 DesktopEnvironmentFactory* desktop_environment_factory,
61 scoped_ptr<protocol::SessionManager> session_manager, 61 scoped_ptr<protocol::SessionManager> session_manager,
62 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 62 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
63 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
63 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, 64 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
64 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, 65 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
65 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) 66 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
67 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
66 : desktop_environment_factory_(desktop_environment_factory), 68 : desktop_environment_factory_(desktop_environment_factory),
67 session_manager_(session_manager.Pass()), 69 session_manager_(session_manager.Pass()),
68 audio_task_runner_(audio_task_runner), 70 audio_task_runner_(audio_task_runner),
71 input_task_runner_(input_task_runner),
69 video_capture_task_runner_(video_capture_task_runner), 72 video_capture_task_runner_(video_capture_task_runner),
70 video_encode_task_runner_(video_encode_task_runner), 73 video_encode_task_runner_(video_encode_task_runner),
71 network_task_runner_(network_task_runner), 74 network_task_runner_(network_task_runner),
75 ui_task_runner_(ui_task_runner),
72 signal_strategy_(signal_strategy), 76 signal_strategy_(signal_strategy),
73 clients_count_(0),
74 state_(kInitial), 77 state_(kInitial),
75 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), 78 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()),
76 login_backoff_(&kDefaultBackoffPolicy), 79 login_backoff_(&kDefaultBackoffPolicy),
77 authenticating_client_(false), 80 authenticating_client_(false),
78 reject_authenticating_client_(false) { 81 reject_authenticating_client_(false) {
79 DCHECK(signal_strategy); 82 DCHECK(signal_strategy);
80 DCHECK(network_task_runner_->BelongsToCurrentThread()); 83 DCHECK(network_task_runner_->BelongsToCurrentThread());
81 84
82 if (!desktop_environment_factory_->SupportsAudioCapture()) { 85 if (!desktop_environment_factory_->SupportsAudioCapture()) {
83 protocol::CandidateSessionConfig::DisableAudioChannel( 86 protocol::CandidateSessionConfig::DisableAudioChannel(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (!shutdown_task.is_null()) 136 if (!shutdown_task.is_null())
134 shutdown_tasks_.push_back(shutdown_task); 137 shutdown_tasks_.push_back(shutdown_task);
135 state_ = kStopping; 138 state_ = kStopping;
136 139
137 // Disconnect all of the clients. 140 // Disconnect all of the clients.
138 while (!clients_.empty()) { 141 while (!clients_.empty()) {
139 clients_.front()->Disconnect(); 142 clients_.front()->Disconnect();
140 } 143 }
141 144
142 // Run the remaining shutdown tasks. 145 // Run the remaining shutdown tasks.
143 if (state_ == kStopping && !clients_count_) 146 if (state_ == kStopping)
144 ShutdownFinish(); 147 ShutdownFinish();
145 148
146 break; 149 break;
147 } 150 }
148 } 151 }
149 152
150 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { 153 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) {
151 DCHECK(network_task_runner_->BelongsToCurrentThread()); 154 DCHECK(network_task_runner_->BelongsToCurrentThread());
152 status_observers_.AddObserver(observer); 155 status_observers_.AddObserver(observer);
153 } 156 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 break; 237 break;
235 } 238 }
236 } 239 }
237 CHECK(it != clients_.end()); 240 CHECK(it != clients_.end());
238 241
239 if (client->is_authenticated()) { 242 if (client->is_authenticated()) {
240 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, 243 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_,
241 OnClientDisconnected(client->client_jid())); 244 OnClientDisconnected(client->client_jid()));
242 } 245 }
243 246
244 client->Stop(base::Bind(&ChromotingHost::OnClientStopped, this)); 247 client->Stop();
245 clients_.erase(it); 248 clients_.erase(it);
249
250 if (state_ == kStopping && clients_.empty())
251 ShutdownFinish();
246 } 252 }
247 253
248 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, 254 void ChromotingHost::OnSessionSequenceNumber(ClientSession* session,
249 int64 sequence_number) { 255 int64 sequence_number) {
250 DCHECK(network_task_runner_->BelongsToCurrentThread()); 256 DCHECK(network_task_runner_->BelongsToCurrentThread());
251 } 257 }
252 258
253 void ChromotingHost::OnSessionRouteChange( 259 void ChromotingHost::OnSessionRouteChange(
254 ClientSession* session, 260 ClientSession* session,
255 const std::string& channel_name, 261 const std::string& channel_name,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 *response = protocol::SessionManager::ACCEPT; 313 *response = protocol::SessionManager::ACCEPT;
308 314
309 LOG(INFO) << "Client connected: " << session->jid(); 315 LOG(INFO) << "Client connected: " << session->jid();
310 316
311 // Create a client object. 317 // Create a client object.
312 scoped_ptr<protocol::ConnectionToClient> connection( 318 scoped_ptr<protocol::ConnectionToClient> connection(
313 new protocol::ConnectionToClient(session)); 319 new protocol::ConnectionToClient(session));
314 scoped_refptr<ClientSession> client = new ClientSession( 320 scoped_refptr<ClientSession> client = new ClientSession(
315 this, 321 this,
316 audio_task_runner_, 322 audio_task_runner_,
323 input_task_runner_,
317 video_capture_task_runner_, 324 video_capture_task_runner_,
318 video_encode_task_runner_, 325 video_encode_task_runner_,
319 network_task_runner_, 326 network_task_runner_,
327 ui_task_runner_,
320 connection.Pass(), 328 connection.Pass(),
321 desktop_environment_factory_, 329 desktop_environment_factory_,
322 max_session_duration_); 330 max_session_duration_);
323 clients_.push_back(client); 331 clients_.push_back(client);
324 clients_count_++;
325 } 332 }
326 333
327 void ChromotingHost::set_protocol_config( 334 void ChromotingHost::set_protocol_config(
328 scoped_ptr<protocol::CandidateSessionConfig> config) { 335 scoped_ptr<protocol::CandidateSessionConfig> config) {
329 DCHECK(network_task_runner_->BelongsToCurrentThread()); 336 DCHECK(network_task_runner_->BelongsToCurrentThread());
330 DCHECK(config.get()); 337 DCHECK(config.get());
331 DCHECK_EQ(state_, kInitial); 338 DCHECK_EQ(state_, kInitial);
332 protocol_config_ = config.Pass(); 339 protocol_config_ = config.Pass();
333 } 340 }
334 341
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 380 }
374 } 381 }
375 382
376 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { 383 void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) {
377 DCHECK(network_task_runner_->BelongsToCurrentThread()); 384 DCHECK(network_task_runner_->BelongsToCurrentThread());
378 DCHECK_EQ(state_, kInitial); 385 DCHECK_EQ(state_, kInitial);
379 386
380 ui_strings_ = ui_strings; 387 ui_strings_ = ui_strings;
381 } 388 }
382 389
383 void ChromotingHost::OnClientStopped() {
384 DCHECK(network_task_runner_->BelongsToCurrentThread());
385
386 --clients_count_;
387 if (state_ == kStopping && !clients_count_)
388 ShutdownFinish();
389 }
390
391 void ChromotingHost::ShutdownFinish() { 390 void ChromotingHost::ShutdownFinish() {
392 DCHECK(network_task_runner_->BelongsToCurrentThread()); 391 DCHECK(network_task_runner_->BelongsToCurrentThread());
393 DCHECK_EQ(state_, kStopping); 392 DCHECK_EQ(state_, kStopping);
394 393
395 state_ = kStopped; 394 state_ = kStopped;
396 395
397 // Destroy session manager. 396 // Destroy session manager.
398 session_manager_.reset(); 397 session_manager_.reset();
399 398
400 // Clear |desktop_environment_factory_| and |signal_strategy_| to 399 // Clear |desktop_environment_factory_| and |signal_strategy_| to
(...skipping 10 matching lines...) Expand all
411 OnShutdown()); 410 OnShutdown());
412 411
413 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); 412 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin();
414 it != shutdown_tasks_.end(); ++it) { 413 it != shutdown_tasks_.end(); ++it) {
415 it->Run(); 414 it->Run();
416 } 415 }
417 shutdown_tasks_.clear(); 416 shutdown_tasks_.clear();
418 } 417 }
419 418
420 } // namespace remoting 419 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698