sys_info_win.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/sys_info.h" 6 7#include <windows.h> 8 9#include "base/file_path.h" 10#include "base/logging.h" 11#include "base/scoped_ptr.h" 12#include "base/string_util.h" 13 14namespace base { 15 16// static 17int SysInfo::NumberOfProcessors() { 18 SYSTEM_INFO info; 19 GetSystemInfo(&info); 20 return static_cast<int>(info.dwNumberOfProcessors); 21} 22 23// static 24int64 SysInfo::AmountOfPhysicalMemory() { 25 MEMORYSTATUSEX memory_info; 26 memory_info.dwLength = sizeof(memory_info); 27 if (!GlobalMemoryStatusEx(&memory_info)) { 28 NOTREACHED(); 29 return 0; 30 } 31 32 int64 rv = static_cast<int64>(memory_info.ullTotalPhys); 33 if (rv < 0) 34 rv = kint64max; 35 return rv; 36} 37 38// static 39int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 40 ULARGE_INTEGER available, total, free; 41 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { 42 return -1; 43 } 44 int64 rv = static_cast<int64>(available.QuadPart); 45 if (rv < 0) 46 rv = kint64max; 47 return rv; 48} 49 50// static 51std::string SysInfo::OperatingSystemName() { 52 return "Windows NT"; 53} 54 55// static 56std::string SysInfo::OperatingSystemVersion() { 57 OSVERSIONINFO info = {0}; 58 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 59 GetVersionEx(&info); 60 61 return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion); 62} 63 64// TODO: Implement OperatingSystemVersionComplete, which would include 65// patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc, 66// BugReportView::SetOSVersion. 67 68// static 69std::string SysInfo::CPUArchitecture() { 70 // TODO: Make this vary when we support any other architectures. 71 return "x86"; 72} 73 74// static 75void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { 76 if (width) 77 *width = GetSystemMetrics(SM_CXSCREEN); 78 79 if (height) 80 *height = GetSystemMetrics(SM_CYSCREEN); 81} 82 83// static 84int SysInfo::DisplayCount() { 85 return GetSystemMetrics(SM_CMONITORS); 86} 87 88// static 89size_t SysInfo::VMAllocationGranularity() { 90 SYSTEM_INFO sysinfo; 91 GetSystemInfo(&sysinfo); 92 93 return sysinfo.dwAllocationGranularity; 94} 95 96// static 97void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, 98 int32 *minor_version, 99 int32 *bugfix_version) { 100 OSVERSIONINFO info = {0}; 101 info.dwOSVersionInfoSize = sizeof(info); 102 GetVersionEx(&info); 103 *major_version = info.dwMajorVersion; 104 *minor_version = info.dwMinorVersion; 105 *bugfix_version = 0; 106} 107 108} // namespace base 109