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
parent af20e897
......@@ -105,5 +105,16 @@
},
},
},
{
'target_name': 'cloud_print_install_lib',
'type': 'static_library',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
],
'sources': [
'<(DEPTH)/cloud_print/common/win/install_utils.cc',
'<(DEPTH)/cloud_print/common/win/install_utils.h',
],
},
],
}
......@@ -6,8 +6,18 @@
#include <windows.h>
#include "base/win/registry.h"
namespace cloud_print {
namespace {
// Google Update related constants.
const wchar_t kClientStateKey[] = L"SOFTWARE\\Google\\Update\\ClientState\\";
const wchar_t* kUsageKey = L"dr";
} // namespace
HRESULT GetLastHResult() {
DWORD error_code = GetLastError();
return error_code ? HRESULT_FROM_WIN32(error_code) : E_FAIL;
......@@ -37,4 +47,15 @@ string16 GetErrorMessage(HRESULT hr) {
return result;
}
void SetGoogleUpdateUsage(const string16& product_id) {
// Set appropriate key to 1 to let Omaha record usage.
base::win::RegKey key;
if (key.Create(HKEY_CURRENT_USER,
(kClientStateKey + product_id).c_str(),
KEY_SET_VALUE) != ERROR_SUCCESS ||
key.WriteValue(kUsageKey, L"1") != ERROR_SUCCESS) {
LOG(ERROR) << "Unable to set usage key";
}
}
} // namespace cloud_print
......@@ -21,6 +21,9 @@ string16 GetErrorMessage(HRESULT hr);
// calling code.
string16 LoadLocalString(DWORD id);
// Sets registry value to notify Google Update that product was used.
void SetGoogleUpdateUsage(const string16& product_id);
} // namespace cloud_print
#endif // CLOUD_PRINT_COMMON_CLOUD_PRINT_UTILS_H_
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cloud_print/common/win/install_utils.h"
#include <windows.h>
#include "base/command_line.h"
#include "base/file_version_info_win.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/win/registry.h"
namespace cloud_print {
namespace {
// Google Update related constants.
const wchar_t kClientsKey[] = L"SOFTWARE\\Google\\Update\\Clients\\";
const wchar_t kClientStateKey[] = L"SOFTWARE\\Google\\Update\\ClientState\\";
const wchar_t* kUsageKey = L"dr";
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";
// Uninstall related constants.
const wchar_t kUninstallKey[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
const wchar_t kInstallLocation[] = L"InstallLocation";
const wchar_t kDisplayVersion[] = L"DisplayVersion";
const wchar_t kDisplayName[] = L"DisplayName";
const wchar_t kPublisher[] = L"Publisher";
const wchar_t kNoModify[] = L"NoModify";
const wchar_t kNoRepair[] = L"NoRepair";
} // namespace
void SetGoogleUpdateKeys(const string16& product_id,
const string16& product_name) {
base::win::RegKey key;
if (key.Create(HKEY_LOCAL_MACHINE,
(cloud_print::kClientsKey + product_id).c_str(),
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, product_name.c_str()) != ERROR_SUCCESS) {
LOG(ERROR) << "Unable to set registry keys";
}
}
void SetGoogleUpdateError(const string16& product_id, const string16& message) {
LOG(ERROR) << message;
base::win::RegKey key;
if (key.Create(HKEY_LOCAL_MACHINE,
(cloud_print::kClientStateKey + product_id).c_str(),
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(const string16& product_id) {
base::win::RegKey key;
if (key.Open(HKEY_LOCAL_MACHINE,
(cloud_print::kClientsKey + product_id).c_str(),
DELETE) != ERROR_SUCCESS) {
LOG(ERROR) << "Unable to open key to delete";
return;
}
if (key.DeleteKey(L"") != ERROR_SUCCESS) {
LOG(ERROR) << "Unable to delete key";
}
}
void CreateUninstallKey(const string16& uninstall_id,
const string16& product_name,
const std::string& uninstall_switch) {
// Now write the Windows Uninstall entries
// Minimal error checking here since the install can continue
// if this fails.
base::win::RegKey key;
if (key.Create(HKEY_LOCAL_MACHINE,
(cloud_print::kUninstallKey + uninstall_id).c_str(),
KEY_SET_VALUE) != ERROR_SUCCESS) {
LOG(ERROR) << "Unable to open key";
return;
}
base::FilePath unstall_binary;
CHECK(PathService::Get(base::FILE_EXE, &unstall_binary));
CommandLine uninstall_command(unstall_binary);
uninstall_command.AppendSwitch(uninstall_switch);
key.WriteValue(kUninstallKey,
uninstall_command.GetCommandLineString().c_str());
key.WriteValue(kInstallLocation,
unstall_binary.DirName().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(kDisplayVersion,
version_info_win->file_version().c_str());
key.WriteValue(kPublisher, version_info_win->company_name().c_str());
} else {
LOG(ERROR) << "Unable to get version string";
}
key.WriteValue(kDisplayName, product_name.c_str());
key.WriteValue(kNoModify, 1);
key.WriteValue(kNoRepair, 1);
}
void DeleteUninstallKey(const string16& uninstall_id) {
::RegDeleteKey(HKEY_LOCAL_MACHINE,
(cloud_print::kUninstallKey + uninstall_id).c_str());
}
base::FilePath GetInstallLocation(const string16& uninstall_id) {
base::win::RegKey key;
if (key.Open(HKEY_LOCAL_MACHINE,
(cloud_print::kUninstallKey + uninstall_id).c_str(),
KEY_QUERY_VALUE) != ERROR_SUCCESS) {
// Not installed.
return base::FilePath();
}
string16 install_path_value;
key.ReadValue(kInstallLocation, &install_path_value);
return base::FilePath(install_path_value);
}
} // namespace cloud_print
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CLOUD_PRINT_COMMON_INSTALL_UTILS_H_
#define CLOUD_PRINT_COMMON_INSTALL_UTILS_H_
#include <wtypes.h>
#include <string>
#include "base/files/file_path.h"
#include "base/string16.h"
namespace cloud_print {
// Sets Google Update registry keys after install or update.
void SetGoogleUpdateKeys(const string16& product_id,
const string16& product_name);
// Sets custom error message to show by Google Update installer
void SetGoogleUpdateError(const string16& product_id, const string16& message);
// Deletes Google Update reg keys on product uninstall.
void DeleteGoogleUpdateKeys(const string16& product_id);
// Creates control panel uninstall item.
void CreateUninstallKey(const string16& uninstall_id,
const string16& product_name,
const std::string& uninstall_switch);
// Deletes control panel uninstall item.
void DeleteUninstallKey(const string16& uninstall_id);
// Returns install location retrieved from control panel uninstall key.
base::FilePath GetInstallLocation(const string16& uninstall_id);
} // namespace cloud_print
#endif // CLOUD_PRINT_COMMON_INSTALL_UTILS_H_
......@@ -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',
],
......
......@@ -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);
......
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment