summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/file_version_info_win.cc5
-rw-r--r--base/process_util_win.cc12
-rw-r--r--base/sys_info.h12
-rw-r--r--base/sys_info_chromeos.cc12
-rw-r--r--base/sys_info_mac.cc8
-rw-r--r--base/sys_info_win.cc41
-rw-r--r--base/win/windows_version.cc100
-rw-r--r--base/win/windows_version.h117
8 files changed, 151 insertions, 156 deletions
diff --git a/base/file_version_info_win.cc b/base/file_version_info_win.cc
index 8c6820e..953caa9 100644
--- a/base/file_version_info_win.cc
+++ b/base/file_version_info_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2008 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.
@@ -12,6 +12,9 @@
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
+// This has to be last.
+#include <strsafe.h>
+
FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page)
: language_(language), code_page_(code_page) {
base::ThreadRestrictions::AssertIOAllowed();
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index a49b78c..8ade06e 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -17,7 +17,6 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
-#include "base/sys_info.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
@@ -555,11 +554,12 @@ bool CleanupProcesses(const std::wstring& executable_name,
///////////////////////////////////////////////////////////////////////////////
// ProcesMetrics
-ProcessMetrics::ProcessMetrics(ProcessHandle process)
- : process_(process),
- processor_count_(base::SysInfo::NumberOfProcessors()),
- last_time_(0),
- last_system_time_(0) {
+ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process),
+ last_time_(0),
+ last_system_time_(0) {
+ SYSTEM_INFO system_info;
+ GetSystemInfo(&system_info);
+ processor_count_ = system_info.dwNumberOfProcessors;
}
// static
diff --git a/base/sys_info.h b/base/sys_info.h
index 863e068..1d2939e 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -41,9 +41,9 @@ class BASE_API SysInfo {
// Retrieves detailed numeric values for the OS version.
// TODO(port): Implement a Linux version of this method and enable the
// corresponding unit test.
- static void OperatingSystemVersionNumbers(int32* major_version,
- int32* minor_version,
- int32* bugfix_version);
+ static void OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version);
// Returns the CPU architecture of the system. Exact return value may differ
// across platforms.
@@ -73,9 +73,9 @@ class BASE_API SysInfo {
// Parses /etc/lsb-release to get version information for Google Chrome OS.
// Declared here so it can be exposed for unit testing.
static void ParseLsbRelease(const std::string& lsb_release,
- int32* major_version,
- int32* minor_version,
- int32* bugfix_version);
+ int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version);
#endif
};
diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc
index cd17c18..b15d71b 100644
--- a/base/sys_info_chromeos.cc
+++ b/base/sys_info_chromeos.cc
@@ -43,9 +43,9 @@ static base::LazyInstance<ChromeOSVersionNumbers>
g_chrome_os_version_numbers(base::LINKER_INITIALIZED);
// static
-void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
- int32* minor_version,
- int32* bugfix_version) {
+void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
if (!g_chrome_os_version_numbers.Get().parsed) {
// The other implementations of SysInfo don't block on the disk.
// See http://code.google.com/p/chromium/issues/detail?id=60394
@@ -75,9 +75,9 @@ std::string SysInfo::GetLinuxStandardBaseVersionKey() {
// static
void SysInfo::ParseLsbRelease(const std::string& lsb_release,
- int32* major_version,
- int32* minor_version,
- int32* bugfix_version) {
+ int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
size_t version_key_index = std::string::npos;
for (int i = 0; kLinuxStandardBaseVersionKeys[i] != NULL; ++i) {
version_key_index = lsb_release.find(kLinuxStandardBaseVersionKeys[i]);
diff --git a/base/sys_info_mac.cc b/base/sys_info_mac.cc
index e668421..79caf55 100644
--- a/base/sys_info_mac.cc
+++ b/base/sys_info_mac.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -14,9 +14,9 @@
namespace base {
// static
-void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
- int32* minor_version,
- int32* bugfix_version) {
+void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
Gestalt(gestaltSystemVersionMajor,
reinterpret_cast<SInt32*>(major_version));
Gestalt(gestaltSystemVersionMinor,
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc
index 045d516..ce8376a 100644
--- a/base/sys_info_win.cc
+++ b/base/sys_info_win.cc
@@ -10,13 +10,14 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/stringprintf.h"
-#include "base/win/windows_version.h"
namespace base {
// static
int SysInfo::NumberOfProcessors() {
- return win::OSInfo::GetInstance()->processors();
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return static_cast<int>(info.dwNumberOfProcessors);
}
// static
@@ -53,17 +54,12 @@ std::string SysInfo::OperatingSystemName() {
// static
std::string SysInfo::OperatingSystemVersion() {
- win::OSInfo* os_info = win::OSInfo::GetInstance();
- win::OSInfo::VersionNumber version_number = os_info->version_number();
- std::string version(StringPrintf("%d.%d", version_number.major,
- version_number.minor));
- win::OSInfo::ServicePack service_pack = os_info->service_pack();
- if (service_pack.major != 0) {
- version += StringPrintf(" SP%d", service_pack.major);
- if (service_pack.minor != 0)
- version += StringPrintf(".%d", service_pack.minor);
- }
- return version;
+ OSVERSIONINFO info = {0};
+ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&info);
+
+ return base::StringPrintf("%lu.%lu",
+ info.dwMajorVersion, info.dwMinorVersion);
}
// TODO: Implement OperatingSystemVersionComplete, which would include
@@ -92,16 +88,21 @@ int SysInfo::DisplayCount() {
// static
size_t SysInfo::VMAllocationGranularity() {
- return win::OSInfo::GetInstance()->allocation_granularity();
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+
+ return sysinfo.dwAllocationGranularity;
}
// static
-void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
- int32* minor_version,
- int32* bugfix_version) {
- win::OSInfo* os_info = win::OSInfo::GetInstance();
- *major_version = os_info->version_number().major;
- *minor_version = os_info->version_number().minor;
+void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ OSVERSIONINFO info = {0};
+ info.dwOSVersionInfoSize = sizeof(info);
+ GetVersionEx(&info);
+ *major_version = info.dwMajorVersion;
+ *minor_version = info.dwMinorVersion;
*bugfix_version = 0;
}
diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc
index 8dc2d93..d53148d 100644
--- a/base/win/windows_version.cc
+++ b/base/win/windows_version.cc
@@ -11,49 +11,81 @@
namespace base {
namespace win {
-// static
-OSInfo* OSInfo::GetInstance() {
- return Singleton<OSInfo>::get();
+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;
}
-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;
+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;
}
- service_pack_.major = version_info.wServicePackMajor;
- service_pack_.minor = version_info.wServicePackMinor;
- SYSTEM_INFO system_info = { 0 };
+ *major = service_pack_major;
+ *minor = service_pack_minor;
+}
+
+WindowsArchitecture GetWindowsArchitecture() {
+ SYSTEM_INFO system_info;
GetNativeSystemInfo(&system_info);
switch (system_info.wProcessorArchitecture) {
- case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break;
- case PROCESSOR_ARCHITECTURE_AMD64: architecture_ = X64_ARCHITECTURE; break;
- case PROCESSOR_ARCHITECTURE_IA64: architecture_ = IA64_ARCHITECTURE; break;
+ 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;
}
- processors_ = system_info.dwNumberOfProcessors;
- allocation_granularity_ = system_info.dwAllocationGranularity;
}
-OSInfo::~OSInfo() {
+WOW64Status GetWOW64Status() {
+ static WOW64Status wow64_status =
+ GetWOW64StatusForProcess(GetCurrentProcess());
+ return wow64_status;
}
-// static
-OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) {
+WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) {
typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL);
IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process"));
@@ -65,9 +97,5 @@ OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) {
return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
}
-Version GetVersion() {
- return OSInfo::GetInstance()->version();
-}
-
} // namespace win
} // namespace base
diff --git a/base/win/windows_version.h b/base/win/windows_version.h
index 96f3792..1d4b9bf 100644
--- a/base/win/windows_version.h
+++ b/base/win/windows_version.h
@@ -7,98 +7,61 @@
#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 (base::win::GetVersion() >= base::win::VERSION_VISTA) ...".
+// "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values,
+// though.
enum Version {
- VERSION_PRE_XP = 0, // Not supported.
- VERSION_XP,
- VERSION_SERVER_2003, // Also includes Windows XP Professional x64.
- VERSION_VISTA,
- VERSION_SERVER_2008,
- VERSION_WIN7,
+ 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,
};
-// 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;
- };
-
- struct ServicePack {
- int major;
- int minor;
- };
-
- // 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,
- };
-
- // 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_; }
-
- // 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);
+// Returns the running version of Windows.
+BASE_API Version GetVersion();
- private:
- OSInfo();
- ~OSInfo();
+// Returns the major and minor version of the service pack installed.
+BASE_API void GetServicePackLevel(int* major, int* minor);
- Version version_;
- VersionNumber version_number_;
- ServicePack service_pack_;
- WindowsArchitecture architecture_;
- int processors_;
- size_t allocation_granularity_;
- WOW64Status wow64_status_;
+enum WindowsArchitecture {
+ X86_ARCHITECTURE,
+ X64_ARCHITECTURE,
+ IA64_ARCHITECTURE,
+ OTHER_ARCHITECTURE,
+};
- friend struct DefaultSingletonTraits<OSInfo>;
- DISALLOW_COPY_AND_ASSIGN(OSInfo);
+// 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,
};
-// 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();
+// 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 GetWOW64Status(), but for the supplied handle instead of the current
+// process.
+BASE_API WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
} // namespace win
} // namespace base