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/daemon_process.h" | 5 #include "remoting/host/daemon_process.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 next_terminal_id_(0), | 167 next_terminal_id_(0), |
168 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 168 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
169 DCHECK(caller_task_runner->BelongsToCurrentThread()); | 169 DCHECK(caller_task_runner->BelongsToCurrentThread()); |
170 } | 170 } |
171 | 171 |
172 void DaemonProcess::CreateDesktopSession(int terminal_id, | 172 void DaemonProcess::CreateDesktopSession(int terminal_id, |
173 const DesktopSessionParams& params, | 173 const DesktopSessionParams& params, |
174 bool virtual_terminal) { | 174 bool virtual_terminal) { |
175 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 175 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
176 | 176 |
| 177 // Terminal IDs cannot be reused. Update the expected next terminal ID. |
| 178 next_terminal_id_ = std::max(next_terminal_id_, terminal_id + 1); |
| 179 |
177 // Validate the supplied terminal ID. An attempt to create a desktop session | 180 // Validate the supplied terminal ID. An attempt to create a desktop session |
178 // with an ID that could possibly have been allocated already is considered | 181 // with an ID that could possibly have been allocated already is considered |
179 // a protocol error and the network process will be restarted. | 182 // a protocol error and the network process will be restarted. |
180 if (IsTerminalIdKnown(terminal_id)) { | 183 if (IsTerminalIdKnown(terminal_id)) { |
181 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; | 184 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; |
182 CrashNetworkProcess(FROM_HERE); | 185 CrashNetworkProcess(FROM_HERE); |
183 return; | 186 return; |
184 } | 187 } |
185 | 188 |
186 // Validate |params|. | 189 // Validate |params|. |
187 if (params.client_dpi_.x() < 0 || params.client_dpi_.y() < 0) { | 190 if (params.client_dpi_.x() < 0 || params.client_dpi_.y() < 0) { |
188 LOG(ERROR) << "Invalid DPI of the remote screen specified: " | 191 LOG(ERROR) << "Invalid DPI of the remote screen specified: " |
189 << params.client_dpi_; | 192 << params.client_dpi_; |
190 SendToNetwork( | 193 SendToNetwork( |
191 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); | 194 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); |
192 return; | 195 return; |
193 } | 196 } |
194 if (params.client_size_.width() < 0 || params.client_size_.height() < 0) { | 197 if (params.client_size_.width() < 0 || params.client_size_.height() < 0) { |
195 LOG(ERROR) << "Invalid resolution of the remote screen specified: " | 198 LOG(ERROR) << "Invalid resolution of the remote screen specified: " |
196 << params.client_size_; | 199 << params.client_size_; |
197 SendToNetwork( | 200 SendToNetwork( |
198 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); | 201 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); |
199 return; | 202 return; |
200 } | 203 } |
201 | 204 |
202 // Create the desktop session. | 205 // Create the desktop session. |
203 scoped_ptr<DesktopSession> session = DoCreateDesktopSession( | 206 scoped_ptr<DesktopSession> session = DoCreateDesktopSession( |
204 terminal_id, params, virtual_terminal); | 207 terminal_id, params, virtual_terminal); |
205 if (session) { | 208 if (!session) { |
206 VLOG(1) << "Daemon: opened desktop session " << terminal_id; | |
207 desktop_sessions_.push_back(session.release()); | |
208 } else { | |
209 LOG(ERROR) << "Failed to create a desktop session."; | 209 LOG(ERROR) << "Failed to create a desktop session."; |
210 SendToNetwork( | 210 SendToNetwork( |
211 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); | 211 new ChromotingDaemonNetworkMsg_TerminalDisconnected(terminal_id)); |
212 return; | 212 return; |
213 } | 213 } |
214 | 214 |
215 // Update the expected terminal ID. | 215 VLOG(1) << "Daemon: opened desktop session " << terminal_id; |
216 next_terminal_id_ = std::max(next_terminal_id_, terminal_id + 1); | 216 desktop_sessions_.push_back(session.release()); |
217 } | 217 } |
218 | 218 |
219 void DaemonProcess::CrashNetworkProcess( | 219 void DaemonProcess::CrashNetworkProcess( |
220 const tracked_objects::Location& location) { | 220 const tracked_objects::Location& location) { |
221 SendToNetwork(new ChromotingDaemonNetworkMsg_Crash( | 221 SendToNetwork(new ChromotingDaemonNetworkMsg_Crash( |
222 location.function_name(), location.file_name(), location.line_number())); | 222 location.function_name(), location.file_name(), location.line_number())); |
223 | 223 |
224 DeleteAllDesktopSessions(); | 224 DeleteAllDesktopSessions(); |
225 } | 225 } |
226 | 226 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 343 } |
344 | 344 |
345 void DaemonProcess::DeleteAllDesktopSessions() { | 345 void DaemonProcess::DeleteAllDesktopSessions() { |
346 while (!desktop_sessions_.empty()) { | 346 while (!desktop_sessions_.empty()) { |
347 delete desktop_sessions_.front(); | 347 delete desktop_sessions_.front(); |
348 desktop_sessions_.pop_front(); | 348 desktop_sessions_.pop_front(); |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 } // namespace remoting | 352 } // namespace remoting |
OLD | NEW |