| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 173 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
| 174 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
| 175 | 175 |
| 176 login_backoff_.Reset(); | 176 login_backoff_.Reset(); |
| 177 | 177 |
| 178 // Disconnect all other clients. |it| should be advanced before Disconnect() | 178 // Disconnect all other clients. |it| should be advanced before Disconnect() |
| 179 // is called to avoid it becoming invalid when the client is removed from | 179 // is called to avoid it becoming invalid when the client is removed from |
| 180 // the list. | 180 // the list. |
| 181 ClientSessions::iterator it = clients_.begin(); | 181 ClientList::iterator it = clients_.begin(); |
| 182 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); | 182 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); |
| 183 while (it != clients_.end()) { | 183 while (it != clients_.end()) { |
| 184 ClientSession* other_client = it->get(); | 184 ClientSession* other_client = *it++; |
| 185 ++it; | |
| 186 if (other_client != client) { | 185 if (other_client != client) { |
| 187 other_client->DisconnectSession(protocol::OK); | 186 other_client->DisconnectSession(protocol::OK); |
| 188 | 187 |
| 189 // Quit if the host was destroyed. | 188 // Quit if the host was destroyed. |
| 190 if (!self) | 189 if (!self) |
| 191 return; | 190 return; |
| 192 } | 191 } |
| 193 } | 192 } |
| 194 | 193 |
| 195 // Disconnects above must have destroyed all other clients. | 194 // Disconnects above must have destroyed all other clients. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 214 DCHECK(CalledOnValidThread()); | 213 DCHECK(CalledOnValidThread()); |
| 215 | 214 |
| 216 // Notify observers. | 215 // Notify observers. |
| 217 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 216 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, |
| 218 OnAccessDenied(client->client_jid())); | 217 OnAccessDenied(client->client_jid())); |
| 219 } | 218 } |
| 220 | 219 |
| 221 void ChromotingHost::OnSessionClosed(ClientSession* client) { | 220 void ChromotingHost::OnSessionClosed(ClientSession* client) { |
| 222 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
| 223 | 222 |
| 224 ClientSessions::iterator it = | 223 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); |
| 225 std::find_if(clients_.begin(), clients_.end(), | |
| 226 [client](const std::unique_ptr<ClientSession>& item) { | |
| 227 return item.get() == client; | |
| 228 }); | |
| 229 CHECK(it != clients_.end()); | 224 CHECK(it != clients_.end()); |
| 230 | 225 |
| 231 bool was_authenticated = client->is_authenticated(); | 226 bool was_authenticated = client->is_authenticated(); |
| 232 std::string jid = client->client_jid(); | 227 std::string jid = client->client_jid(); |
| 233 clients_.erase(it); | 228 clients_.erase(it); |
| 229 delete client; |
| 234 | 230 |
| 235 if (was_authenticated) { | 231 if (was_authenticated) { |
| 236 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 232 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, |
| 237 OnClientDisconnected(jid)); | 233 OnClientDisconnected(jid)); |
| 238 } | 234 } |
| 239 } | 235 } |
| 240 | 236 |
| 241 void ChromotingHost::OnSessionRouteChange( | 237 void ChromotingHost::OnSessionRouteChange( |
| 242 ClientSession* session, | 238 ClientSession* session, |
| 243 const std::string& channel_name, | 239 const std::string& channel_name, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 273 connection.reset(new protocol::WebrtcConnectionToClient( | 269 connection.reset(new protocol::WebrtcConnectionToClient( |
| 274 base::WrapUnique(session), transport_context_, | 270 base::WrapUnique(session), transport_context_, |
| 275 video_encode_task_runner_, audio_task_runner_)); | 271 video_encode_task_runner_, audio_task_runner_)); |
| 276 } else { | 272 } else { |
| 277 connection.reset(new protocol::IceConnectionToClient( | 273 connection.reset(new protocol::IceConnectionToClient( |
| 278 base::WrapUnique(session), transport_context_, | 274 base::WrapUnique(session), transport_context_, |
| 279 video_encode_task_runner_, audio_task_runner_)); | 275 video_encode_task_runner_, audio_task_runner_)); |
| 280 } | 276 } |
| 281 | 277 |
| 282 // Create a ClientSession object. | 278 // Create a ClientSession object. |
| 283 clients_.push_back(base::MakeUnique<ClientSession>( | 279 ClientSession* client = new ClientSession( |
| 284 this, std::move(connection), desktop_environment_factory_, | 280 this, std::move(connection), desktop_environment_factory_, |
| 285 max_session_duration_, pairing_registry_, extensions_.get())); | 281 max_session_duration_, pairing_registry_, extensions_.get()); |
| 282 |
| 283 clients_.push_back(client); |
| 286 } | 284 } |
| 287 | 285 |
| 288 void ChromotingHost::DisconnectAllClients() { | 286 void ChromotingHost::DisconnectAllClients() { |
| 289 DCHECK(CalledOnValidThread()); | 287 DCHECK(CalledOnValidThread()); |
| 290 | 288 |
| 291 while (!clients_.empty()) { | 289 while (!clients_.empty()) { |
| 292 size_t size = clients_.size(); | 290 size_t size = clients_.size(); |
| 293 clients_.front()->DisconnectSession(protocol::OK); | 291 clients_.front()->DisconnectSession(protocol::OK); |
| 294 CHECK_EQ(clients_.size(), size - 1); | 292 CHECK_EQ(clients_.size(), size - 1); |
| 295 } | 293 } |
| 296 } | 294 } |
| 297 | 295 |
| 298 } // namespace remoting | 296 } // namespace remoting |
| OLD | NEW |