Commit b07bccce authored by Robin Lewis's avatar Robin Lewis Committed by Commit Bot

Add helper methods to get Chrome version.

Also adds minimum supported version of Chrome for GCPW.

Bug: 907493
Change-Id: Ie4d0e050050c0f807ec1725bf223df2a11a1e164
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881474
Commit-Queue: Robin Lewis <wrlewis@google.com>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Reviewed-by: default avatarTien Mai <tienmai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711113}
parent eee74467
......@@ -52,6 +52,9 @@ const wchar_t kDefaultProfilePictureFileExtension[] = L".jpg";
namespace {
// Minimum supported version of Chrome for GCPW.
constexpr char kMinimumSupportedChromeVersionStr[] = "77.0.3865.65";
constexpr char kSentinelFilename[] = "gcpw_startup.sentinel";
constexpr base::FilePath::CharType kCredentialProviderFolder[] =
L"Credential Provider";
......@@ -791,6 +794,10 @@ base::string16 GetWindowsVersion() {
return L"Unknown";
}
base::Version GetMinimumSupportedChromeVersion() {
return base::Version(kMinimumSupportedChromeVersionStr);
}
FakesForTesting::FakesForTesting() {}
FakesForTesting::~FakesForTesting() {}
......
......@@ -12,6 +12,7 @@
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "base/version.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_types.h"
#include "chrome/credential_provider/gaiacp/scoped_handle.h"
......@@ -253,6 +254,9 @@ std::string GetDictStringUTF8(const std::unique_ptr<base::Value>& dict,
// https://stackoverflow.com/questions/31072543/reliable-way-to-get-windows-version-from-registry
base::string16 GetWindowsVersion();
// Returns the minimum supported version of Chrome for GCPW.
base::Version GetMinimumSupportedChromeVersion();
class OSUserManager;
class OSProcessManager;
......
......@@ -6,9 +6,9 @@
#include <windows.h>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "build/branding_buildflags.h"
......@@ -18,16 +18,14 @@ namespace {
// TODO(huangs) Refactor the constants: http://crbug.com/148538
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const wchar_t kInstallationRegKey[] =
const wchar_t kUpdateClientStateRegKey[] =
L"Software\\Google\\Update\\ClientState";
// Copied from chrome_appid.cc.
const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
const wchar_t kUpdateClientsRegKey[] = L"Software\\Google\\Update\\Clients";
// Copied from google_chrome_distribution.cc.
// Copied from google_chrome_install_modes.cc.
const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
// Copied frome google_chrome_sxs_distribution.cc.
const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
#else
const wchar_t kInstallationRegKey[] = L"Software\\Chromium";
......@@ -36,16 +34,37 @@ const wchar_t kInstallationRegKey[] = L"Software\\Chromium";
// Copied from util_constants.cc.
const wchar_t kChromeExe[] = L"chrome.exe";
const wchar_t kUninstallStringField[] = L"UninstallString";
const wchar_t kVersionStringField[] = L"pv";
// Returns the registry path to where Client state is stored.
base::string16 GetClientStateRegKey() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
return kUpdateClientStateRegKey;
#else
return kInstallationRegKey;
#endif
}
// Returns the registry path to where basic information about the Clients
// like name and version information are stored.
base::string16 GetClientsRegKey() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
return kUpdateClientsRegKey;
#else
return kInstallationRegKey;
#endif
}
// Reads a string value from the specified product's registry key. Returns true
// iff the value is present and successfully read.
bool GetClientStateValue(InstallationLevel level,
const wchar_t* app_guid,
const wchar_t* value_name,
base::string16* value) {
bool GetValueFromRegistry(InstallationLevel level,
const base::string16 key_path,
const wchar_t* app_guid,
const wchar_t* value_name,
base::string16* value) {
HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
base::string16 subkey(kInstallationRegKey);
base::string16 subkey(key_path);
if (app_guid)
subkey.append(1, L'\\').append(app_guid);
base::win::RegKey reg_key;
......@@ -65,7 +84,8 @@ bool GetClientStateValue(InstallationLevel level,
base::FilePath GetSetupExeFromRegistry(InstallationLevel level,
const wchar_t* app_guid) {
base::string16 uninstall;
if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) {
if (GetValueFromRegistry(level, GetClientStateRegKey(), app_guid,
kUninstallStringField, &uninstall)) {
base::FilePath setup_exe_path(uninstall);
if (base::PathExists(setup_exe_path))
return setup_exe_path;
......@@ -140,4 +160,25 @@ base::FilePath GetAnyChromePath(bool is_sxs) {
return path;
}
base::Version GetChromeVersionForInstallationLevel(InstallationLevel level,
bool is_sxs) {
const wchar_t* app_guid = nullptr; // Chromium doesn't use App GUIDs.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
app_guid = is_sxs ? kSxSBrowserAppGuid : kBrowserAppGuid;
#else
// There is no SxS build for Chromium.
if (is_sxs)
return base::Version();
#endif
base::string16 version_str;
if (GetValueFromRegistry(level, GetClientsRegKey(), app_guid,
kVersionStringField, &version_str)) {
base::Version version(base::UTF16ToASCII(version_str));
if (version.IsValid())
return version;
}
return base::Version();
}
} // namespace chrome_launcher_support
......@@ -5,9 +5,8 @@
#ifndef CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
#define CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
namespace base {
class FilePath;
}
#include <base/files/file_path.h>
#include <base/version.h>
namespace chrome_launcher_support {
......@@ -30,6 +29,14 @@ base::FilePath GetChromePathForInstallationLevel(InstallationLevel level,
// guaranteed to exist.
base::FilePath GetAnyChromePath(bool is_sxs);
// Returns the version of Chrome registered in Google Update at the specified
// installation level, if it can be found in the registry.
// Note: This version number may be different from the version of Chrome that
// the user is already running or will get run when the user launches Chrome.
// If |is_sxs| is true, gets the version of the SxS (Canary) version of Chrome.
base::Version GetChromeVersionForInstallationLevel(InstallationLevel level,
bool is_sxs);
} // namespace chrome_launcher_support
#endif // CHROME_INSTALLER_LAUNCHER_SUPPORT_CHROME_LAUNCHER_SUPPORT_H_
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