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 /base/win/windows_version.cc | |
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 'base/win/windows_version.cc')
-rw-r--r-- | base/win/windows_version.cc | 100 |
1 files changed, 36 insertions, 64 deletions
diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc index d53148d..8dc2d93 100644 --- a/base/win/windows_version.cc +++ b/base/win/windows_version.cc @@ -11,81 +11,49 @@ namespace base { namespace win { -Version GetVersion() { - static bool checked_version = false; - static Version win_version = VERSION_PRE_2000; - if (!checked_version) { - OSVERSIONINFOEX version_info; - version_info.dwOSVersionInfoSize = sizeof version_info; - GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); - if (version_info.dwMajorVersion == 5) { - switch (version_info.dwMinorVersion) { - case 0: - win_version = VERSION_2000; - break; - case 1: - win_version = VERSION_XP; - break; - case 2: - default: - win_version = VERSION_SERVER_2003; - break; - } - } else if (version_info.dwMajorVersion == 6) { - if (version_info.wProductType != VER_NT_WORKSTATION) { - // 2008 is 6.0, and 2008 R2 is 6.1. - win_version = VERSION_2008; - } else { - if (version_info.dwMinorVersion == 0) { - win_version = VERSION_VISTA; - } else { - win_version = VERSION_WIN7; - } - } - } else if (version_info.dwMajorVersion > 6) { - win_version = VERSION_WIN7; - } - checked_version = true; - } - return win_version; +// static +OSInfo* OSInfo::GetInstance() { + return Singleton<OSInfo>::get(); } -void GetServicePackLevel(int* major, int* minor) { - DCHECK(major && minor); - static bool checked_version = false; - static int service_pack_major = -1; - static int service_pack_minor = -1; - if (!checked_version) { - OSVERSIONINFOEX version_info = {0}; - version_info.dwOSVersionInfoSize = sizeof(version_info); - GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info)); - service_pack_major = version_info.wServicePackMajor; - service_pack_minor = version_info.wServicePackMinor; - checked_version = true; +OSInfo::OSInfo() + : version_(VERSION_PRE_XP), + architecture_(OTHER_ARCHITECTURE), + wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { + OSVERSIONINFOEX version_info = { sizeof version_info }; + GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); + version_number_.major = version_info.dwMajorVersion; + version_number_.minor = version_info.dwMinorVersion; + version_number_.build = version_info.dwBuildNumber; + if ((version_number_.major == 5) && (version_number_.minor > 0)) { + version_ = (version_number_.minor == 1) ? VERSION_XP : VERSION_SERVER_2003; + } else if (version_number_.major == 6) { + if (version_info.wProductType == VER_NT_WORKSTATION) + version_ = (version_number_.minor == 0) ? VERSION_VISTA : VERSION_WIN7; + else + version_ = VERSION_SERVER_2008; + } else if (version_number_.major > 6) { + version_ = VERSION_WIN7; } + service_pack_.major = version_info.wServicePackMajor; + service_pack_.minor = version_info.wServicePackMinor; - *major = service_pack_major; - *minor = service_pack_minor; -} - -WindowsArchitecture GetWindowsArchitecture() { - SYSTEM_INFO system_info; + SYSTEM_INFO system_info = { 0 }; GetNativeSystemInfo(&system_info); switch (system_info.wProcessorArchitecture) { - case PROCESSOR_ARCHITECTURE_INTEL: return X86_ARCHITECTURE; - case PROCESSOR_ARCHITECTURE_AMD64: return X64_ARCHITECTURE; - case PROCESSOR_ARCHITECTURE_IA64: return IA64_ARCHITECTURE; - default: return OTHER_ARCHITECTURE; + case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break; + case PROCESSOR_ARCHITECTURE_AMD64: architecture_ = X64_ARCHITECTURE; break; + case PROCESSOR_ARCHITECTURE_IA64: architecture_ = IA64_ARCHITECTURE; break; } + processors_ = system_info.dwNumberOfProcessors; + allocation_granularity_ = system_info.dwAllocationGranularity; } -WOW64Status GetWOW64Status() { - static WOW64Status wow64_status = - GetWOW64StatusForProcess(GetCurrentProcess()); - return wow64_status; +OSInfo::~OSInfo() { } -WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) { +// static +OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) { typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); @@ -97,5 +65,9 @@ WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) { return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; } +Version GetVersion() { + return OSInfo::GetInstance()->version(); +} + } // namespace win } // namespace base |