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/win/wts_terminal_monitor.h" | 5 #include "remoting/host/win/wts_terminal_monitor.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wtsapi32.h> | 8 #include <wtsapi32.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Use the fast path if the caller wants to get id of the session attached to | 54 // Use the fast path if the caller wants to get id of the session attached to |
55 // the physical console. | 55 // the physical console. |
56 if (terminal_id == kConsole) | 56 if (terminal_id == kConsole) |
57 return WTSGetActiveConsoleSessionId(); | 57 return WTSGetActiveConsoleSessionId(); |
58 | 58 |
59 // Enumerate all sessions and try to match the client endpoint. | 59 // Enumerate all sessions and try to match the client endpoint. |
60 WTS_SESSION_INFO* session_info; | 60 WTS_SESSION_INFO* session_info; |
61 DWORD session_info_count; | 61 DWORD session_info_count; |
62 if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &session_info, | 62 if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &session_info, |
63 &session_info_count)) { | 63 &session_info_count)) { |
64 LOG_GETLASTERROR(ERROR) << "Failed to enumerate all sessions"; | 64 PLOG(ERROR) << "Failed to enumerate all sessions"; |
65 return kInvalidSessionId; | 65 return kInvalidSessionId; |
66 } | 66 } |
67 for (DWORD i = 0; i < session_info_count; ++i) { | 67 for (DWORD i = 0; i < session_info_count; ++i) { |
68 uint32 session_id = session_info[i].SessionId; | 68 uint32 session_id = session_info[i].SessionId; |
69 | 69 |
70 std::string id; | 70 std::string id; |
71 if (LookupTerminalId(session_id, &id) && terminal_id == id) { | 71 if (LookupTerminalId(session_id, &id) && terminal_id == id) { |
72 WTSFreeMemory(session_info); | 72 WTSFreeMemory(session_info); |
73 return session_id; | 73 return session_id; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 // |terminal_id| is not associated with any session. | 77 // |terminal_id| is not associated with any session. |
78 WTSFreeMemory(session_info); | 78 WTSFreeMemory(session_info); |
79 return kInvalidSessionId; | 79 return kInvalidSessionId; |
80 } | 80 } |
81 | 81 |
82 WtsTerminalMonitor::WtsTerminalMonitor() { | 82 WtsTerminalMonitor::WtsTerminalMonitor() { |
83 } | 83 } |
84 | 84 |
85 } // namespace remoting | 85 } // namespace remoting |
OLD | NEW |