OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/setup/daemon_controller_delegate_win.h" | 5 #include "remoting/host/setup/daemon_controller_delegate_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Open the service and query its current state. | 91 // Open the service and query its current state. |
92 ScopedScHandle scmanager( | 92 ScopedScHandle scmanager( |
93 ::OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASE, | 93 ::OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASE, |
94 SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE)); | 94 SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE)); |
95 if (!scmanager.IsValid()) { | 95 if (!scmanager.IsValid()) { |
96 DWORD error = GetLastError(); | 96 DWORD error = GetLastError(); |
97 PLOG(ERROR) << "Failed to connect to the service control manager"; | 97 PLOG(ERROR) << "Failed to connect to the service control manager"; |
98 return error; | 98 return error; |
99 } | 99 } |
100 | 100 |
101 ScopedScHandle service( | 101 ScopedScHandle service(::OpenServiceW(scmanager.Get(), kWindowsServiceName, |
102 ::OpenServiceW(scmanager, kWindowsServiceName, SERVICE_QUERY_STATUS)); | 102 SERVICE_QUERY_STATUS)); |
103 if (!service.IsValid()) { | 103 if (!service.IsValid()) { |
104 DWORD error = GetLastError(); | 104 DWORD error = GetLastError(); |
105 if (error != ERROR_SERVICE_DOES_NOT_EXIST) { | 105 if (error != ERROR_SERVICE_DOES_NOT_EXIST) { |
106 PLOG(ERROR) << "Failed to open to the '" << kWindowsServiceName | 106 PLOG(ERROR) << "Failed to open to the '" << kWindowsServiceName |
107 << "' service"; | 107 << "' service"; |
108 } | 108 } |
109 return error; | 109 return error; |
110 } | 110 } |
111 | 111 |
112 service_out->Set(service.Take()); | 112 service_out->Set(service.Take()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return DaemonController::STATE_NOT_IMPLEMENTED; | 146 return DaemonController::STATE_NOT_IMPLEMENTED; |
147 } | 147 } |
148 // TODO(alexeypa): Make the thread alertable, so we can switch to APC | 148 // TODO(alexeypa): Make the thread alertable, so we can switch to APC |
149 // notifications rather than polling. | 149 // notifications rather than polling. |
150 ScopedScHandle service; | 150 ScopedScHandle service; |
151 DWORD error = OpenService(&service); | 151 DWORD error = OpenService(&service); |
152 | 152 |
153 switch (error) { | 153 switch (error) { |
154 case ERROR_SUCCESS: { | 154 case ERROR_SUCCESS: { |
155 SERVICE_STATUS status; | 155 SERVICE_STATUS status; |
156 if (::QueryServiceStatus(service, &status)) { | 156 if (::QueryServiceStatus(service.Get(), &status)) { |
157 return ConvertToDaemonState(status.dwCurrentState); | 157 return ConvertToDaemonState(status.dwCurrentState); |
158 } else { | 158 } else { |
159 PLOG(ERROR) << "Failed to query the state of the '" | 159 PLOG(ERROR) << "Failed to query the state of the '" |
160 << kWindowsServiceName << "' service"; | 160 << kWindowsServiceName << "' service"; |
161 return DaemonController::STATE_UNKNOWN; | 161 return DaemonController::STATE_UNKNOWN; |
162 } | 162 } |
163 break; | 163 break; |
164 } | 164 } |
165 case ERROR_SERVICE_DOES_NOT_EXIST: | 165 case ERROR_SERVICE_DOES_NOT_EXIST: |
166 return DaemonController::STATE_NOT_INSTALLED; | 166 return DaemonController::STATE_NOT_INSTALLED; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 InvokeCompletionCallback(done, hr); | 458 InvokeCompletionCallback(done, hr); |
459 } | 459 } |
460 | 460 |
461 scoped_refptr<DaemonController> DaemonController::Create() { | 461 scoped_refptr<DaemonController> DaemonController::Create() { |
462 scoped_ptr<DaemonController::Delegate> delegate( | 462 scoped_ptr<DaemonController::Delegate> delegate( |
463 new DaemonControllerDelegateWin()); | 463 new DaemonControllerDelegateWin()); |
464 return new DaemonController(delegate.Pass()); | 464 return new DaemonController(delegate.Pass()); |
465 } | 465 } |
466 | 466 |
467 } // namespace remoting | 467 } // namespace remoting |
OLD | NEW |