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 "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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (!service_manager) | 54 if (!service_manager) |
55 return E_POINTER; | 55 return E_POINTER; |
56 | 56 |
57 service_manager->Set(::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)); | 57 service_manager->Set(::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)); |
58 if (!service_manager->IsValid()) | 58 if (!service_manager->IsValid()) |
59 return cloud_print::GetLastHResult(); | 59 return cloud_print::GetLastHResult(); |
60 | 60 |
61 return S_OK; | 61 return S_OK; |
62 } | 62 } |
63 | 63 |
64 HRESULT OpenService(const string16& name, DWORD access, | 64 HRESULT OpenService(const base::string16& name, DWORD access, |
65 ServiceHandle* service) { | 65 ServiceHandle* service) { |
66 if (!service) | 66 if (!service) |
67 return E_POINTER; | 67 return E_POINTER; |
68 | 68 |
69 ServiceHandle scm; | 69 ServiceHandle scm; |
70 HRESULT hr = OpenServiceManager(&scm); | 70 HRESULT hr = OpenServiceManager(&scm); |
71 if (FAILED(hr)) | 71 if (FAILED(hr)) |
72 return hr; | 72 return hr; |
73 | 73 |
74 service->Set(::OpenService(scm, name.c_str(), access)); | 74 service->Set(::OpenService(scm, name.c_str(), access)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 return S_OK; | 122 return S_OK; |
123 } | 123 } |
124 | 124 |
125 base::FilePath ServiceController::GetBinary() const { | 125 base::FilePath ServiceController::GetBinary() const { |
126 base::FilePath service_path; | 126 base::FilePath service_path; |
127 CHECK(PathService::Get(base::FILE_EXE, &service_path)); | 127 CHECK(PathService::Get(base::FILE_EXE, &service_path)); |
128 return service_path.DirName().Append(base::FilePath(kServiceExeName)); | 128 return service_path.DirName().Append(base::FilePath(kServiceExeName)); |
129 } | 129 } |
130 | 130 |
131 HRESULT ServiceController::InstallConnectorService( | 131 HRESULT ServiceController::InstallConnectorService( |
132 const string16& user, | 132 const base::string16& user, |
133 const string16& password, | 133 const base::string16& password, |
134 const base::FilePath& user_data_dir, | 134 const base::FilePath& user_data_dir, |
135 bool enable_logging) { | 135 bool enable_logging) { |
136 return InstallService(user, password, true, kServiceSwitch, user_data_dir, | 136 return InstallService(user, password, true, kServiceSwitch, user_data_dir, |
137 enable_logging); | 137 enable_logging); |
138 } | 138 } |
139 | 139 |
140 HRESULT ServiceController::InstallCheckService( | 140 HRESULT ServiceController::InstallCheckService( |
141 const string16& user, | 141 const base::string16& user, |
142 const string16& password, | 142 const base::string16& password, |
143 const base::FilePath& user_data_dir) { | 143 const base::FilePath& user_data_dir) { |
144 return InstallService(user, password, false, kRequirementsSwitch, | 144 return InstallService(user, password, false, kRequirementsSwitch, |
145 user_data_dir, true); | 145 user_data_dir, true); |
146 } | 146 } |
147 | 147 |
148 HRESULT ServiceController::InstallService(const string16& user, | 148 HRESULT ServiceController::InstallService(const base::string16& user, |
149 const string16& password, | 149 const base::string16& password, |
150 bool auto_start, | 150 bool auto_start, |
151 const std::string& run_switch, | 151 const std::string& run_switch, |
152 const base::FilePath& user_data_dir, | 152 const base::FilePath& user_data_dir, |
153 bool enable_logging) { | 153 bool enable_logging) { |
154 // TODO(vitalybuka): consider "lite" version if we don't want unregister | 154 // TODO(vitalybuka): consider "lite" version if we don't want unregister |
155 // printers here. | 155 // printers here. |
156 HRESULT hr = UninstallService(); | 156 HRESULT hr = UninstallService(); |
157 if (FAILED(hr)) | 157 if (FAILED(hr)) |
158 return hr; | 158 return hr; |
159 | 159 |
(...skipping 26 matching lines...) Expand all Loading... |
186 } | 186 } |
187 } else { | 187 } else { |
188 LOG(ERROR) << "Failed to open security policy."; | 188 LOG(ERROR) << "Failed to open security policy."; |
189 } | 189 } |
190 | 190 |
191 ServiceHandle scm; | 191 ServiceHandle scm; |
192 hr = OpenServiceManager(&scm); | 192 hr = OpenServiceManager(&scm); |
193 if (FAILED(hr)) | 193 if (FAILED(hr)) |
194 return hr; | 194 return hr; |
195 | 195 |
196 string16 display_name = | 196 base::string16 display_name = |
197 cloud_print::LoadLocalString(IDS_SERVICE_DISPLAY_NAME); | 197 cloud_print::LoadLocalString(IDS_SERVICE_DISPLAY_NAME); |
198 ServiceHandle service( | 198 ServiceHandle service( |
199 ::CreateService( | 199 ::CreateService( |
200 scm, name_.c_str(), display_name.c_str(), SERVICE_ALL_ACCESS, | 200 scm, name_.c_str(), display_name.c_str(), SERVICE_ALL_ACCESS, |
201 SERVICE_WIN32_OWN_PROCESS, | 201 SERVICE_WIN32_OWN_PROCESS, |
202 auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START, | 202 auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START, |
203 SERVICE_ERROR_NORMAL, command_line.GetCommandLineString().c_str(), | 203 SERVICE_ERROR_NORMAL, command_line.GetCommandLineString().c_str(), |
204 NULL, NULL, NULL, user.empty() ? NULL : user.c_str(), | 204 NULL, NULL, NULL, user.empty() ? NULL : user.c_str(), |
205 password.empty() ? NULL : password.c_str())); | 205 password.empty() ? NULL : password.c_str())); |
206 | 206 |
207 if (!service.IsValid()) { | 207 if (!service.IsValid()) { |
208 LOG(ERROR) << "Failed to install service as " << user << "."; | 208 LOG(ERROR) << "Failed to install service as " << user << "."; |
209 return cloud_print::GetLastHResult(); | 209 return cloud_print::GetLastHResult(); |
210 } | 210 } |
211 | 211 |
212 string16 description_string = | 212 base::string16 description_string = |
213 cloud_print::LoadLocalString(IDS_SERVICE_DESCRIPTION); | 213 cloud_print::LoadLocalString(IDS_SERVICE_DESCRIPTION); |
214 SERVICE_DESCRIPTION description = {0}; | 214 SERVICE_DESCRIPTION description = {0}; |
215 description.lpDescription = const_cast<wchar_t*>(description_string.c_str()); | 215 description.lpDescription = const_cast<wchar_t*>(description_string.c_str()); |
216 ::ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description); | 216 ::ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description); |
217 | 217 |
218 return S_OK; | 218 return S_OK; |
219 } | 219 } |
220 | 220 |
221 HRESULT ServiceController::UninstallService() { | 221 HRESULT ServiceController::UninstallService() { |
222 StopService(); | 222 StopService(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 state_ = STATE_NOT_FOUND; | 307 state_ = STATE_NOT_FOUND; |
308 return; | 308 return; |
309 } | 309 } |
310 is_logging_enabled_ = command_line_.HasSwitch(switches::kEnableLogging); | 310 is_logging_enabled_ = command_line_.HasSwitch(switches::kEnableLogging); |
311 user_ = config->lpServiceStartName; | 311 user_ = config->lpServiceStartName; |
312 } | 312 } |
313 | 313 |
314 bool ServiceController::is_logging_enabled() const { | 314 bool ServiceController::is_logging_enabled() const { |
315 return command_line_.HasSwitch(switches::kEnableLogging); | 315 return command_line_.HasSwitch(switches::kEnableLogging); |
316 } | 316 } |
OLD | NEW |