1 // Copyright (c) 2008 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 14 namespace base { 15 16 // static 17 int SysInfo::NumberOfProcessors() { 18 SYSTEM_INFO info; 19 GetSystemInfo(&info); 20 return static_cast<int>(info.dwNumberOfProcessors); 21 } 22 23 // static 24 int64 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 39 int64 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 51 bool SysInfo::HasEnvVar(const wchar_t* var) { 52 return GetEnvironmentVariable(var, NULL, 0) != 0; 53 } 54 55 // static 56 std::wstring SysInfo::GetEnvVar(const wchar_t* var) { 57 DWORD value_length = GetEnvironmentVariable(var, NULL, 0); 58 if (value_length == 0) { 59 return L""; 60 } 61 scoped_array<wchar_t> value(new wchar_t[value_length]); 62 GetEnvironmentVariable(var, value.get(), value_length); 63 return std::wstring(value.get()); 64 } 65 66 // static 67 std::string SysInfo::OperatingSystemName() { 68 return "Windows NT"; 69 } 70 71 // static 72 std::string SysInfo::OperatingSystemVersion() { 73 OSVERSIONINFO info = {0}; 74 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 75 GetVersionEx(&info); 76 77 return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion); 78 } 79 80 // TODO: Implement OperatingSystemVersionComplete, which would include 81 // patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc, 82 // BugReportView::SetOSVersion. 83 84 // static 85 std::string SysInfo::CPUArchitecture() { 86 // TODO: Make this vary when we support any other architectures. 87 return "x86"; 88 } 89 90 // static 91 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { 92 if (width) 93 *width = GetSystemMetrics(SM_CXSCREEN); 94 95 if (height) 96 *height = GetSystemMetrics(SM_CYSCREEN); 97 } 98 99 // static 100 int SysInfo::DisplayCount() { 101 return GetSystemMetrics(SM_CMONITORS); 102 } 103 104 // static 105 size_t SysInfo::VMAllocationGranularity() { 106 SYSTEM_INFO sysinfo; 107 GetSystemInfo(&sysinfo); 108 109 return sysinfo.dwAllocationGranularity; 110 } 111 112 // static 113 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, 114 int32 *minor_version, 115 int32 *bugfix_version) { 116 OSVERSIONINFO info = {0}; 117 info.dwOSVersionInfoSize = sizeof(info); 118 GetVersionEx(&info); 119 *major_version = info.dwMajorVersion; 120 *minor_version = info.dwMinorVersion; 121 *bugfix_version = 0; 122 } 123 124 } // namespace base 125