ipc/chromium/src/base/sys_info_win.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial