OLD | NEW |
1 // Copyright (c) 2012 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 "cloud_print/service/win/service_controller.h" | 5 #include "cloud_print/service/win/service_controller.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <atlctl.h> | 9 #include <atlctl.h> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 status.dwCurrentState > SERVICE_STOPPED) { | 107 status.dwCurrentState > SERVICE_STOPPED) { |
108 Sleep(500); | 108 Sleep(500); |
109 ::ControlService(service, SERVICE_CONTROL_STOP, &status); | 109 ::ControlService(service, SERVICE_CONTROL_STOP, &status); |
110 } | 110 } |
111 return S_OK; | 111 return S_OK; |
112 } | 112 } |
113 | 113 |
114 HRESULT ServiceController::InstallService(const string16& user, | 114 HRESULT ServiceController::InstallService(const string16& user, |
115 const string16& password, | 115 const string16& password, |
116 const std::string& run_switch, | 116 const std::string& run_switch, |
117 const base::FilePath& user_data_dir) { | 117 const base::FilePath& user_data_dir, |
| 118 bool auto_start) { |
118 // TODO(vitalybuka): consider "lite" version if we don't want unregister | 119 // TODO(vitalybuka): consider "lite" version if we don't want unregister |
119 // printers here. | 120 // printers here. |
120 HRESULT hr = UninstallService(); | 121 HRESULT hr = UninstallService(); |
121 if (FAILED(hr)) | 122 if (FAILED(hr)) |
122 return hr; | 123 return hr; |
123 | 124 |
124 hr = UpdateRegistryAppId(true); | 125 hr = UpdateRegistryAppId(true); |
125 if (FAILED(hr)) | 126 if (FAILED(hr)) |
126 return hr; | 127 return hr; |
127 | 128 |
(...skipping 17 matching lines...) Expand all Loading... |
145 } | 146 } |
146 | 147 |
147 ServiceHandle scm; | 148 ServiceHandle scm; |
148 hr = OpenServiceManager(&scm); | 149 hr = OpenServiceManager(&scm); |
149 if (FAILED(hr)) | 150 if (FAILED(hr)) |
150 return hr; | 151 return hr; |
151 | 152 |
152 ServiceHandle service( | 153 ServiceHandle service( |
153 ::CreateService( | 154 ::CreateService( |
154 scm, name_.c_str(), name_.c_str(), SERVICE_ALL_ACCESS, | 155 scm, name_.c_str(), name_.c_str(), SERVICE_ALL_ACCESS, |
155 SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, | 156 SERVICE_WIN32_OWN_PROCESS, |
156 command_line.GetCommandLineString().c_str(), NULL, NULL, NULL, | 157 auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START, |
157 user.empty() ? NULL : user.c_str(), | 158 SERVICE_ERROR_NORMAL, command_line.GetCommandLineString().c_str(), |
| 159 NULL, NULL, NULL, user.empty() ? NULL : user.c_str(), |
158 password.empty() ? NULL : password.c_str())); | 160 password.empty() ? NULL : password.c_str())); |
159 | 161 |
160 if (!service.IsValid()) { | 162 if (!service.IsValid()) { |
161 LOG(ERROR) << "Failed to install service as " << user << "."; | 163 LOG(ERROR) << "Failed to install service as " << user << "."; |
162 return HResultFromLastError(); | 164 return HResultFromLastError(); |
163 } | 165 } |
164 | 166 |
165 return S_OK; | 167 return S_OK; |
166 } | 168 } |
167 | 169 |
168 HRESULT ServiceController::UninstallService() { | 170 HRESULT ServiceController::UninstallService() { |
169 StopService(); | 171 StopService(); |
170 | 172 |
171 ServiceHandle service; | 173 ServiceHandle service; |
172 OpenService(name_, SERVICE_STOP | DELETE, &service); | 174 OpenService(name_, SERVICE_STOP | DELETE, &service); |
173 HRESULT hr = S_FALSE; | 175 HRESULT hr = S_FALSE; |
174 if (service) { | 176 if (service) { |
175 if (!::DeleteService(service)) { | 177 if (!::DeleteService(service)) { |
176 LOG(ERROR) << "Failed to uninstall service"; | 178 LOG(ERROR) << "Failed to uninstall service"; |
177 hr = HResultFromLastError(); | 179 hr = HResultFromLastError(); |
178 } | 180 } |
179 } | 181 } |
180 UpdateRegistryAppId(false); | 182 UpdateRegistryAppId(false); |
181 return hr; | 183 return hr; |
182 } | 184 } |
183 | 185 |
OLD | NEW |