michael@0: // Copyright (c) 2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/sys_info.h" michael@0: michael@0: #include michael@0: michael@0: #include "base/logging.h" michael@0: #include "base/scoped_ptr.h" michael@0: #include "base/string_util.h" michael@0: michael@0: namespace base { michael@0: michael@0: // static michael@0: int SysInfo::NumberOfProcessors() { michael@0: SYSTEM_INFO info; michael@0: GetSystemInfo(&info); michael@0: return static_cast(info.dwNumberOfProcessors); michael@0: } michael@0: michael@0: // static michael@0: int64_t SysInfo::AmountOfPhysicalMemory() { michael@0: MEMORYSTATUSEX memory_info; michael@0: memory_info.dwLength = sizeof(memory_info); michael@0: if (!GlobalMemoryStatusEx(&memory_info)) { michael@0: NOTREACHED(); michael@0: return 0; michael@0: } michael@0: michael@0: int64_t rv = static_cast(memory_info.ullTotalPhys); michael@0: if (rv < 0) michael@0: rv = kint64max; michael@0: return rv; michael@0: } michael@0: michael@0: // static michael@0: int64_t SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { michael@0: ULARGE_INTEGER available, total, free; michael@0: if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { michael@0: return -1; michael@0: } michael@0: int64_t rv = static_cast(available.QuadPart); michael@0: if (rv < 0) michael@0: rv = kint64max; michael@0: return rv; michael@0: } michael@0: michael@0: // static michael@0: bool SysInfo::HasEnvVar(const wchar_t* var) { michael@0: return GetEnvironmentVariable(var, NULL, 0) != 0; michael@0: } michael@0: michael@0: // static michael@0: std::wstring SysInfo::GetEnvVar(const wchar_t* var) { michael@0: DWORD value_length = GetEnvironmentVariable(var, NULL, 0); michael@0: if (value_length == 0) { michael@0: return L""; michael@0: } michael@0: scoped_array value(new wchar_t[value_length]); michael@0: GetEnvironmentVariable(var, value.get(), value_length); michael@0: return std::wstring(value.get()); michael@0: } michael@0: michael@0: // static michael@0: std::string SysInfo::OperatingSystemName() { michael@0: return "Windows NT"; michael@0: } michael@0: michael@0: // static michael@0: std::string SysInfo::OperatingSystemVersion() { michael@0: OSVERSIONINFO info = {0}; michael@0: info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); michael@0: GetVersionEx(&info); michael@0: michael@0: return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion); michael@0: } michael@0: michael@0: // TODO: Implement OperatingSystemVersionComplete, which would include michael@0: // patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc, michael@0: // BugReportView::SetOSVersion. michael@0: michael@0: // static michael@0: std::string SysInfo::CPUArchitecture() { michael@0: // TODO: Make this vary when we support any other architectures. michael@0: return "x86"; michael@0: } michael@0: michael@0: // static michael@0: void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { michael@0: if (width) michael@0: *width = GetSystemMetrics(SM_CXSCREEN); michael@0: michael@0: if (height) michael@0: *height = GetSystemMetrics(SM_CYSCREEN); michael@0: } michael@0: michael@0: // static michael@0: int SysInfo::DisplayCount() { michael@0: return GetSystemMetrics(SM_CMONITORS); michael@0: } michael@0: michael@0: // static michael@0: size_t SysInfo::VMAllocationGranularity() { michael@0: SYSTEM_INFO sysinfo; michael@0: GetSystemInfo(&sysinfo); michael@0: michael@0: return sysinfo.dwAllocationGranularity; michael@0: } michael@0: michael@0: // static michael@0: void SysInfo::OperatingSystemVersionNumbers(int32_t *major_version, michael@0: int32_t *minor_version, michael@0: int32_t *bugfix_version) { michael@0: OSVERSIONINFO info = {0}; michael@0: info.dwOSVersionInfoSize = sizeof(info); michael@0: GetVersionEx(&info); michael@0: *major_version = info.dwMajorVersion; michael@0: *minor_version = info.dwMinorVersion; michael@0: *bugfix_version = 0; michael@0: } michael@0: michael@0: } // namespace base