| 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/win/host_service.h" | 8 #include "remoting/host/win/host_service.h" |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 fprintf(stderr, kUsageMessage, program_name); | 84 fprintf(stderr, kUsageMessage, program_name); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 namespace remoting { | 89 namespace remoting { |
| 90 | 90 |
| 91 HostService::HostService() : | 91 HostService::HostService() : |
| 92 console_session_id_(kInvalidSessionId), | 92 console_session_id_(kInvalidSessionId), |
| 93 run_routine_(&HostService::RunAsService), | 93 run_routine_(&HostService::RunAsService), |
| 94 service_name_(kWindowsServiceName), | |
| 95 service_status_handle_(0), | 94 service_status_handle_(0), |
| 96 stopped_event_(true, false) { | 95 stopped_event_(true, false) { |
| 97 } | 96 } |
| 98 | 97 |
| 99 HostService::~HostService() { | 98 HostService::~HostService() { |
| 100 } | 99 } |
| 101 | 100 |
| 102 void HostService::AddWtsConsoleObserver(WtsConsoleObserver* observer) { | 101 void HostService::AddWtsConsoleObserver(WtsConsoleObserver* observer) { |
| 103 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 102 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 104 | 103 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 220 |
| 222 // Run the service. | 221 // Run the service. |
| 223 message_loop->Run(); | 222 message_loop->Run(); |
| 224 | 223 |
| 225 // Release the control handler. | 224 // Release the control handler. |
| 226 stopped_event_.Signal(); | 225 stopped_event_.Signal(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 int HostService::RunAsService() { | 228 int HostService::RunAsService() { |
| 230 SERVICE_TABLE_ENTRYW dispatch_table[] = { | 229 SERVICE_TABLE_ENTRYW dispatch_table[] = { |
| 231 { const_cast<LPWSTR>(service_name_.c_str()), &HostService::ServiceMain }, | 230 { const_cast<LPWSTR>(kWindowsServiceName), &HostService::ServiceMain }, |
| 232 { NULL, NULL } | 231 { NULL, NULL } |
| 233 }; | 232 }; |
| 234 | 233 |
| 235 if (!StartServiceCtrlDispatcherW(dispatch_table)) { | 234 if (!StartServiceCtrlDispatcherW(dispatch_table)) { |
| 236 LOG_GETLASTERROR(ERROR) | 235 LOG_GETLASTERROR(ERROR) |
| 237 << "Failed to connect to the service control manager"; | 236 << "Failed to connect to the service control manager"; |
| 238 return kErrorExitCode; | 237 return kErrorExitCode; |
| 239 } | 238 } |
| 240 | 239 |
| 241 return kSuccessExitCode; | 240 return kSuccessExitCode; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 340 |
| 342 VOID WINAPI HostService::ServiceMain(DWORD argc, WCHAR* argv[]) { | 341 VOID WINAPI HostService::ServiceMain(DWORD argc, WCHAR* argv[]) { |
| 343 MessageLoop message_loop; | 342 MessageLoop message_loop; |
| 344 | 343 |
| 345 // Allow other threads to post to our message loop. | 344 // Allow other threads to post to our message loop. |
| 346 HostService* self = HostService::GetInstance(); | 345 HostService* self = HostService::GetInstance(); |
| 347 self->main_task_runner_ = message_loop.message_loop_proxy(); | 346 self->main_task_runner_ = message_loop.message_loop_proxy(); |
| 348 | 347 |
| 349 // Register the service control handler. | 348 // Register the service control handler. |
| 350 self->service_status_handle_ = | 349 self->service_status_handle_ = |
| 351 RegisterServiceCtrlHandlerExW(self->service_name_.c_str(), | 350 RegisterServiceCtrlHandlerExW(kWindowsServiceName, |
| 352 &HostService::ServiceControlHandler, | 351 &HostService::ServiceControlHandler, |
| 353 self); | 352 self); |
| 354 if (self->service_status_handle_ == 0) { | 353 if (self->service_status_handle_ == 0) { |
| 355 LOG_GETLASTERROR(ERROR) | 354 LOG_GETLASTERROR(ERROR) |
| 356 << "Failed to register the service control handler"; | 355 << "Failed to register the service control handler"; |
| 357 return; | 356 return; |
| 358 } | 357 } |
| 359 | 358 |
| 360 // Report running status of the service. | 359 // Report running status of the service. |
| 361 SERVICE_STATUS service_status; | 360 SERVICE_STATUS service_status; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 440 } |
| 442 | 441 |
| 443 remoting::HostService* service = remoting::HostService::GetInstance(); | 442 remoting::HostService* service = remoting::HostService::GetInstance(); |
| 444 if (!service->InitWithCommandLine(command_line)) { | 443 if (!service->InitWithCommandLine(command_line)) { |
| 445 usage(argv[0]); | 444 usage(argv[0]); |
| 446 return kUsageExitCode; | 445 return kUsageExitCode; |
| 447 } | 446 } |
| 448 | 447 |
| 449 return service->Run(); | 448 return service->Run(); |
| 450 } | 449 } |
| OLD | NEW |