OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 ChromotingHost::ChromotingHost(ChromotingHostContext* context, | 43 ChromotingHost::ChromotingHost(ChromotingHostContext* context, |
44 MutableHostConfig* config, | 44 MutableHostConfig* config, |
45 DesktopEnvironment* environment, | 45 DesktopEnvironment* environment, |
46 bool allow_nat_traversal) | 46 bool allow_nat_traversal) |
47 : context_(context), | 47 : context_(context), |
48 desktop_environment_(environment), | 48 desktop_environment_(environment), |
49 config_(config), | 49 config_(config), |
50 allow_nat_traversal_(allow_nat_traversal), | 50 allow_nat_traversal_(allow_nat_traversal), |
| 51 have_shared_secret_(false), |
51 stopping_recorders_(0), | 52 stopping_recorders_(0), |
52 state_(kInitial), | 53 state_(kInitial), |
53 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 54 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
54 is_it2me_(false) { | 55 is_it2me_(false) { |
55 DCHECK(desktop_environment_); | 56 DCHECK(desktop_environment_); |
56 desktop_environment_->set_host(this); | 57 desktop_environment_->set_host(this); |
57 } | 58 } |
58 | 59 |
59 ChromotingHost::~ChromotingHost() { | 60 ChromotingHost::~ChromotingHost() { |
60 DCHECK(clients_.empty()); | 61 DCHECK(clients_.empty()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 128 |
128 // Stop session manager. | 129 // Stop session manager. |
129 if (session_manager_.get()) { | 130 if (session_manager_.get()) { |
130 session_manager_->Close(); | 131 session_manager_->Close(); |
131 // It may not be safe to delete |session_manager_| here becase | 132 // It may not be safe to delete |session_manager_| here becase |
132 // this method may be invoked in response to a libjingle event and | 133 // this method may be invoked in response to a libjingle event and |
133 // libjingle's sigslot doesn't handle it properly, so postpone the | 134 // libjingle's sigslot doesn't handle it properly, so postpone the |
134 // deletion. | 135 // deletion. |
135 context_->network_message_loop()->DeleteSoon( | 136 context_->network_message_loop()->DeleteSoon( |
136 FROM_HERE, session_manager_.release()); | 137 FROM_HERE, session_manager_.release()); |
| 138 have_shared_secret_ = false; |
137 } | 139 } |
138 | 140 |
139 // Stop XMPP connection synchronously. | 141 // Stop XMPP connection synchronously. |
140 if (signal_strategy_.get()) { | 142 if (signal_strategy_.get()) { |
141 signal_strategy_->Close(); | 143 signal_strategy_->Close(); |
142 signal_strategy_.reset(); | 144 signal_strategy_.reset(); |
143 | 145 |
144 for (StatusObserverList::iterator it = status_observers_.begin(); | 146 for (StatusObserverList::iterator it = status_observers_.begin(); |
145 it != status_observers_.end(); ++it) { | 147 it != status_observers_.end(); ++it) { |
146 (*it)->OnSignallingDisconnected(); | 148 (*it)->OnSignallingDisconnected(); |
147 } | 149 } |
148 } | 150 } |
149 | 151 |
150 if (recorder_.get()) { | 152 if (recorder_.get()) { |
151 StopScreenRecorder(); | 153 StopScreenRecorder(); |
152 } else { | 154 } else { |
153 ShutdownFinish(); | 155 ShutdownFinish(); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
157 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 159 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
158 DCHECK_EQ(state_, kInitial); | 160 DCHECK_EQ(state_, kInitial); |
159 status_observers_.push_back(observer); | 161 status_observers_.push_back(observer); |
160 } | 162 } |
161 | 163 |
162 void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { | 164 void ChromotingHost::SetSharedSecret(const std::string& shared_secret) { |
163 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 165 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
164 session_manager_->set_authenticator_factory( | 166 shared_secret_ = shared_secret; |
165 new protocol::V1HostAuthenticatorFactory( | 167 have_shared_secret_ = true; |
166 key_pair_.GenerateCertificate(), key_pair_.private_key(), | 168 if (session_manager_.get()) { |
167 shared_secret)); | 169 session_manager_->set_authenticator_factory( |
| 170 new protocol::V1HostAuthenticatorFactory( |
| 171 key_pair_.GenerateCertificate(), key_pair_.private_key(), |
| 172 shared_secret_)); |
| 173 } |
168 } | 174 } |
169 | 175 |
170 //////////////////////////////////////////////////////////////////////////// | 176 //////////////////////////////////////////////////////////////////////////// |
171 // protocol::ClientSession::EventHandler implementation. | 177 // protocol::ClientSession::EventHandler implementation. |
172 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 178 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
173 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 179 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
174 | 180 |
175 // Disconnect all other clients. | 181 // Disconnect all other clients. |
176 // Iterate over a copy of the list of clients, to avoid mutating the list | 182 // Iterate over a copy of the list of clients, to avoid mutating the list |
177 // while iterating over it. | 183 // while iterating over it. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 LOG(INFO) << "Host connected as " << local_jid_; | 265 LOG(INFO) << "Host connected as " << local_jid_; |
260 | 266 |
261 // Create and start session manager. | 267 // Create and start session manager. |
262 protocol::JingleSessionManager* server = | 268 protocol::JingleSessionManager* server = |
263 new protocol::JingleSessionManager(context_->network_message_loop()); | 269 new protocol::JingleSessionManager(context_->network_message_loop()); |
264 | 270 |
265 server->Init(local_jid_, signal_strategy_.get(), | 271 server->Init(local_jid_, signal_strategy_.get(), |
266 this, allow_nat_traversal_); | 272 this, allow_nat_traversal_); |
267 | 273 |
268 session_manager_.reset(server); | 274 session_manager_.reset(server); |
| 275 if (have_shared_secret_) { |
| 276 session_manager_->set_authenticator_factory( |
| 277 new protocol::V1HostAuthenticatorFactory( |
| 278 key_pair_.GenerateCertificate(), key_pair_.private_key(), |
| 279 shared_secret_)); |
| 280 } |
269 | 281 |
270 for (StatusObserverList::iterator it = status_observers_.begin(); | 282 for (StatusObserverList::iterator it = status_observers_.begin(); |
271 it != status_observers_.end(); ++it) { | 283 it != status_observers_.end(); ++it) { |
272 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); | 284 (*it)->OnSignallingConnected(signal_strategy_.get(), local_jid_); |
273 } | 285 } |
274 } else if (state == SignalStrategy::StatusObserver::CLOSED) { | 286 } else if (state == SignalStrategy::StatusObserver::CLOSED) { |
275 LOG(INFO) << "Host disconnected from talk network."; | 287 LOG(INFO) << "Host disconnected from talk network."; |
276 for (StatusObserverList::iterator it = status_observers_.begin(); | 288 for (StatusObserverList::iterator it = status_observers_.begin(); |
277 it != status_observers_.end(); ++it) { | 289 it != status_observers_.end(); ++it) { |
278 (*it)->OnSignallingDisconnected(); | 290 (*it)->OnSignallingDisconnected(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 459 } |
448 | 460 |
449 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); | 461 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); |
450 it != shutdown_tasks_.end(); ++it) { | 462 it != shutdown_tasks_.end(); ++it) { |
451 it->Run(); | 463 it->Run(); |
452 } | 464 } |
453 shutdown_tasks_.clear(); | 465 shutdown_tasks_.clear(); |
454 } | 466 } |
455 | 467 |
456 } // namespace remoting | 468 } // namespace remoting |
OLD | NEW |