OLD | NEW |
---|---|
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/base/encoder.h" | 13 #include "remoting/base/encoder.h" |
14 #include "remoting/base/encoder_row_based.h" | 14 #include "remoting/base/encoder_row_based.h" |
15 #include "remoting/base/encoder_vp8.h" | 15 #include "remoting/base/encoder_vp8.h" |
16 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
17 #include "remoting/host/desktop_environment.h" | 17 #include "remoting/host/desktop_environment.h" |
18 #include "remoting/host/event_executor.h" | 18 #include "remoting/host/event_executor.h" |
19 #include "remoting/host/host_config.h" | 19 #include "remoting/host/host_config.h" |
20 #include "remoting/host/host_port_allocator.h" | |
21 #include "remoting/host/screen_recorder.h" | 20 #include "remoting/host/screen_recorder.h" |
22 #include "remoting/protocol/connection_to_client.h" | 21 #include "remoting/protocol/connection_to_client.h" |
23 #include "remoting/protocol/client_stub.h" | 22 #include "remoting/protocol/client_stub.h" |
24 #include "remoting/protocol/host_stub.h" | 23 #include "remoting/protocol/host_stub.h" |
25 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
26 #include "remoting/protocol/jingle_session_manager.h" | |
27 #include "remoting/protocol/libjingle_transport_factory.h" | |
28 #include "remoting/protocol/session_config.h" | 25 #include "remoting/protocol/session_config.h" |
29 | 26 |
30 using remoting::protocol::ConnectionToClient; | 27 using remoting::protocol::ConnectionToClient; |
31 using remoting::protocol::InputStub; | 28 using remoting::protocol::InputStub; |
32 | 29 |
33 namespace remoting { | 30 namespace remoting { |
34 | 31 |
35 namespace { | 32 namespace { |
36 | 33 |
37 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | 34 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { |
(...skipping 21 matching lines...) Expand all Loading... | |
59 // Don't use initial delay unless the last request was an error. | 56 // Don't use initial delay unless the last request was an error. |
60 false, | 57 false, |
61 }; | 58 }; |
62 | 59 |
63 } // namespace | 60 } // namespace |
64 | 61 |
65 ChromotingHost::ChromotingHost( | 62 ChromotingHost::ChromotingHost( |
66 ChromotingHostContext* context, | 63 ChromotingHostContext* context, |
67 SignalStrategy* signal_strategy, | 64 SignalStrategy* signal_strategy, |
68 DesktopEnvironment* environment, | 65 DesktopEnvironment* environment, |
66 scoped_ptr<SessionManagerFactory> session_manager_factory, | |
Sergey Ulanov
2012/06/11 23:43:37
Instead of passing the factory here can we pass th
| |
69 const NetworkSettings& network_settings) | 67 const NetworkSettings& network_settings) |
70 : context_(context), | 68 : context_(context), |
71 desktop_environment_(environment), | 69 desktop_environment_(environment), |
70 session_manager_factory_(session_manager_factory.Pass()), | |
72 network_settings_(network_settings), | 71 network_settings_(network_settings), |
73 signal_strategy_(signal_strategy), | 72 signal_strategy_(signal_strategy), |
74 stopping_recorders_(0), | 73 stopping_recorders_(0), |
75 state_(kInitial), | 74 state_(kInitial), |
76 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 75 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
77 login_backoff_(&kDefaultBackoffPolicy), | 76 login_backoff_(&kDefaultBackoffPolicy), |
78 authenticating_client_(false), | 77 authenticating_client_(false), |
79 reject_authenticating_client_(false) { | 78 reject_authenticating_client_(false) { |
80 DCHECK(context_); | 79 DCHECK(context_); |
81 DCHECK(signal_strategy); | 80 DCHECK(signal_strategy); |
82 DCHECK(desktop_environment_); | 81 DCHECK(desktop_environment_); |
83 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 82 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
84 } | 83 } |
85 | 84 |
86 ChromotingHost::~ChromotingHost() { | 85 ChromotingHost::~ChromotingHost() { |
87 DCHECK(clients_.empty()); | 86 DCHECK(clients_.empty()); |
88 } | 87 } |
89 | 88 |
90 void ChromotingHost::Start() { | 89 void ChromotingHost::Start() { |
91 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 90 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
92 | 91 |
93 LOG(INFO) << "Starting host"; | 92 LOG(INFO) << "Starting host"; |
94 | 93 |
95 // Make sure this object is not started. | 94 // Make sure this object is not started. |
96 if (state_ != kInitial) | 95 if (state_ != kInitial) |
97 return; | 96 return; |
98 state_ = kStarted; | 97 state_ = kStarted; |
99 | 98 |
100 // Create port allocator and transport factory. | |
101 scoped_ptr<HostPortAllocator> port_allocator( | |
102 HostPortAllocator::Create(context_->url_request_context_getter(), | |
103 network_settings_)); | |
104 | |
105 bool incoming_only = network_settings_.nat_traversal_mode == | |
106 NetworkSettings::NAT_TRAVERSAL_DISABLED; | |
107 | |
108 scoped_ptr<protocol::TransportFactory> transport_factory( | |
109 new protocol::LibjingleTransportFactory( | |
110 port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), | |
111 incoming_only)); | |
112 | |
113 // Create and start session manager. | 99 // Create and start session manager. |
114 bool fetch_stun_relay_info = network_settings_.nat_traversal_mode == | 100 session_manager_.reset(session_manager_factory_->CreateSessionManager( |
115 NetworkSettings::NAT_TRAVERSAL_ENABLED; | 101 network_settings_, context_->url_request_context_getter()).release()); |
116 session_manager_.reset(new protocol::JingleSessionManager( | |
117 transport_factory.Pass(), fetch_stun_relay_info)); | |
118 session_manager_->Init(signal_strategy_, this); | 102 session_manager_->Init(signal_strategy_, this); |
119 } | 103 } |
120 | 104 |
121 // This method is called when we need to destroy the host process. | 105 // This method is called when we need to destroy the host process. |
122 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { | 106 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { |
123 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 107 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
124 context_->network_message_loop()->PostTask( | 108 context_->network_message_loop()->PostTask( |
125 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); | 109 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); |
126 return; | 110 return; |
127 } | 111 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 OnShutdown()); | 434 OnShutdown()); |
451 | 435 |
452 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 436 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
453 it != shutdown_tasks_.end(); ++it) { | 437 it != shutdown_tasks_.end(); ++it) { |
454 it->Run(); | 438 it->Run(); |
455 } | 439 } |
456 shutdown_tasks_.clear(); | 440 shutdown_tasks_.clear(); |
457 } | 441 } |
458 | 442 |
459 } // namespace remoting | 443 } // namespace remoting |
OLD | NEW |