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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return; | 170 return; |
171 } | 171 } |
172 login_backoff_.InformOfRequest(false); | 172 login_backoff_.InformOfRequest(false); |
173 } | 173 } |
174 | 174 |
175 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 175 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
176 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
177 | 177 |
178 login_backoff_.Reset(); | 178 login_backoff_.Reset(); |
179 | 179 |
180 // Disconnect all other clients. |it| should be advanced before Disconnect() | 180 // Disconnect all clients, except |client|. |
181 // is called to avoid it becoming invalid when the client is removed from | |
182 // the list. | |
183 ClientList::iterator it = clients_.begin(); | |
184 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); | 181 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); |
185 while (it != clients_.end()) { | 182 while (clients_.size() > 1) { |
186 ClientSession* other_client = *it++; | 183 clients_[(clients_.front().get() == client) ? 1 : 0]->DisconnectSession( |
187 if (other_client != client) { | 184 protocol::OK); |
188 other_client->DisconnectSession(protocol::OK); | |
189 | 185 |
190 // Quit if the host was destroyed. | 186 // Quit if the host was destroyed. |
191 if (!self) | 187 if (!self) |
192 return; | 188 return; |
193 } | |
194 } | 189 } |
195 | 190 |
196 // Disconnects above must have destroyed all other clients. | 191 // Disconnects above must have destroyed all other clients. |
197 DCHECK_EQ(clients_.size(), 1U); | 192 DCHECK_EQ(clients_.size(), 1U); |
| 193 DCHECK(clients_.front().get() == client); |
198 | 194 |
199 // Notify observers that there is at least one authenticated client. | 195 // Notify observers that there is at least one authenticated client. |
200 const std::string& jid = client->client_jid(); | |
201 | |
202 for (auto& observer : status_observers_) | 196 for (auto& observer : status_observers_) |
203 observer.OnClientAuthenticated(jid); | 197 observer.OnClientAuthenticated(client->client_jid()); |
204 } | 198 } |
205 | 199 |
206 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { | 200 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { |
207 DCHECK(CalledOnValidThread()); | 201 DCHECK(CalledOnValidThread()); |
208 | 202 |
209 // Notify observers. | 203 // Notify observers. |
210 for (auto& observer : status_observers_) | 204 for (auto& observer : status_observers_) |
211 observer.OnClientConnected(client->client_jid()); | 205 observer.OnClientConnected(client->client_jid()); |
212 } | 206 } |
213 | 207 |
214 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { | 208 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { |
215 DCHECK(CalledOnValidThread()); | 209 DCHECK(CalledOnValidThread()); |
216 | 210 |
217 // Notify observers. | 211 // Notify observers. |
218 for (auto& observer : status_observers_) | 212 for (auto& observer : status_observers_) |
219 observer.OnAccessDenied(client->client_jid()); | 213 observer.OnAccessDenied(client->client_jid()); |
220 } | 214 } |
221 | 215 |
222 void ChromotingHost::OnSessionClosed(ClientSession* client) { | 216 void ChromotingHost::OnSessionClosed(ClientSession* client) { |
223 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
224 | 218 |
225 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); | 219 ClientSessions::iterator it = |
| 220 std::find_if(clients_.begin(), clients_.end(), |
| 221 [client](const std::unique_ptr<ClientSession>& item) { |
| 222 return item.get() == client; |
| 223 }); |
226 CHECK(it != clients_.end()); | 224 CHECK(it != clients_.end()); |
227 | 225 |
228 bool was_authenticated = client->is_authenticated(); | 226 bool was_authenticated = client->is_authenticated(); |
229 std::string jid = client->client_jid(); | 227 std::string jid = client->client_jid(); |
230 clients_.erase(it); | 228 clients_.erase(it); |
231 delete client; | |
232 | 229 |
233 if (was_authenticated) { | 230 if (was_authenticated) { |
234 for (auto& observer : status_observers_) | 231 for (auto& observer : status_observers_) |
235 observer.OnClientDisconnected(jid); | 232 observer.OnClientDisconnected(jid); |
236 } | 233 } |
237 } | 234 } |
238 | 235 |
239 void ChromotingHost::OnSessionRouteChange( | 236 void ChromotingHost::OnSessionRouteChange( |
240 ClientSession* session, | 237 ClientSession* session, |
241 const std::string& channel_name, | 238 const std::string& channel_name, |
(...skipping 28 matching lines...) Expand all Loading... |
270 connection.reset(new protocol::WebrtcConnectionToClient( | 267 connection.reset(new protocol::WebrtcConnectionToClient( |
271 base::WrapUnique(session), transport_context_, | 268 base::WrapUnique(session), transport_context_, |
272 video_encode_task_runner_, audio_task_runner_)); | 269 video_encode_task_runner_, audio_task_runner_)); |
273 } else { | 270 } else { |
274 connection.reset(new protocol::IceConnectionToClient( | 271 connection.reset(new protocol::IceConnectionToClient( |
275 base::WrapUnique(session), transport_context_, | 272 base::WrapUnique(session), transport_context_, |
276 video_encode_task_runner_, audio_task_runner_)); | 273 video_encode_task_runner_, audio_task_runner_)); |
277 } | 274 } |
278 | 275 |
279 // Create a ClientSession object. | 276 // Create a ClientSession object. |
280 ClientSession* client = new ClientSession( | 277 clients_.push_back(base::MakeUnique<ClientSession>( |
281 this, std::move(connection), desktop_environment_factory_, | 278 this, std::move(connection), desktop_environment_factory_, |
282 max_session_duration_, pairing_registry_, extensions_.get()); | 279 max_session_duration_, pairing_registry_, extensions_.get())); |
283 | |
284 clients_.push_back(client); | |
285 } | 280 } |
286 | 281 |
287 void ChromotingHost::DisconnectAllClients() { | 282 void ChromotingHost::DisconnectAllClients() { |
288 DCHECK(CalledOnValidThread()); | 283 DCHECK(CalledOnValidThread()); |
289 | 284 |
290 while (!clients_.empty()) { | 285 while (!clients_.empty()) { |
291 size_t size = clients_.size(); | 286 size_t size = clients_.size(); |
292 clients_.front()->DisconnectSession(protocol::OK); | 287 clients_.front()->DisconnectSession(protocol::OK); |
293 CHECK_EQ(clients_.size(), size - 1); | 288 CHECK_EQ(clients_.size(), size - 1); |
294 } | 289 } |
295 } | 290 } |
296 | 291 |
297 } // namespace remoting | 292 } // namespace remoting |
OLD | NEW |