| 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 // This file implements the Windows service controlling Me2Me host processes | 5 // This file implements the Windows service controlling Me2Me host processes |
| 6 // running within user sessions. | 6 // running within user sessions. |
| 7 | 7 |
| 8 #include "remoting/host/host_service_win.h" | 8 #include "remoting/host/host_service_win.h" |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <wtsapi32.h> | 11 #include <wtsapi32.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 | 13 |
| 14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
| 15 #include "base/base_paths.h" | 15 #include "base/base_paths.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/process_util.h" | |
| 23 #include "base/stringize_macros.h" | 22 #include "base/stringize_macros.h" |
| 24 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
| 25 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 26 #include "base/win/wrapped_window_proc.h" | 25 #include "base/win/wrapped_window_proc.h" |
| 27 | 26 |
| 28 #include "remoting/base/scoped_sc_handle_win.h" | 27 #include "remoting/base/scoped_sc_handle_win.h" |
| 29 #include "remoting/host/branding.h" | 28 #include "remoting/host/branding.h" |
| 30 #include "remoting/host/host_service_resource.h" | 29 #include "remoting/host/host_service_resource.h" |
| 31 #include "remoting/host/wts_console_observer_win.h" | 30 #include "remoting/host/wts_console_observer_win.h" |
| 32 #include "remoting/host/wts_session_process_launcher_win.h" | 31 #include "remoting/host/wts_session_process_launcher_win.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 int result = kErrorExitCode; | 247 int result = kErrorExitCode; |
| 249 | 248 |
| 250 // Subscribe to Ctrl-C and other console events. | 249 // Subscribe to Ctrl-C and other console events. |
| 251 if (!SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, TRUE)) { | 250 if (!SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, TRUE)) { |
| 252 LOG_GETLASTERROR(ERROR) | 251 LOG_GETLASTERROR(ERROR) |
| 253 << "Failed to set console control handler"; | 252 << "Failed to set console control handler"; |
| 254 return result; | 253 return result; |
| 255 } | 254 } |
| 256 | 255 |
| 257 // Create a window for receiving session change notifications. | 256 // Create a window for receiving session change notifications. |
| 258 LPCWSTR atom = NULL; | |
| 259 HWND window = NULL; | 257 HWND window = NULL; |
| 260 WNDPROC window_proc = | 258 WNDCLASSEX window_class; |
| 261 base::win::WrappedWindowProc<SessionChangeNotificationProc>; | 259 base::win::InitializeWindowClass( |
| 262 HINSTANCE instance = base::GetModuleFromAddress(window_proc); | 260 kSessionNotificationWindowClass, |
| 263 | 261 &base::win::WrappedWindowProc<SessionChangeNotificationProc>, |
| 264 WNDCLASSEX wc = {0}; | 262 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| 265 wc.cbSize = sizeof(wc); | 263 &window_class); |
| 266 wc.lpfnWndProc = window_proc; | 264 HINSTANCE instance = window_class.hInstance; |
| 267 wc.hInstance = instance; | 265 ATOM atom = RegisterClassExW(&window_class); |
| 268 wc.lpszClassName = kSessionNotificationWindowClass; | 266 if (atom == 0) { |
| 269 atom = reinterpret_cast<LPCWSTR>(RegisterClassExW(&wc)); | |
| 270 if (atom == NULL) { | |
| 271 LOG_GETLASTERROR(ERROR) | 267 LOG_GETLASTERROR(ERROR) |
| 272 << "Failed to register the window class '" | 268 << "Failed to register the window class '" |
| 273 << kSessionNotificationWindowClass << "'"; | 269 << kSessionNotificationWindowClass << "'"; |
| 274 goto cleanup; | 270 goto cleanup; |
| 275 } | 271 } |
| 276 | 272 |
| 277 window = CreateWindowW(atom, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance, 0); | 273 window = CreateWindowW(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, |
| 274 instance, 0); |
| 278 if (window == NULL) { | 275 if (window == NULL) { |
| 279 LOG_GETLASTERROR(ERROR) | 276 LOG_GETLASTERROR(ERROR) |
| 280 << "Failed to creat the session notificationwindow"; | 277 << "Failed to creat the session notificationwindow"; |
| 281 goto cleanup; | 278 goto cleanup; |
| 282 } | 279 } |
| 283 | 280 |
| 284 // Post a dummy session change notification to peek up the current console | 281 // Post a dummy session change notification to peek up the current console |
| 285 // session. | 282 // session. |
| 286 message_loop.PostTask(FROM_HERE, base::Bind( | 283 message_loop.PostTask(FROM_HERE, base::Bind( |
| 287 &HostService::OnSessionChange, base::Unretained(this))); | 284 &HostService::OnSessionChange, base::Unretained(this))); |
| 288 | 285 |
| 289 // Subscribe to session change notifications. | 286 // Subscribe to session change notifications. |
| 290 if (WTSRegisterSessionNotification(window, | 287 if (WTSRegisterSessionNotification(window, |
| 291 NOTIFY_FOR_ALL_SESSIONS) != FALSE) { | 288 NOTIFY_FOR_ALL_SESSIONS) != FALSE) { |
| 292 // Run the service. | 289 // Run the service. |
| 293 RunMessageLoop(); | 290 RunMessageLoop(); |
| 294 | 291 |
| 295 WTSUnRegisterSessionNotification(window); | 292 WTSUnRegisterSessionNotification(window); |
| 296 result = kSuccessExitCode; | 293 result = kSuccessExitCode; |
| 297 } | 294 } |
| 298 | 295 |
| 299 cleanup: | 296 cleanup: |
| 300 if (window != NULL) { | 297 if (window != NULL) { |
| 301 DestroyWindow(window); | 298 DestroyWindow(window); |
| 302 } | 299 } |
| 303 | 300 |
| 304 if (atom != 0) { | 301 if (atom != 0) { |
| 305 UnregisterClass(atom, instance); | 302 UnregisterClass(MAKEINTATOM(atom), instance); |
| 306 } | 303 } |
| 307 | 304 |
| 308 // Unsubscribe from console events. Ignore the exit code. There is nothing | 305 // Unsubscribe from console events. Ignore the exit code. There is nothing |
| 309 // we can do about it now and the program is about to exit anyway. Even if | 306 // we can do about it now and the program is about to exit anyway. Even if |
| 310 // it crashes nothing is going to be broken because of it. | 307 // it crashes nothing is going to be broken because of it. |
| 311 SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, FALSE); | 308 SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, FALSE); |
| 312 | 309 |
| 313 message_loop_ = NULL; | 310 message_loop_ = NULL; |
| 314 return result; | 311 return result; |
| 315 } | 312 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 434 } |
| 438 | 435 |
| 439 remoting::HostService* service = remoting::HostService::GetInstance(); | 436 remoting::HostService* service = remoting::HostService::GetInstance(); |
| 440 if (!service->InitWithCommandLine(command_line)) { | 437 if (!service->InitWithCommandLine(command_line)) { |
| 441 usage(argv[0]); | 438 usage(argv[0]); |
| 442 return kUsageExitCode; | 439 return kUsageExitCode; |
| 443 } | 440 } |
| 444 | 441 |
| 445 return service->Run(); | 442 return service->Run(); |
| 446 } | 443 } |
| OLD | NEW |