Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: cloud_print/service/win/cloud_print_service.cc

Issue 10459005: Fixed AppID registration. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cloud_print/service/win/cloud_print_service.rgs » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cloud_print/service/win/cloud_print_service.h" 5 #include "cloud_print/service/win/cloud_print_service.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <iostream> 8 #include <iostream>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CLOUDPRINTSERVICE, 142 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CLOUDPRINTSERVICE,
143 "{8013FB7C-2E3E-4992-B8BD-05C0C4AB0627}") 143 "{8013FB7C-2E3E-4992-B8BD-05C0C4AB0627}")
144 144
145 HRESULT InitializeSecurity() { 145 HRESULT InitializeSecurity() {
146 // TODO(gene): Check if we need to call CoInitializeSecurity and provide 146 // TODO(gene): Check if we need to call CoInitializeSecurity and provide
147 // the appropriate security settings for service. 147 // the appropriate security settings for service.
148 return S_OK; 148 return S_OK;
149 } 149 }
150 150
151 HRESULT Install(const FilePath& user_data_dir) { 151 HRESULT InstallService(const FilePath& user_data_dir) {
152 // TODO(vitalybuka): consider "lite" version if we don't want unregister 152 // TODO(vitalybuka): consider "lite" version if we don't want unregister
153 // printers here. 153 // printers here.
154 if (!Uninstall()) 154 HRESULT hr = UninstallService();
155 return E_FAIL; 155 if (FAILED(hr))
156 return hr;
157
158 hr = UpdateRegistryAppId(true);
159 if (FAILED(hr))
160 return hr;
156 161
157 FilePath service_path; 162 FilePath service_path;
158 CHECK(PathService::Get(base::FILE_EXE, &service_path)); 163 CHECK(PathService::Get(base::FILE_EXE, &service_path));
159 CommandLine command_line(service_path); 164 CommandLine command_line(service_path);
160 command_line.AppendSwitch(kServiceSwitch); 165 command_line.AppendSwitch(kServiceSwitch);
161 command_line.AppendSwitchPath(kUserDataDirSwitch, user_data_dir); 166 command_line.AppendSwitchPath(kUserDataDirSwitch, user_data_dir);
162 167
163 ServiceHandle scm; 168 ServiceHandle scm;
164 HRESULT hr = OpenServiceManager(&scm); 169 hr = OpenServiceManager(&scm);
165 if (FAILED(hr)) 170 if (FAILED(hr))
166 return hr; 171 return hr;
167 172
168 ServiceHandle service( 173 ServiceHandle service(
169 ::CreateService( 174 ::CreateService(
170 scm, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, 175 scm, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS,
171 SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, 176 SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
172 command_line.GetCommandLineString().c_str(), NULL, NULL, NULL, 177 command_line.GetCommandLineString().c_str(), NULL, NULL, NULL,
173 L"NT AUTHORITY\\LocalService", NULL)); 178 L"NT AUTHORITY\\LocalService", NULL));
174 179
175 if (!service.IsValid()) 180 if (!service.IsValid())
176 return HResultFromLastError(); 181 return HResultFromLastError();
177 182
178 return S_OK; 183 return S_OK;
179 } 184 }
180 185
186 HRESULT UninstallService() {
187 if (!Uninstall())
188 return E_FAIL;
189 return UpdateRegistryAppId(false);
190 }
191
181 bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode) { 192 bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode) {
182 CHECK(pnRetCode); 193 CHECK(pnRetCode);
183 CommandLine command_line(CommandLine::NO_PROGRAM); 194 CommandLine command_line(CommandLine::NO_PROGRAM);
184 command_line.ParseFromString(lpCmdLine); 195 command_line.ParseFromString(lpCmdLine);
185 bool is_service = false; 196 bool is_service = false;
186 *pnRetCode = ParseCommandLine(command_line, &is_service); 197 *pnRetCode = ParseCommandLine(command_line, &is_service);
187 if (FAILED(*pnRetCode)) { 198 if (FAILED(*pnRetCode)) {
188 LOG(ERROR) << "Operation failed. 0x" << std::setw(8) << 199 LOG(ERROR) << "Operation failed. 0x" << std::setw(8) <<
189 std::setbase(16) << *pnRetCode; 200 std::setbase(16) << *pnRetCode;
190 } 201 }
(...skipping 22 matching lines...) Expand all
213 private: 224 private:
214 HRESULT ParseCommandLine(const CommandLine& command_line, bool* is_service) { 225 HRESULT ParseCommandLine(const CommandLine& command_line, bool* is_service) {
215 if (!is_service) 226 if (!is_service)
216 return E_INVALIDARG; 227 return E_INVALIDARG;
217 *is_service = false; 228 *is_service = false;
218 229
219 if (command_line.HasSwitch(kStopSwitch)) 230 if (command_line.HasSwitch(kStopSwitch))
220 return StopService(); 231 return StopService();
221 232
222 if (command_line.HasSwitch(kUninstallSwitch)) 233 if (command_line.HasSwitch(kUninstallSwitch))
223 return Uninstall() ? S_OK : E_FAIL; 234 return UninstallService();
224 235
225 if (command_line.HasSwitch(kInstallSwitch)) { 236 if (command_line.HasSwitch(kInstallSwitch)) {
226 if (!command_line.HasSwitch(kUserDataDirSwitch)) { 237 if (!command_line.HasSwitch(kUserDataDirSwitch)) {
227 InvalidUsage(); 238 InvalidUsage();
228 return S_FALSE; 239 return S_FALSE;
229 } 240 }
230 241
231 FilePath data_dir = command_line.GetSwitchValuePath(kUserDataDirSwitch); 242 FilePath data_dir = command_line.GetSwitchValuePath(kUserDataDirSwitch);
232 HRESULT hr = ProcessServiceState(data_dir, 243 HRESULT hr = ProcessServiceState(data_dir,
233 command_line.HasSwitch(kQuietSwitch)); 244 command_line.HasSwitch(kQuietSwitch));
234 if (FAILED(hr)) 245 if (FAILED(hr))
235 return hr; 246 return hr;
236 hr = Install(data_dir); 247 hr = InstallService(data_dir);
237 if (SUCCEEDED(hr) && command_line.HasSwitch(kStartSwitch)) 248 if (SUCCEEDED(hr) && command_line.HasSwitch(kStartSwitch))
238 return StartService(); 249 return StartService();
239 250
240 return hr; 251 return hr;
241 } 252 }
242 253
243 if (command_line.HasSwitch(kStartSwitch)) 254 if (command_line.HasSwitch(kStartSwitch))
244 return StartService(); 255 return StartService();
245 256
246 if (command_line.HasSwitch(kServiceSwitch)) { 257 if (command_line.HasSwitch(kServiceSwitch)) {
(...skipping 20 matching lines...) Expand all
267 std::cout << file.value() << ":\n"; 278 std::cout << file.value() << ":\n";
268 std::cout << contents << "\n"; 279 std::cout << contents << "\n";
269 } 280 }
270 281
271 if (!is_valid) 282 if (!is_valid)
272 LOG(ERROR) << "Invalid file: " << file.value(); 283 LOG(ERROR) << "Invalid file: " << file.value();
273 284
274 if (quiet) 285 if (quiet)
275 return is_valid ? S_OK : HRESULT_FROM_WIN32(ERROR_FILE_INVALID); 286 return is_valid ? S_OK : HRESULT_FROM_WIN32(ERROR_FILE_INVALID);
276 287
277 std::cout << "Do you want to use this file [y/n]:"; 288 if (!contents.empty()) {
278 for (;;) { 289 std::cout << "Do you want to use this file [y/n]:";
279 std::string input; 290 for (;;) {
280 std::getline(std::cin, input); 291 std::string input;
281 StringToLowerASCII(&input); 292 std::getline(std::cin, input);
282 if (input == "y") { 293 StringToLowerASCII(&input);
283 return S_OK; 294 if (input == "y") {
284 } else if (input == "n") { 295 return S_OK;
285 is_valid = false; 296 } else if (input == "n") {
286 break; 297 is_valid = false;
298 break;
299 }
287 } 300 }
288 } 301 }
289 302
290 while (!is_valid) { 303 while (!is_valid) {
291 std::string email = GetOption("email", service_state.email(), false); 304 std::string email = GetOption("email", service_state.email(), false);
292 std::string password = GetOption("password", "", true); 305 std::string password = GetOption("password", "", true);
293 std::string proxy_id = GetOption("connector_id", 306 std::string proxy_id = GetOption("connector_id",
294 service_state.proxy_id(), false); 307 service_state.proxy_id(), false);
295 is_valid = service_state.Configure(email, password, proxy_id); 308 is_valid = service_state.Configure(email, password, proxy_id);
296 if (is_valid) { 309 if (is_valid) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 379
367 FilePath user_data_dir_; 380 FilePath user_data_dir_;
368 }; 381 };
369 382
370 CloudPrintServiceModule _AtlModule; 383 CloudPrintServiceModule _AtlModule;
371 384
372 int main() { 385 int main() {
373 base::AtExitManager at_exit; 386 base::AtExitManager at_exit;
374 return _AtlModule.WinMain(0); 387 return _AtlModule.WinMain(0);
375 } 388 }
OLDNEW
« no previous file with comments | « no previous file | cloud_print/service/win/cloud_print_service.rgs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698