summaryrefslogtreecommitdiffstats
path: root/cloud_print/virtual_driver
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 06:03:14 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 06:03:14 +0000
commita38bfa4a1ded160a9202fdfd76ef608bd3da6a24 (patch)
tree5fe8c52ac4a90c8e7489d45623818d6f4fa8c3ba /cloud_print/virtual_driver
parentaf20e8978167d2a0f9fda5c3245bc19de7f0a295 (diff)
downloadchromium_src-a38bfa4a1ded160a9202fdfd76ef608bd3da6a24.zip
chromium_src-a38bfa4a1ded160a9202fdfd76ef608bd3da6a24.tar.gz
chromium_src-a38bfa4a1ded160a9202fdfd76ef608bd3da6a24.tar.bz2
Moved Google Update and install related code to cloud_print/common
R=gene Review URL: https://chromiumcodereview.appspot.com/14107007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print/virtual_driver')
-rw-r--r--cloud_print/virtual_driver/win/install/setup.cc182
-rw-r--r--cloud_print/virtual_driver/win/install/virtual_driver_install.gyp1
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.cc10
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver_consts.cc6
-rw-r--r--cloud_print/virtual_driver/win/virtual_driver_consts.h3
5 files changed, 40 insertions, 162 deletions
diff --git a/cloud_print/virtual_driver/win/install/setup.cc b/cloud_print/virtual_driver/win/install/setup.cc
index df7eb57..fbc297e 100644
--- a/cloud_print/virtual_driver/win/install/setup.cc
+++ b/cloud_print/virtual_driver/win/install/setup.cc
@@ -23,6 +23,7 @@
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#include "cloud_print/common/win/cloud_print_utils.h"
+#include "cloud_print/common/win/install_utils.h"
#include "cloud_print/virtual_driver/win/virtual_driver_consts.h"
#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
#include "grit/virtual_driver_setup_resources.h"
@@ -30,12 +31,12 @@
#include <strsafe.h> // Must be after base headers to avoid deprecation
// warnings.
+namespace cloud_print {
+
namespace {
const wchar_t kNameValue[] = L"GCP Virtual Driver";
-const wchar_t kUninstallRegistry[] =
- L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
- L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}";
+const wchar_t kUninstallId[] = L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}";
const wchar_t kInstallerName[] = L"virtual_driver_setup.exe";
const wchar_t kGcpUrl[] = L"http://www.google.com/cloudprint";
@@ -62,69 +63,6 @@ const char kRegisterSwitch[] = "register";
const char kUninstallSwitch[] = "uninstall";
const char kUnregisterSwitch[] = "unregister";
-// Google update related constants.
-const wchar_t kVersionKey[] = L"pv";
-const wchar_t kNameKey[] = L"name";
-const DWORD kInstallerResultFailedCustomError = 1;
-const wchar_t kRegValueInstallerResult[] = L"InstallerResult";
-const wchar_t kRegValueInstallerResultUIString[] = L"InstallerResultUIString";
-
-void SetGoogleUpdateKeys() {
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- }
-
- // Get the version from the resource file.
- string16 version_string;
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
-
- if (version_info.get()) {
- FileVersionInfoWin* version_info_win =
- static_cast<FileVersionInfoWin*>(version_info.get());
- version_string = version_info_win->product_version();
- } else {
- LOG(ERROR) << "Unable to get version string";
- // Use a random version string so that Google Update has something to go by.
- version_string = L"0.0.0.99";
- }
-
- if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS ||
- key.WriteValue(kNameKey, kNameValue) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to set registry keys";
- }
-}
-
-void SetGoogleUpdateError(const string16& message) {
- LOG(ERROR) << message;
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientStateKey,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- }
-
- if (key.WriteValue(kRegValueInstallerResult,
- kInstallerResultFailedCustomError) != ERROR_SUCCESS ||
- key.WriteValue(kRegValueInstallerResultUIString,
- message.c_str()) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to set registry keys";
- }
-}
-
-void DeleteGoogleUpdateKeys() {
- base::win::RegKey key;
- if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
- DELETE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key to delete";
- return;
- }
- if (key.DeleteKey(L"") != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to delete key";
- }
-}
-
base::FilePath GetSystemPath(const string16& binary) {
base::FilePath path;
if (!PathService::Get(base::DIR_SYSTEM, &path)) {
@@ -135,7 +73,7 @@ base::FilePath GetSystemPath(const string16& binary) {
}
base::FilePath GetNativeSystemPath(const string16& binary) {
- if (!cloud_print::IsSystem64Bit())
+ if (!IsSystem64Bit())
return GetSystemPath(binary);
base::FilePath path;
// Sysnative will bypass filesystem redirection and give us
@@ -165,19 +103,18 @@ void SpoolerServiceCommand(const char* command) {
HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
DCHECK(install || install_path.empty());
- base::FilePath target_path =
- GetNativeSystemPath(cloud_print::GetPortMonitorDllName());
+ base::FilePath target_path = GetNativeSystemPath(GetPortMonitorDllName());
if (target_path.empty()) {
LOG(ERROR) << "Unable to get port monitor target path.";
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
}
if (install) {
base::FilePath source_path =
- install_path.Append(cloud_print::GetPortMonitorDllName());
+ install_path.Append(GetPortMonitorDllName());
if (!file_util::CopyFile(source_path, target_path)) {
LOG(ERROR) << "Unable copy port monitor dll from " <<
source_path.value() << " to " << target_path.value();
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
} else if (!file_util::PathExists(target_path)) {
// Already removed. Just "succeed" silently.
@@ -197,8 +134,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
}
// Use system32 path here because otherwise ::AddMonitor would fail.
- command_line.AppendArgPath(GetSystemPath(
- cloud_print::GetPortMonitorDllName()));
+ command_line.AppendArgPath(GetSystemPath(GetPortMonitorDllName()));
base::LaunchOptions options;
options.wait = true;
@@ -213,7 +149,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
if (install) {
if (!GetExitCodeProcess(regsvr32_handle, &exit_code)) {
LOG(ERROR) << "Unable to get regsvr32.exe exit code.";
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
if (exit_code != 0) {
LOG(ERROR) << "Regsvr32.exe failed with " << exit_code;
@@ -334,7 +270,8 @@ HRESULT InstallDriver(const base::FilePath& install_path) {
base::FilePath ui_help_path = temp_path.path().Append(kHelpName);
if (!file_util::PathExists(xps_path)) {
- SetGoogleUpdateError(cloud_print::LoadLocalString(IDS_ERROR_NO_XPS));
+ SetGoogleUpdateError(kGoogleUpdateProductId,
+ LoadLocalString(IDS_ERROR_NO_XPS));
return HRESULT_FROM_WIN32(ERROR_BAD_DRIVER);
}
@@ -355,25 +292,25 @@ HRESULT InstallDriver(const base::FilePath& install_path) {
driver_info.pDependentFiles = &dependent_files[0];
// Set up user visible strings.
- string16 manufacturer = cloud_print::LoadLocalString(IDS_GOOGLE);
+ string16 manufacturer = LoadLocalString(IDS_GOOGLE);
driver_info.pszMfgName = const_cast<LPWSTR>(manufacturer.c_str());
driver_info.pszProvider = const_cast<LPWSTR>(manufacturer.c_str());
driver_info.pszOEMUrl = const_cast<LPWSTR>(kGcpUrl);
driver_info.dwlDriverVersion = GetVersionNumber();
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
driver_info.pName = const_cast<LPWSTR>(driver_name.c_str());
if (!::AddPrinterDriverEx(NULL, 6, reinterpret_cast<BYTE*>(&driver_info),
APD_COPY_NEW_FILES | APD_COPY_FROM_DIRECTORY)) {
LOG(ERROR) << "Unable to add printer driver";
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
return S_OK;
}
HRESULT UninstallDriver() {
int tries = 3;
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
while (!DeletePrinterDriverEx(NULL,
NULL,
const_cast<LPWSTR>(driver_name.c_str()),
@@ -390,7 +327,7 @@ HRESULT UninstallDriver() {
Sleep(2000);
}
if (tries <= 0) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to delete printer driver.";
return result;
}
@@ -402,18 +339,18 @@ HRESULT InstallPrinter(void) {
// None of the print API structures likes constant strings even though they
// don't modify the string. const_casting is the cleanest option.
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
printer_info.pDriverName = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pPrinterName = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pComment = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pLocation = const_cast<LPWSTR>(kGcpUrl);
string16 port_name;
- printer_info.pPortName = const_cast<LPWSTR>(cloud_print::kPortName);
+ printer_info.pPortName = const_cast<LPWSTR>(kPortName);
printer_info.Attributes = PRINTER_ATTRIBUTE_DIRECT|PRINTER_ATTRIBUTE_LOCAL;
printer_info.pPrintProcessor = L"winprint";
HANDLE handle = AddPrinter(NULL, 2, reinterpret_cast<BYTE*>(&printer_info));
if (handle == NULL) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to add printer";
return result;
}
@@ -425,7 +362,7 @@ HRESULT UninstallPrinter(void) {
HANDLE handle = NULL;
PRINTER_DEFAULTS printer_defaults = {0};
printer_defaults.DesiredAccess = PRINTER_ALL_ACCESS;
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
if (!OpenPrinter(const_cast<LPWSTR>(driver_name.c_str()),
&handle,
&printer_defaults)) {
@@ -434,7 +371,7 @@ HRESULT UninstallPrinter(void) {
return S_OK;
}
if (!DeletePrinter(handle)) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to delete printer";
ClosePrinter(handle);
return result;
@@ -443,46 +380,6 @@ HRESULT UninstallPrinter(void) {
return S_OK;
}
-void SetupUninstall(const base::FilePath& install_path) {
- // Now write the Windows Uninstall entries
- // Minimal error checking here since the install can contiunue
- // if this fails.
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, kUninstallRegistry,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- return;
- }
- CommandLine uninstall_command(install_path.Append(kInstallerName));
- uninstall_command.AppendArg("--uninstall");
- key.WriteValue(L"UninstallString",
- uninstall_command.GetCommandLineString().c_str());
- key.WriteValue(L"InstallLocation", install_path.value().c_str());
-
-
- // Get the version resource.
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
-
- if (version_info.get()) {
- FileVersionInfoWin* version_info_win =
- static_cast<FileVersionInfoWin*>(version_info.get());
- key.WriteValue(L"DisplayVersion",
- version_info_win->file_version().c_str());
- key.WriteValue(L"Publisher", version_info_win->company_name().c_str());
- } else {
- LOG(ERROR) << "Unable to get version string";
- }
- key.WriteValue(L"DisplayName",
- cloud_print::LoadLocalString(IDS_DRIVER_NAME).c_str());
- key.WriteValue(L"NoModify", 1);
- key.WriteValue(L"NoRepair", 1);
-}
-
-void CleanupUninstall() {
- ::RegDeleteKey(HKEY_LOCAL_MACHINE, kUninstallRegistry);
-}
-
bool IsOSSupported() {
// We don't support XP service pack 2 or older.
base::win::Version version = base::win::GetVersion();
@@ -521,19 +418,6 @@ HRESULT RegisterVirtualDriver(const base::FilePath& install_path) {
return S_OK;
}
-void GetCurrentInstallPath(base::FilePath* install_path) {
- base::win::RegKey key;
- if (key.Open(HKEY_LOCAL_MACHINE, kUninstallRegistry,
- KEY_QUERY_VALUE) != ERROR_SUCCESS) {
- // Not installed.
- *install_path = base::FilePath();
- return;
- }
- string16 install_path_value;
- key.ReadValue(L"InstallLocation", &install_path_value);
- *install_path = base::FilePath(install_path_value);
-}
-
HRESULT TryUnregisterVirtualDriver() {
HRESULT result = S_OK;
result = UninstallPrinter();
@@ -599,11 +483,11 @@ HRESULT DeleteProgramDir(const base::FilePath& installer_source, bool wait) {
}
HRESULT DoUninstall() {
- DeleteGoogleUpdateKeys();
+ DeleteGoogleUpdateKeys(kGoogleUpdateProductId);
HRESULT result = UnregisterVirtualDriver();
if (FAILED(result))
return result;
- CleanupUninstall();
+ DeleteUninstallKey(kUninstallId);
base::FilePath installer_source;
if (PathService::Get(base::FILE_EXE, &installer_source))
return DeleteProgramDir(installer_source, false);
@@ -636,18 +520,18 @@ HRESULT DoInstall(const base::FilePath& install_path) {
LOG(ERROR) << "Unable to unregister.";
return result;
}
- base::FilePath old_install_path;
- GetCurrentInstallPath(&old_install_path);
+ base::FilePath old_install_path = GetInstallLocation(kUninstallId);
if (!old_install_path.value().empty() &&
install_path != old_install_path) {
if (file_util::DirectoryExists(old_install_path))
file_util::Delete(old_install_path, true);
}
- SetupUninstall(install_path);
+ CreateUninstallKey(kUninstallId, LoadLocalString(IDS_DRIVER_NAME),
+ kUninstallSwitch);
result = RegisterVirtualDriver(install_path);
if (FAILED(result))
return result;
- SetGoogleUpdateKeys();
+ SetGoogleUpdateKeys(kGoogleUpdateProductId, kNameValue);
return result;
}
@@ -677,13 +561,15 @@ HRESULT ExecuteCommands() {
} // namespace
+} // namespace cloud_print
+
int WINAPI WinMain(__in HINSTANCE hInstance,
- __in HINSTANCE hPrevInstance,
- __in LPSTR lpCmdLine,
- __in int nCmdShow) {
+ __in HINSTANCE hPrevInstance,
+ __in LPSTR lpCmdLine,
+ __in int nCmdShow) {
base::AtExitManager at_exit_manager;
CommandLine::Init(0, NULL);
- HRESULT retval = ExecuteCommands();
+ HRESULT retval = cloud_print::ExecuteCommands();
LOG(INFO) << _com_error(retval).ErrorMessage() << " HRESULT=0x" <<
std::setbase(16) << retval;
diff --git a/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
index acb22e7..35c2b66 100644
--- a/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
+++ b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp
@@ -22,6 +22,7 @@
'dependencies': [
'../virtual_driver.gyp:virtual_driver_lib',
'<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/cloud_print/cloud_print.gyp:cloud_print_install_lib',
'<(DEPTH)/cloud_print/cloud_print.gyp:cloud_print_version_resources',
'virtual_driver_setup_resources',
],
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
index e1cc9b7..c13228a 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -25,6 +25,7 @@
#include "base/win/windows_version.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+#include "cloud_print/common/win/cloud_print_utils.h"
#include "cloud_print/virtual_driver/win/port_monitor/spooler_win.h"
#include "cloud_print/virtual_driver/win/virtual_driver_consts.h"
#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
@@ -405,14 +406,7 @@ BOOL WINAPI Monitor2StartDocPort(HANDLE port_handle,
DWORD job_id,
DWORD,
BYTE*) {
- const wchar_t* kUsageKey = L"dr";
- // Set appropriate key to 1 to let Omaha record usage.
- base::win::RegKey key;
- if (key.Create(HKEY_CURRENT_USER, kGoogleUpdateClientStateKey,
- KEY_SET_VALUE) != ERROR_SUCCESS ||
- key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to set usage key";
- }
+ SetGoogleUpdateUsage(kGoogleUpdateProductId);
if (port_handle == NULL) {
LOG(ERROR) << "port_handle should not be NULL.";
SetLastError(ERROR_INVALID_PARAMETER);
diff --git a/cloud_print/virtual_driver/win/virtual_driver_consts.cc b/cloud_print/virtual_driver/win/virtual_driver_consts.cc
index 8898043..5ce4fc1 100644
--- a/cloud_print/virtual_driver/win/virtual_driver_consts.cc
+++ b/cloud_print/virtual_driver/win/virtual_driver_consts.cc
@@ -10,10 +10,8 @@ namespace cloud_print {
const wchar_t kPortName[] = L"GCP:";
const size_t kPortNameSize = sizeof(kPortName);
-const wchar_t kGoogleUpdateClientsKey[] = L"SOFTWARE\\Google\\Update\\"
- L"Clients\\{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
-const wchar_t kGoogleUpdateClientStateKey[] = L"SOFTWARE\\Google\\Update\\"
- L"ClientState\\{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
+const wchar_t kGoogleUpdateProductId[] =
+ L"{9B13FA92-1F73-4761-AB78-2C6ADAC3660D}";
} // namespace cloud_print
diff --git a/cloud_print/virtual_driver/win/virtual_driver_consts.h b/cloud_print/virtual_driver/win/virtual_driver_consts.h
index 9d4b893..7e5a404 100644
--- a/cloud_print/virtual_driver/win/virtual_driver_consts.h
+++ b/cloud_print/virtual_driver/win/virtual_driver_consts.h
@@ -9,8 +9,7 @@ namespace cloud_print {
extern const wchar_t kPortName[];
extern const size_t kPortNameSize;
-extern const wchar_t kGoogleUpdateClientsKey[];
-extern const wchar_t kGoogleUpdateClientStateKey[];
+extern const wchar_t kGoogleUpdateProductId[];
} // namespace cloud_print