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/screen_recorder.h" | 20 #include "remoting/host/screen_recorder.h" |
21 #include "remoting/protocol/connection_to_client.h" | 21 #include "remoting/protocol/connection_to_client.h" |
22 #include "remoting/protocol/client_stub.h" | 22 #include "remoting/protocol/client_stub.h" |
23 #include "remoting/protocol/host_stub.h" | 23 #include "remoting/protocol/host_stub.h" |
24 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
25 #include "remoting/protocol/jingle_session_manager.h" | 25 #include "remoting/protocol/jingle_session_manager.h" |
26 #include "remoting/protocol/libjingle_transport_factory.h" | 26 #include "remoting/protocol/libjingle_transport_factory.h" |
27 #include "remoting/protocol/session_config.h" | 27 #include "remoting/protocol/session_config.h" |
28 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | |
29 #include "third_party/libjingle/source/talk/base/network.h" | |
30 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h" | |
28 | 31 |
29 using remoting::protocol::ConnectionToClient; | 32 using remoting::protocol::ConnectionToClient; |
30 using remoting::protocol::InputStub; | 33 using remoting::protocol::InputStub; |
31 | 34 |
32 namespace remoting { | 35 namespace remoting { |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | 39 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { |
37 // Number of initial errors (in sequence) to ignore before applying | 40 // Number of initial errors (in sequence) to ignore before applying |
(...skipping 20 matching lines...) Expand all Loading... | |
58 // Don't use initial delay unless the last request was an error. | 61 // Don't use initial delay unless the last request was an error. |
59 false, | 62 false, |
60 }; | 63 }; |
61 | 64 |
62 } // namespace | 65 } // namespace |
63 | 66 |
64 ChromotingHost::ChromotingHost( | 67 ChromotingHost::ChromotingHost( |
65 ChromotingHostContext* context, | 68 ChromotingHostContext* context, |
66 SignalStrategy* signal_strategy, | 69 SignalStrategy* signal_strategy, |
67 DesktopEnvironment* environment, | 70 DesktopEnvironment* environment, |
68 const protocol::NetworkSettings& network_settings) | 71 const NetworkSettings& network_settings) |
69 : context_(context), | 72 : context_(context), |
70 desktop_environment_(environment), | 73 desktop_environment_(environment), |
71 network_settings_(network_settings), | 74 network_settings_(network_settings), |
72 signal_strategy_(signal_strategy), | 75 signal_strategy_(signal_strategy), |
73 stopping_recorders_(0), | 76 stopping_recorders_(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) { |
(...skipping 11 matching lines...) Expand all Loading... | |
90 void ChromotingHost::Start() { | 93 void ChromotingHost::Start() { |
91 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 94 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
92 | 95 |
93 LOG(INFO) << "Starting host"; | 96 LOG(INFO) << "Starting host"; |
94 | 97 |
95 // Make sure this object is not started. | 98 // Make sure this object is not started. |
96 if (state_ != kInitial) | 99 if (state_ != kInitial) |
97 return; | 100 return; |
98 state_ = kStarted; | 101 state_ = kStarted; |
99 | 102 |
103 // Create port allocator. | |
104 // TODO(sergeyu): Replace the code below with HostPortAllocator when | |
105 // it is implemented. | |
106 scoped_ptr<talk_base::NetworkManager> network_manager( | |
107 new talk_base::BasicNetworkManager()); | |
108 scoped_ptr<talk_base::PacketSocketFactory> socket_factory( | |
109 new talk_base::BasicPacketSocketFactory()); | |
110 scoped_ptr<cricket::PortAllocator> port_allocator; | |
111 | |
112 // We always use PseudoTcp to provide a reliable channel. However | |
113 // when it is used together with TCP the performance is veryey bad | |
Wez
2012/04/27 17:58:51
typo: veryey
Sergey Ulanov
2012/04/27 22:51:14
Done.
| |
114 // so we explicitly disable TCP connections. | |
Wez
2012/04/27 17:58:51
nit: ... disable channels conencting over TCP.
Sergey Ulanov
2012/04/27 22:51:14
Done.
| |
115 int port_allocator_flags = cricket::PORTALLOCATOR_DISABLE_TCP; | |
116 if (network_settings_.nat_traversal_mode == | |
117 NetworkSettings::NAT_TRAVERSAL_ENABLED) { | |
Wez
2012/04/27 17:58:51
Replace this if/else with a switch, so it's easier
Sergey Ulanov
2012/04/27 22:51:14
In one of my two other CLs this code is moved and
| |
118 port_allocator.reset(new cricket::HttpPortAllocator( | |
119 network_manager.get(), socket_factory.get(), "")); | |
120 } else { | |
121 port_allocator_flags |= cricket::PORTALLOCATOR_DISABLE_STUN | | |
122 cricket::PORTALLOCATOR_DISABLE_RELAY; | |
123 port_allocator.reset( | |
124 new cricket::BasicPortAllocator(network_manager.get(), | |
125 socket_factory.get())); | |
126 } | |
127 port_allocator->set_flags(port_allocator_flags); | |
128 port_allocator->SetPortRange(network_settings_.min_port, | |
129 network_settings_.max_port); | |
130 | |
131 bool incoming_only = network_settings_.nat_traversal_mode == | |
132 NetworkSettings::NAT_TRAVERSAL_DISABLED; | |
133 | |
134 scoped_ptr<protocol::TransportFactory> transport_factory( | |
135 new protocol::LibjingleTransportFactory( | |
136 network_manager.Pass(), socket_factory.Pass(), | |
137 port_allocator.Pass(), incoming_only)); | |
138 | |
100 // Create and start session manager. | 139 // Create and start session manager. |
101 scoped_ptr<protocol::TransportFactory> transport_factory( | 140 bool fetch_stun_relay_info = network_settings_.nat_traversal_mode == |
102 new protocol::LibjingleTransportFactory()); | 141 NetworkSettings::NAT_TRAVERSAL_ENABLED; |
Wez
2012/04/27 17:58:51
nit: Consider defining this false, before the port
Sergey Ulanov
2012/04/27 22:51:14
This code above is moved to a separate file in one
| |
103 session_manager_.reset( | 142 session_manager_.reset(new protocol::JingleSessionManager( |
104 new protocol::JingleSessionManager(transport_factory.Pass())); | 143 transport_factory.Pass(), fetch_stun_relay_info)); |
105 session_manager_->Init(signal_strategy_, this, network_settings_); | 144 session_manager_->Init(signal_strategy_, this); |
106 } | 145 } |
107 | 146 |
108 // This method is called when we need to destroy the host process. | 147 // This method is called when we need to destroy the host process. |
109 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { | 148 void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { |
110 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 149 if (!context_->network_message_loop()->BelongsToCurrentThread()) { |
111 context_->network_message_loop()->PostTask( | 150 context_->network_message_loop()->PostTask( |
112 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); | 151 FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); |
113 return; | 152 return; |
114 } | 153 } |
115 | 154 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 OnShutdown()); | 451 OnShutdown()); |
413 | 452 |
414 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 453 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
415 it != shutdown_tasks_.end(); ++it) { | 454 it != shutdown_tasks_.end(); ++it) { |
416 it->Run(); | 455 it->Run(); |
417 } | 456 } |
418 shutdown_tasks_.clear(); | 457 shutdown_tasks_.clear(); |
419 } | 458 } |
420 | 459 |
421 } // namespace remoting | 460 } // namespace remoting |
OLD | NEW |