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.h | |
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.h')
-rw-r--r-- | base/win/windows_version.h | 117 |
1 files changed, 77 insertions, 40 deletions
diff --git a/base/win/windows_version.h b/base/win/windows_version.h index 1d4b9bf..96f3792 100644 --- a/base/win/windows_version.h +++ b/base/win/windows_version.h @@ -7,61 +7,98 @@ #pragma once #include "base/base_api.h" +#include "base/memory/singleton.h" typedef void* HANDLE; namespace base { namespace win { +// The running version of Windows. This is declared outside OSInfo for +// syntactic sugar reasons; see the declaration of GetVersion() below. // NOTE: Keep these in order so callers can do things like -// "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values, -// though. +// "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...". enum Version { - VERSION_PRE_2000 = 0, // Not supported - VERSION_2000 = 1, // Not supported - VERSION_XP = 2, - VERSION_SERVER_2003 = 3, // Also includes Windows XP Professional x64 edition - VERSION_VISTA = 4, - VERSION_2008 = 5, - VERSION_WIN7 = 6, + VERSION_PRE_XP = 0, // Not supported. + VERSION_XP, + VERSION_SERVER_2003, // Also includes Windows XP Professional x64. + VERSION_VISTA, + VERSION_SERVER_2008, + VERSION_WIN7, }; -// Returns the running version of Windows. -BASE_API Version GetVersion(); +// A Singleton that can be used to query various pieces of information about the +// OS and process state. +class BASE_API OSInfo { + public: + struct VersionNumber { + int major; + int minor; + int build; + }; -// Returns the major and minor version of the service pack installed. -BASE_API void GetServicePackLevel(int* major, int* minor); + struct ServicePack { + int major; + int minor; + }; -enum WindowsArchitecture { - X86_ARCHITECTURE, - X64_ARCHITECTURE, - IA64_ARCHITECTURE, - OTHER_ARCHITECTURE, -}; + // The processor architecture this copy of Windows natively uses. For + // example, given an x64-capable processor, we have three possibilities: + // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE + // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE + // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE + enum WindowsArchitecture { + X86_ARCHITECTURE, + X64_ARCHITECTURE, + IA64_ARCHITECTURE, + OTHER_ARCHITECTURE, + }; -// Returns the processor architecture this copy of Windows natively uses. -// For example, given an x64-capable processor, we have three possibilities: -// 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE -// 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE -// 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE -BASE_API WindowsArchitecture GetWindowsArchitecture(); - -enum WOW64Status { - WOW64_DISABLED, - WOW64_ENABLED, - WOW64_UNKNOWN, -}; + // Whether a process is running under WOW64 (the wrapper that allows 32-bit + // processes to run on 64-bit versions of Windows). This will return + // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit + // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. + // the process does not have sufficient access rights to determine this. + enum WOW64Status { + WOW64_DISABLED, + WOW64_ENABLED, + WOW64_UNKNOWN, + }; + + static OSInfo* GetInstance(); + + Version version() const { return version_; } + // The next two functions return arrays of values, [major, minor(, build)]. + VersionNumber version_number() const { return version_number_; } + ServicePack service_pack() const { return service_pack_; } + WindowsArchitecture architecture() const { return architecture_; } + int processors() const { return processors_; } + size_t allocation_granularity() const { return allocation_granularity_; } + WOW64Status wow64_status() const { return wow64_status_; } -// Returns whether this process is running under WOW64 (the wrapper that allows -// 32-bit processes to run on 64-bit versions of Windows). This will return -// WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit Chrome -// on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. the -// process does not have sufficient access rights to determine this. -BASE_API WOW64Status GetWOW64Status(); + // Like wow64_status(), but for the supplied handle instead of the current + // process. This doesn't touch member state, so you can bypass the singleton. + static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); -// Like GetWOW64Status(), but for the supplied handle instead of the current -// process. -BASE_API WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); + private: + OSInfo(); + ~OSInfo(); + + Version version_; + VersionNumber version_number_; + ServicePack service_pack_; + WindowsArchitecture architecture_; + int processors_; + size_t allocation_granularity_; + WOW64Status wow64_status_; + + friend struct DefaultSingletonTraits<OSInfo>; + DISALLOW_COPY_AND_ASSIGN(OSInfo); +}; + +// Because this is by far the most commonly-requested value from the above +// singleton, we add a global-scope accessor here as syntactic sugar. +BASE_API Version GetVersion(); } // namespace win } // namespace base |