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

Side by Side Diff: cloud_print/virtual_driver/win/install/setup.cc

Issue 12294008: Fix more remaining FilePath -> base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 <iomanip> 5 #include <iomanip>
6 #include <windows.h> 6 #include <windows.h>
7 #include <winspool.h> 7 #include <winspool.h>
8 #include <setupapi.h> // Must be included after windows.h 8 #include <setupapi.h> // Must be included after windows.h
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, 80 if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
81 DELETE) != ERROR_SUCCESS) { 81 DELETE) != ERROR_SUCCESS) {
82 LOG(ERROR) << "Unable to open key to delete"; 82 LOG(ERROR) << "Unable to open key to delete";
83 return; 83 return;
84 } 84 }
85 if (key.DeleteKey(L"") != ERROR_SUCCESS) { 85 if (key.DeleteKey(L"") != ERROR_SUCCESS) {
86 LOG(ERROR) << "Unable to delete key"; 86 LOG(ERROR) << "Unable to delete key";
87 } 87 }
88 } 88 }
89 89
90 FilePath GetSystemPath(const string16& binary) { 90 base::FilePath GetSystemPath(const string16& binary) {
91 FilePath path; 91 base::FilePath path;
92 if (!PathService::Get(base::DIR_SYSTEM, &path)) { 92 if (!PathService::Get(base::DIR_SYSTEM, &path)) {
93 LOG(ERROR) << "Unable to get system path."; 93 LOG(ERROR) << "Unable to get system path.";
94 return path; 94 return path;
95 } 95 }
96 return path.Append(binary); 96 return path.Append(binary);
97 } 97 }
98 98
99 FilePath GetNativeSystemPath(const string16& binary) { 99 base::FilePath GetNativeSystemPath(const string16& binary) {
100 if (!cloud_print::IsSystem64Bit()) 100 if (!cloud_print::IsSystem64Bit())
101 return GetSystemPath(binary); 101 return GetSystemPath(binary);
102 FilePath path; 102 base::FilePath path;
103 // Sysnative will bypass filesystem redirection and give us 103 // Sysnative will bypass filesystem redirection and give us
104 // the location of the 64bit system32 from a 32 bit process. 104 // the location of the 64bit system32 from a 32 bit process.
105 if (!PathService::Get(base::DIR_WINDOWS, &path)) { 105 if (!PathService::Get(base::DIR_WINDOWS, &path)) {
106 LOG(ERROR) << "Unable to get windows path."; 106 LOG(ERROR) << "Unable to get windows path.";
107 return path; 107 return path;
108 } 108 }
109 return path.Append(L"sysnative").Append(binary); 109 return path.Append(L"sysnative").Append(binary);
110 } 110 }
111 111
112 void SpoolerServiceCommand(const char* command) { 112 void SpoolerServiceCommand(const char* command) {
113 FilePath net_path = GetNativeSystemPath(L"net"); 113 base::FilePath net_path = GetNativeSystemPath(L"net");
114 if (net_path.empty()) 114 if (net_path.empty())
115 return; 115 return;
116 CommandLine command_line(net_path); 116 CommandLine command_line(net_path);
117 command_line.AppendArg(command); 117 command_line.AppendArg(command);
118 command_line.AppendArg("spooler"); 118 command_line.AppendArg("spooler");
119 command_line.AppendArg("/y"); 119 command_line.AppendArg("/y");
120 120
121 base::LaunchOptions options; 121 base::LaunchOptions options;
122 options.wait = true; 122 options.wait = true;
123 options.start_hidden = true; 123 options.start_hidden = true;
124 LOG(INFO) << command_line.GetCommandLineString(); 124 LOG(INFO) << command_line.GetCommandLineString();
125 base::LaunchProcess(command_line, options, NULL); 125 base::LaunchProcess(command_line, options, NULL);
126 } 126 }
127 127
128 HRESULT RegisterPortMonitor(bool install, const FilePath& install_path) { 128 HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
129 DCHECK(install || install_path.empty()); 129 DCHECK(install || install_path.empty());
130 FilePath target_path = 130 base::FilePath target_path =
131 GetNativeSystemPath(cloud_print::GetPortMonitorDllName()); 131 GetNativeSystemPath(cloud_print::GetPortMonitorDllName());
132 if (target_path.empty()) { 132 if (target_path.empty()) {
133 LOG(ERROR) << "Unable to get port monitor target path."; 133 LOG(ERROR) << "Unable to get port monitor target path.";
134 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); 134 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
135 } 135 }
136 if (install) { 136 if (install) {
137 FilePath source_path = 137 base::FilePath source_path =
138 install_path.Append(cloud_print::GetPortMonitorDllName()); 138 install_path.Append(cloud_print::GetPortMonitorDllName());
139 if (!file_util::CopyFile(source_path, target_path)) { 139 if (!file_util::CopyFile(source_path, target_path)) {
140 LOG(ERROR) << "Unable copy port monitor dll from " << 140 LOG(ERROR) << "Unable copy port monitor dll from " <<
141 source_path.value() << " to " << target_path.value(); 141 source_path.value() << " to " << target_path.value();
142 return cloud_print::GetLastHResult(); 142 return cloud_print::GetLastHResult();
143 } 143 }
144 } else if (!file_util::PathExists(target_path)) { 144 } else if (!file_util::PathExists(target_path)) {
145 // Already removed. Just "succeed" silently. 145 // Already removed. Just "succeed" silently.
146 return S_OK; 146 return S_OK;
147 } 147 }
148 148
149 FilePath regsvr32_path = GetNativeSystemPath(L"regsvr32.exe"); 149 base::FilePath regsvr32_path = GetNativeSystemPath(L"regsvr32.exe");
150 if (regsvr32_path.empty()) { 150 if (regsvr32_path.empty()) {
151 LOG(ERROR) << "Can't find regsvr32.exe."; 151 LOG(ERROR) << "Can't find regsvr32.exe.";
152 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); 152 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
153 } 153 }
154 154
155 CommandLine command_line(regsvr32_path); 155 CommandLine command_line(regsvr32_path);
156 command_line.AppendArg("/s"); 156 command_line.AppendArg("/s");
157 if (!install) { 157 if (!install) {
158 command_line.AppendArg("/u"); 158 command_line.AppendArg("/u");
159 } 159 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 retval <<= 32; 208 retval <<= 32;
209 retval |= fixed_file_info->dwFileVersionLS; 209 retval |= fixed_file_info->dwFileVersionLS;
210 } 210 }
211 return retval; 211 return retval;
212 } 212 }
213 213
214 UINT CALLBACK CabinetCallback(PVOID data, 214 UINT CALLBACK CabinetCallback(PVOID data,
215 UINT notification, 215 UINT notification,
216 UINT_PTR param1, 216 UINT_PTR param1,
217 UINT_PTR param2 ) { 217 UINT_PTR param2 ) {
218 FilePath* temp_path = reinterpret_cast<FilePath*>(data); 218 base::FilePath* temp_path = reinterpret_cast<base::FilePath*>(data);
219 if (notification == SPFILENOTIFY_FILEINCABINET) { 219 if (notification == SPFILENOTIFY_FILEINCABINET) {
220 FILE_IN_CABINET_INFO* info = 220 FILE_IN_CABINET_INFO* info =
221 reinterpret_cast<FILE_IN_CABINET_INFO*>(param1); 221 reinterpret_cast<FILE_IN_CABINET_INFO*>(param1);
222 for (int i = 0; i < arraysize(kDependencyList); i++) { 222 for (int i = 0; i < arraysize(kDependencyList); i++) {
223 FilePath base_name(info->NameInCabinet); 223 base::FilePath base_name(info->NameInCabinet);
224 base_name = base_name.BaseName(); 224 base_name = base_name.BaseName();
225 if (FilePath::CompareEqualIgnoreCase(base_name.value().c_str(), 225 if (base::FilePath::CompareEqualIgnoreCase(base_name.value().c_str(),
226 kDependencyList[i])) { 226 kDependencyList[i])) {
227 StringCchCopy(info->FullTargetName, MAX_PATH, 227 StringCchCopy(info->FullTargetName, MAX_PATH,
228 temp_path->Append(kDependencyList[i]).value().c_str()); 228 temp_path->Append(kDependencyList[i]).value().c_str());
229 return FILEOP_DOIT; 229 return FILEOP_DOIT;
230 } 230 }
231 } 231 }
232 232
233 return FILEOP_SKIP; 233 return FILEOP_SKIP;
234 } 234 }
235 return NO_ERROR; 235 return NO_ERROR;
236 } 236 }
237 237
238 void ReadyPpdDependencies(const FilePath& install_path) { 238 void ReadyPpdDependencies(const base::FilePath& install_path) {
239 base::win::Version version = base::win::GetVersion(); 239 base::win::Version version = base::win::GetVersion();
240 if (version >= base::win::VERSION_VISTA) { 240 if (version >= base::win::VERSION_VISTA) {
241 // GetCorePrinterDrivers and GetPrinterDriverPackagePath only exist on 241 // GetCorePrinterDrivers and GetPrinterDriverPackagePath only exist on
242 // Vista and later. Winspool.drv must be delayloaded so these calls don't 242 // Vista and later. Winspool.drv must be delayloaded so these calls don't
243 // create problems on XP. 243 // create problems on XP.
244 DWORD size = MAX_PATH; 244 DWORD size = MAX_PATH;
245 wchar_t package_path[MAX_PATH] = {0}; 245 wchar_t package_path[MAX_PATH] = {0};
246 CORE_PRINTER_DRIVER driver; 246 CORE_PRINTER_DRIVER driver;
247 GetCorePrinterDrivers(NULL, 247 GetCorePrinterDrivers(NULL,
248 NULL, 248 NULL,
249 L"{D20EA372-DD35-4950-9ED8-A6335AFE79F5}", 249 L"{D20EA372-DD35-4950-9ED8-A6335AFE79F5}",
250 1, 250 1,
251 &driver); 251 &driver);
252 GetPrinterDriverPackagePath(NULL, 252 GetPrinterDriverPackagePath(NULL,
253 NULL, 253 NULL,
254 NULL, 254 NULL,
255 driver.szPackageID, 255 driver.szPackageID,
256 package_path, 256 package_path,
257 MAX_PATH, 257 MAX_PATH,
258 &size); 258 &size);
259 SetupIterateCabinet(package_path, 259 SetupIterateCabinet(package_path,
260 0, 260 0,
261 CabinetCallback, 261 CabinetCallback,
262 const_cast<FilePath*>(&install_path)); 262 const_cast<base::FilePath*>(&install_path));
263 } else { 263 } else {
264 // PS driver files are in the sp3 cab. 264 // PS driver files are in the sp3 cab.
265 FilePath package_path; 265 base::FilePath package_path;
266 PathService::Get(base::DIR_WINDOWS, &package_path); 266 PathService::Get(base::DIR_WINDOWS, &package_path);
267 package_path = package_path.Append(L"Driver Cache\\i386\\sp3.cab"); 267 package_path = package_path.Append(L"Driver Cache\\i386\\sp3.cab");
268 SetupIterateCabinet(package_path.value().c_str(), 268 SetupIterateCabinet(package_path.value().c_str(),
269 0, 269 0,
270 CabinetCallback, 270 CabinetCallback,
271 const_cast<FilePath*>(&install_path)); 271 const_cast<base::FilePath*>(&install_path));
272 272
273 // The XPS driver files are just sitting uncompressed in the driver cache. 273 // The XPS driver files are just sitting uncompressed in the driver cache.
274 FilePath xps_path; 274 base::FilePath xps_path;
275 PathService::Get(base::DIR_WINDOWS, &xps_path); 275 PathService::Get(base::DIR_WINDOWS, &xps_path);
276 xps_path = xps_path.Append(L"Driver Cache\\i386"); 276 xps_path = xps_path.Append(L"Driver Cache\\i386");
277 xps_path = xps_path.Append(kDriverName); 277 xps_path = xps_path.Append(kDriverName);
278 file_util::CopyFile(xps_path, install_path.Append(kDriverName)); 278 file_util::CopyFile(xps_path, install_path.Append(kDriverName));
279 } 279 }
280 } 280 }
281 281
282 HRESULT InstallPpd(const FilePath& install_path) { 282 HRESULT InstallPpd(const base::FilePath& install_path) {
283 DRIVER_INFO_6 driver_info = {0}; 283 DRIVER_INFO_6 driver_info = {0};
284 HRESULT result = S_OK; 284 HRESULT result = S_OK;
285 285
286 // Set up paths for the files we depend on. 286 // Set up paths for the files we depend on.
287 FilePath ppd_path = install_path.Append(kPpdName); 287 base::FilePath ppd_path = install_path.Append(kPpdName);
288 FilePath xps_path = install_path.Append(kDriverName); 288 base::FilePath xps_path = install_path.Append(kDriverName);
289 FilePath ui_path = install_path.Append(kUiDriverName); 289 base::FilePath ui_path = install_path.Append(kUiDriverName);
290 FilePath ui_help_path = install_path.Append(kHelpName); 290 base::FilePath ui_help_path = install_path.Append(kHelpName);
291 ReadyPpdDependencies(install_path); 291 ReadyPpdDependencies(install_path);
292 // None of the print API structures likes constant strings even though they 292 // None of the print API structures likes constant strings even though they
293 // don't modify the string. const_casting is the cleanest option. 293 // don't modify the string. const_casting is the cleanest option.
294 driver_info.pDataFile = const_cast<LPWSTR>(ppd_path.value().c_str()); 294 driver_info.pDataFile = const_cast<LPWSTR>(ppd_path.value().c_str());
295 driver_info.pHelpFile = const_cast<LPWSTR>(ui_help_path.value().c_str()); 295 driver_info.pHelpFile = const_cast<LPWSTR>(ui_help_path.value().c_str());
296 driver_info.pDriverPath = const_cast<LPWSTR>(xps_path.value().c_str()); 296 driver_info.pDriverPath = const_cast<LPWSTR>(xps_path.value().c_str());
297 driver_info.pConfigFile = const_cast<LPWSTR>(ui_path.value().c_str()); 297 driver_info.pConfigFile = const_cast<LPWSTR>(ui_path.value().c_str());
298 298
299 // Set up user visible strings. 299 // Set up user visible strings.
300 string16 manufacturer = cloud_print::LoadLocalString(IDS_GOOGLE); 300 string16 manufacturer = cloud_print::LoadLocalString(IDS_GOOGLE);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (!DeletePrinter(handle)) { 383 if (!DeletePrinter(handle)) {
384 HRESULT result = cloud_print::GetLastHResult(); 384 HRESULT result = cloud_print::GetLastHResult();
385 LOG(ERROR) << "Unable to delete printer"; 385 LOG(ERROR) << "Unable to delete printer";
386 ClosePrinter(handle); 386 ClosePrinter(handle);
387 return result; 387 return result;
388 } 388 }
389 ClosePrinter(handle); 389 ClosePrinter(handle);
390 return S_OK; 390 return S_OK;
391 } 391 }
392 392
393 void SetupUninstall(const FilePath& install_path) { 393 void SetupUninstall(const base::FilePath& install_path) {
394 // Now write the Windows Uninstall entries 394 // Now write the Windows Uninstall entries
395 // Minimal error checking here since the install can contiunue 395 // Minimal error checking here since the install can contiunue
396 // if this fails. 396 // if this fails.
397 base::win::RegKey key; 397 base::win::RegKey key;
398 if (key.Create(HKEY_LOCAL_MACHINE, kUninstallRegistry, 398 if (key.Create(HKEY_LOCAL_MACHINE, kUninstallRegistry,
399 KEY_SET_VALUE) != ERROR_SUCCESS) { 399 KEY_SET_VALUE) != ERROR_SUCCESS) {
400 LOG(ERROR) << "Unable to open key"; 400 LOG(ERROR) << "Unable to open key";
401 return; 401 return;
402 } 402 }
403 CommandLine uninstall_command(install_path.Append(kInstallerName)); 403 CommandLine uninstall_command(install_path.Append(kInstallerName));
(...skipping 27 matching lines...) Expand all
431 } 431 }
432 432
433 bool IsOSSupported() { 433 bool IsOSSupported() {
434 // We don't support XP service pack 2 or older. 434 // We don't support XP service pack 2 or older.
435 base::win::Version version = base::win::GetVersion(); 435 base::win::Version version = base::win::GetVersion();
436 return (version > base::win::VERSION_XP) || 436 return (version > base::win::VERSION_XP) ||
437 ((version == base::win::VERSION_XP) && 437 ((version == base::win::VERSION_XP) &&
438 (base::win::OSInfo::GetInstance()->service_pack().major >= 3)); 438 (base::win::OSInfo::GetInstance()->service_pack().major >= 3));
439 } 439 }
440 440
441 HRESULT RegisterVirtualDriver(const FilePath& install_path) { 441 HRESULT RegisterVirtualDriver(const base::FilePath& install_path) {
442 HRESULT result = S_OK; 442 HRESULT result = S_OK;
443 443
444 DCHECK(file_util::DirectoryExists(install_path)); 444 DCHECK(file_util::DirectoryExists(install_path));
445 if (!IsOSSupported()) { 445 if (!IsOSSupported()) {
446 LOG(ERROR) << "Requires XP SP3 or later."; 446 LOG(ERROR) << "Requires XP SP3 or later.";
447 return HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION); 447 return HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION);
448 } 448 }
449 449
450 result = RegisterPortMonitor(true, install_path); 450 result = RegisterPortMonitor(true, install_path);
451 if (FAILED(result)) { 451 if (FAILED(result)) {
452 LOG(ERROR) << "Unable to register port monitor."; 452 LOG(ERROR) << "Unable to register port monitor.";
453 return result; 453 return result;
454 } 454 }
455 455
456 result = InstallPpd(install_path); 456 result = InstallPpd(install_path);
457 if (FAILED(result)) { 457 if (FAILED(result)) {
458 LOG(ERROR) << "Unable to install Ppd."; 458 LOG(ERROR) << "Unable to install Ppd.";
459 return result; 459 return result;
460 } 460 }
461 461
462 result = InstallPrinter(); 462 result = InstallPrinter();
463 if (FAILED(result) && 463 if (FAILED(result) &&
464 result != HRESULT_FROM_WIN32(ERROR_PRINTER_ALREADY_EXISTS)) { 464 result != HRESULT_FROM_WIN32(ERROR_PRINTER_ALREADY_EXISTS)) {
465 LOG(ERROR) << "Unable to install printer."; 465 LOG(ERROR) << "Unable to install printer.";
466 return result; 466 return result;
467 } 467 }
468 return S_OK; 468 return S_OK;
469 } 469 }
470 470
471 void GetCurrentInstallPath(FilePath* install_path) { 471 void GetCurrentInstallPath(base::FilePath* install_path) {
472 base::win::RegKey key; 472 base::win::RegKey key;
473 if (key.Open(HKEY_LOCAL_MACHINE, kUninstallRegistry, 473 if (key.Open(HKEY_LOCAL_MACHINE, kUninstallRegistry,
474 KEY_QUERY_VALUE) != ERROR_SUCCESS) { 474 KEY_QUERY_VALUE) != ERROR_SUCCESS) {
475 // Not installed. 475 // Not installed.
476 *install_path = FilePath(); 476 *install_path = base::FilePath();
477 return; 477 return;
478 } 478 }
479 string16 install_path_value; 479 string16 install_path_value;
480 key.ReadValue(L"InstallLocation", &install_path_value); 480 key.ReadValue(L"InstallLocation", &install_path_value);
481 *install_path = FilePath(install_path_value); 481 *install_path = base::FilePath(install_path_value);
482 } 482 }
483 483
484 HRESULT TryUnregisterVirtualDriver() { 484 HRESULT TryUnregisterVirtualDriver() {
485 HRESULT result = S_OK; 485 HRESULT result = S_OK;
486 result = UninstallPrinter(); 486 result = UninstallPrinter();
487 if (FAILED(result)) { 487 if (FAILED(result)) {
488 LOG(ERROR) << "Unable to delete printer."; 488 LOG(ERROR) << "Unable to delete printer.";
489 return result; 489 return result;
490 } 490 }
491 result = UninstallPpd(); 491 result = UninstallPpd();
492 if (FAILED(result)) { 492 if (FAILED(result)) {
493 LOG(ERROR) << "Unable to remove PPD."; 493 LOG(ERROR) << "Unable to remove PPD.";
494 return result; 494 return result;
495 } 495 }
496 // The second argument is ignored if the first is false. 496 // The second argument is ignored if the first is false.
497 result = RegisterPortMonitor(false, FilePath()); 497 result = RegisterPortMonitor(false, base::FilePath());
498 if (FAILED(result)) { 498 if (FAILED(result)) {
499 LOG(ERROR) << "Unable to remove port monitor."; 499 LOG(ERROR) << "Unable to remove port monitor.";
500 return result; 500 return result;
501 } 501 }
502 return S_OK; 502 return S_OK;
503 } 503 }
504 504
505 HRESULT UnregisterVirtualDriver() { 505 HRESULT UnregisterVirtualDriver() {
506 HRESULT hr = S_FALSE; 506 HRESULT hr = S_FALSE;
507 for (int i = 0; i < 2; ++i) { 507 for (int i = 0; i < 2; ++i) {
508 hr = TryUnregisterVirtualDriver(); 508 hr = TryUnregisterVirtualDriver();
509 if (SUCCEEDED(hr)) { 509 if (SUCCEEDED(hr)) {
510 break; 510 break;
511 } 511 }
512 // Restart spooler and try again. 512 // Restart spooler and try again.
513 SpoolerServiceCommand("stop"); 513 SpoolerServiceCommand("stop");
514 SpoolerServiceCommand("start"); 514 SpoolerServiceCommand("start");
515 } 515 }
516 return hr; 516 return hr;
517 } 517 }
518 518
519 HRESULT DeleteProgramDir(const FilePath& installer_source, bool wait) { 519 HRESULT DeleteProgramDir(const base::FilePath& installer_source, bool wait) {
520 FilePath temp_path; 520 base::FilePath temp_path;
521 if (file_util::CreateTemporaryFile(&temp_path)) { 521 if (file_util::CreateTemporaryFile(&temp_path)) {
522 file_util::CopyFile(installer_source, temp_path); 522 file_util::CopyFile(installer_source, temp_path);
523 file_util::DeleteAfterReboot(temp_path); 523 file_util::DeleteAfterReboot(temp_path);
524 CommandLine command_line(temp_path); 524 CommandLine command_line(temp_path);
525 command_line.AppendSwitchPath(kDelete, installer_source.DirName()); 525 command_line.AppendSwitchPath(kDelete, installer_source.DirName());
526 base::LaunchOptions options; 526 base::LaunchOptions options;
527 options.wait = wait; 527 options.wait = wait;
528 base::ProcessHandle process_handle; 528 base::ProcessHandle process_handle;
529 if (!base::LaunchProcess(command_line, options, &process_handle)) { 529 if (!base::LaunchProcess(command_line, options, &process_handle)) {
530 LOG(ERROR) << "Unable to launch child uninstall."; 530 LOG(ERROR) << "Unable to launch child uninstall.";
(...skipping 13 matching lines...) Expand all
544 } 544 }
545 return S_OK; 545 return S_OK;
546 } 546 }
547 547
548 HRESULT DoUninstall() { 548 HRESULT DoUninstall() {
549 DeleteGoogleUpdateKeys(); 549 DeleteGoogleUpdateKeys();
550 HRESULT result = UnregisterVirtualDriver(); 550 HRESULT result = UnregisterVirtualDriver();
551 if (FAILED(result)) 551 if (FAILED(result))
552 return result; 552 return result;
553 CleanupUninstall(); 553 CleanupUninstall();
554 FilePath installer_source; 554 base::FilePath installer_source;
555 if (PathService::Get(base::FILE_EXE, &installer_source)) 555 if (PathService::Get(base::FILE_EXE, &installer_source))
556 return DeleteProgramDir(installer_source, false); 556 return DeleteProgramDir(installer_source, false);
557 return S_OK; 557 return S_OK;
558 } 558 }
559 559
560 HRESULT DoUnregister() { 560 HRESULT DoUnregister() {
561 return UnregisterVirtualDriver(); 561 return UnregisterVirtualDriver();
562 } 562 }
563 563
564 HRESULT DoRegister(const FilePath& install_path) { 564 HRESULT DoRegister(const base::FilePath& install_path) {
565 HRESULT result = UnregisterVirtualDriver(); 565 HRESULT result = UnregisterVirtualDriver();
566 if (FAILED(result)) 566 if (FAILED(result))
567 return result; 567 return result;
568 return RegisterVirtualDriver(install_path); 568 return RegisterVirtualDriver(install_path);
569 } 569 }
570 570
571 HRESULT DoDelete(const FilePath& install_path) { 571 HRESULT DoDelete(const base::FilePath& install_path) {
572 if (install_path.value().empty()) 572 if (install_path.value().empty())
573 return E_INVALIDARG; 573 return E_INVALIDARG;
574 if (!file_util::DirectoryExists(install_path)) 574 if (!file_util::DirectoryExists(install_path))
575 return S_FALSE; 575 return S_FALSE;
576 Sleep(5000); // Give parent some time to exit. 576 Sleep(5000); // Give parent some time to exit.
577 return file_util::Delete(install_path, true) ? S_OK : E_FAIL; 577 return file_util::Delete(install_path, true) ? S_OK : E_FAIL;
578 } 578 }
579 579
580 HRESULT DoInstall(const FilePath& install_path) { 580 HRESULT DoInstall(const base::FilePath& install_path) {
581 HRESULT result = UnregisterVirtualDriver(); 581 HRESULT result = UnregisterVirtualDriver();
582 if (FAILED(result)) { 582 if (FAILED(result)) {
583 LOG(ERROR) << "Unable to unregister."; 583 LOG(ERROR) << "Unable to unregister.";
584 return result; 584 return result;
585 } 585 }
586 FilePath old_install_path; 586 base::FilePath old_install_path;
587 GetCurrentInstallPath(&old_install_path); 587 GetCurrentInstallPath(&old_install_path);
588 if (!old_install_path.value().empty() && 588 if (!old_install_path.value().empty() &&
589 install_path != old_install_path) { 589 install_path != old_install_path) {
590 if (file_util::DirectoryExists(old_install_path)) 590 if (file_util::DirectoryExists(old_install_path))
591 file_util::Delete(old_install_path, true); 591 file_util::Delete(old_install_path, true);
592 } 592 }
593 SetupUninstall(install_path); 593 SetupUninstall(install_path);
594 result = RegisterVirtualDriver(install_path); 594 result = RegisterVirtualDriver(install_path);
595 if (FAILED(result)) 595 if (FAILED(result))
596 return result; 596 return result;
597 SetGoogleUpdateKeys(); 597 SetGoogleUpdateKeys();
598 return result; 598 return result;
599 } 599 }
600 600
601 HRESULT ExecuteCommands() { 601 HRESULT ExecuteCommands() {
602 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 602 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
603 603
604 FilePath exe_path; 604 base::FilePath exe_path;
605 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) || 605 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) ||
606 !file_util::DirectoryExists(exe_path)) { 606 !file_util::DirectoryExists(exe_path)) {
607 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); 607 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
608 } 608 }
609 609
610 if (command_line.HasSwitch(kDelete)) { 610 if (command_line.HasSwitch(kDelete)) {
611 return DoDelete(command_line.GetSwitchValuePath(kDelete)); 611 return DoDelete(command_line.GetSwitchValuePath(kDelete));
612 } else if (command_line.HasSwitch(kUninstallSwitch)) { 612 } else if (command_line.HasSwitch(kUninstallSwitch)) {
613 return DoUninstall(); 613 return DoUninstall();
614 } else if (command_line.HasSwitch(kInstallSwitch)) { 614 } else if (command_line.HasSwitch(kInstallSwitch)) {
(...skipping 19 matching lines...) Expand all
634 634
635 LOG(INFO) << "HRESULT=0x" << std::setbase(16) << retval; 635 LOG(INFO) << "HRESULT=0x" << std::setbase(16) << retval;
636 636
637 // Installer is silent by default as required by Google Update. 637 // Installer is silent by default as required by Google Update.
638 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { 638 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) {
639 cloud_print::DisplayWindowsMessage(NULL, retval, 639 cloud_print::DisplayWindowsMessage(NULL, retval,
640 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); 640 cloud_print::LoadLocalString(IDS_DRIVER_NAME));
641 } 641 }
642 return retval; 642 return retval;
643 } 643 }
OLDNEW
« no previous file with comments | « cloud_print/service/win/cloud_print_service.cc ('k') | cloud_print/virtual_driver/win/port_monitor/port_monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698