| 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> |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 int result = kErrorExitCode; | 248 int result = kErrorExitCode; |
| 249 | 249 |
| 250 // Subscribe to Ctrl-C and other console events. | 250 // Subscribe to Ctrl-C and other console events. |
| 251 if (!SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, TRUE)) { | 251 if (!SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, TRUE)) { |
| 252 LOG_GETLASTERROR(ERROR) | 252 LOG_GETLASTERROR(ERROR) |
| 253 << "Failed to set console control handler"; | 253 << "Failed to set console control handler"; |
| 254 return result; | 254 return result; |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Create a window for receiving session change notifications. | 257 // Create a window for receiving session change notifications. |
| 258 LPCWSTR atom = NULL; | |
| 259 HWND window = NULL; | 258 HWND window = NULL; |
| 260 WNDPROC window_proc = | 259 WNDCLASSEX window_class; |
| 261 base::win::WrappedWindowProc<SessionChangeNotificationProc>; | 260 base::win::InitializeWindowClass( |
| 262 HINSTANCE instance = base::GetModuleFromAddress(window_proc); | 261 &window_class, |
| 263 | 262 kSessionNotificationWindowClass, |
| 264 WNDCLASSEX wc = {0}; | 263 &base::win::WrappedWindowProc<SessionChangeNotificationProc>, |
| 265 wc.cbSize = sizeof(wc); | 264 0, 0, 0, NULL, NULL, NULL, NULL, NULL); |
| 266 wc.lpfnWndProc = window_proc; | 265 HINSTANCE instance = window_class.hInstance; |
| 267 wc.hInstance = instance; | 266 ATOM atom = RegisterClassExW(&window_class); |
| 268 wc.lpszClassName = kSessionNotificationWindowClass; | 267 if (atom == 0) { |
| 269 atom = reinterpret_cast<LPCWSTR>(RegisterClassExW(&wc)); | |
| 270 if (atom == NULL) { | |
| 271 LOG_GETLASTERROR(ERROR) | 268 LOG_GETLASTERROR(ERROR) |
| 272 << "Failed to register the window class '" | 269 << "Failed to register the window class '" |
| 273 << kSessionNotificationWindowClass << "'"; | 270 << kSessionNotificationWindowClass << "'"; |
| 274 goto cleanup; | 271 goto cleanup; |
| 275 } | 272 } |
| 276 | 273 |
| 277 window = CreateWindowW(atom, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance, 0); | 274 window = CreateWindowW(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, |
| 275 instance, 0); |
| 278 if (window == NULL) { | 276 if (window == NULL) { |
| 279 LOG_GETLASTERROR(ERROR) | 277 LOG_GETLASTERROR(ERROR) |
| 280 << "Failed to creat the session notificationwindow"; | 278 << "Failed to creat the session notificationwindow"; |
| 281 goto cleanup; | 279 goto cleanup; |
| 282 } | 280 } |
| 283 | 281 |
| 284 // Post a dummy session change notification to peek up the current console | 282 // Post a dummy session change notification to peek up the current console |
| 285 // session. | 283 // session. |
| 286 message_loop.PostTask(FROM_HERE, base::Bind( | 284 message_loop.PostTask(FROM_HERE, base::Bind( |
| 287 &HostService::OnSessionChange, base::Unretained(this))); | 285 &HostService::OnSessionChange, base::Unretained(this))); |
| 288 | 286 |
| 289 // Subscribe to session change notifications. | 287 // Subscribe to session change notifications. |
| 290 if (WTSRegisterSessionNotification(window, | 288 if (WTSRegisterSessionNotification(window, |
| 291 NOTIFY_FOR_ALL_SESSIONS) != FALSE) { | 289 NOTIFY_FOR_ALL_SESSIONS) != FALSE) { |
| 292 // Run the service. | 290 // Run the service. |
| 293 RunMessageLoop(); | 291 RunMessageLoop(); |
| 294 | 292 |
| 295 WTSUnRegisterSessionNotification(window); | 293 WTSUnRegisterSessionNotification(window); |
| 296 result = kSuccessExitCode; | 294 result = kSuccessExitCode; |
| 297 } | 295 } |
| 298 | 296 |
| 299 cleanup: | 297 cleanup: |
| 300 if (window != NULL) { | 298 if (window != NULL) { |
| 301 DestroyWindow(window); | 299 DestroyWindow(window); |
| 302 } | 300 } |
| 303 | 301 |
| 304 if (atom != 0) { | 302 if (atom != 0) { |
| 305 UnregisterClass(atom, instance); | 303 UnregisterClass(MAKEINTATOM(atom), instance); |
| 306 } | 304 } |
| 307 | 305 |
| 308 // Unsubscribe from console events. Ignore the exit code. There is nothing | 306 // 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 | 307 // 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. | 308 // it crashes nothing is going to be broken because of it. |
| 311 SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, FALSE); | 309 SetConsoleCtrlHandler(&HostService::ConsoleControlHandler, FALSE); |
| 312 | 310 |
| 313 message_loop_ = NULL; | 311 message_loop_ = NULL; |
| 314 return result; | 312 return result; |
| 315 } | 313 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 435 } |
| 438 | 436 |
| 439 remoting::HostService* service = remoting::HostService::GetInstance(); | 437 remoting::HostService* service = remoting::HostService::GetInstance(); |
| 440 if (!service->InitWithCommandLine(command_line)) { | 438 if (!service->InitWithCommandLine(command_line)) { |
| 441 usage(argv[0]); | 439 usage(argv[0]); |
| 442 return kUsageExitCode; | 440 return kUsageExitCode; |
| 443 } | 441 } |
| 444 | 442 |
| 445 return service->Run(); | 443 return service->Run(); |
| 446 } | 444 } |
| OLD | NEW |