Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2126)

Unified Diff: base/win/windows_version.cc

Issue 6713107: Make the windows_version.h functions threadsafe by using a singleton. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/windows_version.h ('k') | chrome/browser/bug_report_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/windows_version.cc
===================================================================
--- base/win/windows_version.cc (revision 80667)
+++ base/win/windows_version.cc (working copy)
@@ -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 @@
return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
}
+Version GetVersion() {
+ return OSInfo::GetInstance()->version();
+}
+
} // namespace win
} // namespace base
« no previous file with comments | « base/win/windows_version.h ('k') | chrome/browser/bug_report_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698