diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-07 18:49:09 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-07 18:49:09 +0000 |
commit | 517617476b7231f63b2f900d9dc825db2ee4161d (patch) | |
tree | a09d1e81c9796b0859a01dfc467710724046e8ce /chrome/installer | |
parent | d91ddfc676314764d240a9ad0da06063bb265d76 (diff) | |
download | chromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.zip chromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.tar.gz chromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.tar.bz2 |
Make the windows_version.h functions threadsafe by using a singleton. Add accessors to the singleton for more values that various code wants, then convert almost everyone using OSVERSIONINFO or SYSTEM_INFO structs to calling these accessors. Declare an AtExitManager in the out-of-process test runner since it didn't have one and that breaks singleton-using code in the test executable (as opposed to in chrome.dll).
A few other minor cleanups along the way (binding of "*", shorter code, etc.). Because I ran into problems with it while modifying gcapi.cc, I cleaned up our usage of strsafe.h a bit, so that files that don't need it don't include it and files that do use STRSAFE_NO_DEPRECATE instead of a modified #include order.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6713107
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r-- | chrome/installer/gcapi/gcapi.cc | 64 | ||||
-rw-r--r-- | chrome/installer/setup/install_worker.cc | 3 | ||||
-rw-r--r-- | chrome/installer/util/google_chrome_distribution.cc | 12 | ||||
-rw-r--r-- | chrome/installer/util/install_util.cc | 13 |
4 files changed, 45 insertions, 47 deletions
diff --git a/chrome/installer/gcapi/gcapi.cc b/chrome/installer/gcapi/gcapi.cc index 5ba9251..dc38bbe 100644 --- a/chrome/installer/gcapi/gcapi.cc +++ b/chrome/installer/gcapi/gcapi.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -8,10 +8,12 @@ #include <atlcom.h> #include <windows.h> #include <sddl.h> -#include <stdlib.h> +#define STRSAFE_NO_DEPRECATE #include <strsafe.h> #include <tlhelp32.h> +#include <cstdlib> + #include "google_update_idl.h" namespace { @@ -156,31 +158,31 @@ bool ReadValueFromRegistry(HKEY root_key, const wchar_t *sub_key, bool IsChromeInstalled(HKEY root_key) { wchar_t version[64]; size_t size = _countof(version); - if (ReadValueFromRegistry(root_key, kChromeRegClientsKey, kChromeRegVersion, - version, &size)) - return true; - return false; + return ReadValueFromRegistry(root_key, kChromeRegClientsKey, + kChromeRegVersion, version, &size); } -bool IsWinXPSp2OrLater(bool* is_vista_or_later) { - OSVERSIONINFOEX osviex = { sizeof(OSVERSIONINFOEX) }; - int r = ::GetVersionEx((LPOSVERSIONINFO)&osviex); - // If this failed we're on Win9X or a pre NT4SP6 OS. - if (!r) - return false; - - if (osviex.dwMajorVersion < 5) - return false; - - if (osviex.dwMajorVersion > 5) { - *is_vista_or_later = true; - return true; // way beyond Windows XP; - } - - if (osviex.dwMinorVersion >= 1 && osviex.wServicePackMajor >= 2) - return true; // Windows XP SP2 or better. - - return false; // Windows 2000, WinXP no Service Pack. +enum WindowsVersion { + VERSION_BELOW_XP_SP2, + VERSION_XP_SP2_UP_TO_VISTA, // "but not including" + VERSION_VISTA_OR_HIGHER, +}; +WindowsVersion GetWindowsVersion() { + OSVERSIONINFOEX version_info = { sizeof version_info }; + GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); + + // Windows Vista is version 6.0. + if (version_info.dwMajorVersion >= 6) + return VERSION_VISTA_OR_HIGHER; + + // Windows XP is version 5.1. (5.2 is Windows Server 2003/XP Pro x64.) + if ((version_info.dwMajorVersion < 5) || (version_info.dwMinorVersion < 1)) + return VERSION_BELOW_XP_SP2; + + // For XP itself, we only support SP2 and above. + return ((version_info.dwMinorVersion > 1) || + (version_info.wServicePackMajor >= 2)) ? + VERSION_XP_SP2_UP_TO_VISTA : VERSION_BELOW_XP_SP2; } // Note this function should not be called on old Windows versions where these @@ -230,9 +232,8 @@ bool VerifyHKLMAccess(const wchar_t* sub_key) { bool IsRunningElevated() { // This method should be called only for Vista or later. - bool is_vista_or_later = false; - IsWinXPSp2OrLater(&is_vista_or_later); - if (!is_vista_or_later || !VerifyAdminGroup()) + if ((GetWindowsVersion() < VERSION_VISTA_OR_HIGHER) || + !VerifyAdminGroup()) return false; HANDLE process_token; @@ -287,9 +288,9 @@ DLLEXPORT BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, DWORD *reasons) { DWORD local_reasons = 0; - bool is_vista_or_later = false; + WindowsVersion windows_version = GetWindowsVersion(); // System requirements? - if (!IsWinXPSp2OrLater(&is_vista_or_later)) + if (windows_version == VERSION_BELOW_XP_SP2) local_reasons |= GCCC_ERROR_OSNOTSUPPORTED; if (IsChromeInstalled(HKEY_LOCAL_MACHINE)) @@ -300,7 +301,8 @@ DLLEXPORT BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag, if (!VerifyHKLMAccess(kChromeRegClientsKey)) { local_reasons |= GCCC_ERROR_ACCESSDENIED; - } else if (is_vista_or_later && !VerifyAdminGroup()) { + } else if ((windows_version == VERSION_VISTA_OR_HIGHER) && + !VerifyAdminGroup()) { // For Vista or later check for elevation since even for admin user we could // be running in non-elevated mode. We require integrity level High. local_reasons |= GCCC_ERROR_INTEGRITYLEVEL; diff --git a/chrome/installer/setup/install_worker.cc b/chrome/installer/setup/install_worker.cc index 8b11835..7bdc9e5 100644 --- a/chrome/installer/setup/install_worker.cc +++ b/chrome/installer/setup/install_worker.cc @@ -512,7 +512,8 @@ void AddInstallWorkItems(const InstallationState& original_state, // Extra executable for 64 bit systems. // NOTE: We check for "not disabled" so that if the API call fails, we play it // safe and copy the executable anyway. - if (base::win::GetWOW64Status() != base::win::WOW64_DISABLED) { + if (base::win::OSInfo::GetInstance()->wow64_status() != + base::win::OSInfo::WOW64_DISABLED) { install_list->AddMoveTreeWorkItem( src_path.Append(installer::kWowHelperExe).value(), target_path.Append(installer::kWowHelperExe).value(), diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index c2ee5eb..89dd58a 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -326,14 +326,10 @@ void GoogleChromeDistribution::DoPostUninstallOperations( // need to escape the string before using it in a URL. const std::wstring kVersionParam = L"crversion"; const std::wstring kOSParam = L"os"; - std::wstring os_version = L"na"; - OSVERSIONINFO version_info; - version_info.dwOSVersionInfoSize = sizeof(version_info); - if (GetVersionEx(&version_info)) { - os_version = StringPrintf(L"%d.%d.%d", version_info.dwMajorVersion, - version_info.dwMinorVersion, - version_info.dwBuildNumber); - } + base::win::OSInfo::VersionNumber version_number = + base::win::OSInfo::GetInstance()->version_number(); + std::wstring os_version = StringPrintf(L"%d.%d.%d", version_number.major, + version_number.minor, version_number.build); FilePath iexplore; if (!PathService::Get(base::DIR_PROGRAM_FILES, &iexplore)) diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc index 999d84a..d1110de 100644 --- a/chrome/installer/util/install_util.cc +++ b/chrome/installer/util/install_util.cc @@ -19,6 +19,7 @@ #include "base/memory/scoped_ptr.h" #include "base/path_service.h" #include "base/string_util.h" +#include "base/sys_info.h" #include "base/values.h" #include "base/version.h" #include "base/win/registry.h" @@ -136,15 +137,13 @@ Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist, } bool InstallUtil::IsOSSupported() { - int major, minor; - base::win::Version version = base::win::GetVersion(); - base::win::GetServicePackLevel(&major, &minor); - // We do not support Win2K or older, or XP without service pack 2. - VLOG(1) << "Windows Version: " << version - << ", Service Pack: " << major << "." << minor; + VLOG(1) << base::SysInfo::OperatingSystemName() << ' ' + << base::SysInfo::OperatingSystemVersion(); + base::win::Version version = base::win::GetVersion(); return (version > base::win::VERSION_XP) || - (version == base::win::VERSION_XP && major >= 2); + ((version == base::win::VERSION_XP) && + (base::win::OSInfo::GetInstance()->service_pack().major >= 2)); } void InstallUtil::WriteInstallerResult(bool system_install, |