ipc/chromium/src/base/sys_info_win.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/sys_info_win.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/sys_info.h"
     1.9 +
    1.10 +#include <windows.h>
    1.11 +
    1.12 +#include "base/logging.h"
    1.13 +#include "base/scoped_ptr.h"
    1.14 +#include "base/string_util.h"
    1.15 +
    1.16 +namespace base {
    1.17 +
    1.18 +// static
    1.19 +int SysInfo::NumberOfProcessors() {
    1.20 +  SYSTEM_INFO info;
    1.21 +  GetSystemInfo(&info);
    1.22 +  return static_cast<int>(info.dwNumberOfProcessors);
    1.23 +}
    1.24 +
    1.25 +// static
    1.26 +int64_t SysInfo::AmountOfPhysicalMemory() {
    1.27 +  MEMORYSTATUSEX memory_info;
    1.28 +  memory_info.dwLength = sizeof(memory_info);
    1.29 +  if (!GlobalMemoryStatusEx(&memory_info)) {
    1.30 +    NOTREACHED();
    1.31 +    return 0;
    1.32 +  }
    1.33 +
    1.34 +  int64_t rv = static_cast<int64_t>(memory_info.ullTotalPhys);
    1.35 +  if (rv < 0)
    1.36 +    rv = kint64max;
    1.37 +  return rv;
    1.38 +}
    1.39 +
    1.40 +// static
    1.41 +int64_t SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) {
    1.42 +  ULARGE_INTEGER available, total, free;
    1.43 +  if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) {
    1.44 +    return -1;
    1.45 +  }
    1.46 +  int64_t rv = static_cast<int64_t>(available.QuadPart);
    1.47 +  if (rv < 0)
    1.48 +    rv = kint64max;
    1.49 +  return rv;
    1.50 +}
    1.51 +
    1.52 +// static
    1.53 +bool SysInfo::HasEnvVar(const wchar_t* var) {
    1.54 +  return GetEnvironmentVariable(var, NULL, 0) != 0;
    1.55 +}
    1.56 +
    1.57 +// static
    1.58 +std::wstring SysInfo::GetEnvVar(const wchar_t* var) {
    1.59 +  DWORD value_length = GetEnvironmentVariable(var, NULL, 0);
    1.60 +  if (value_length == 0) {
    1.61 +    return L"";
    1.62 +  }
    1.63 +  scoped_array<wchar_t> value(new wchar_t[value_length]);
    1.64 +  GetEnvironmentVariable(var, value.get(), value_length);
    1.65 +  return std::wstring(value.get());
    1.66 +}
    1.67 +
    1.68 +// static
    1.69 +std::string SysInfo::OperatingSystemName() {
    1.70 +  return "Windows NT";
    1.71 +}
    1.72 +
    1.73 +// static
    1.74 +std::string SysInfo::OperatingSystemVersion() {
    1.75 +  OSVERSIONINFO info = {0};
    1.76 +  info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    1.77 +  GetVersionEx(&info);
    1.78 +
    1.79 +  return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion);
    1.80 +}
    1.81 +
    1.82 +// TODO: Implement OperatingSystemVersionComplete, which would include
    1.83 +// patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc,
    1.84 +// BugReportView::SetOSVersion.
    1.85 +
    1.86 +// static
    1.87 +std::string SysInfo::CPUArchitecture() {
    1.88 +  // TODO: Make this vary when we support any other architectures.
    1.89 +  return "x86";
    1.90 +}
    1.91 +
    1.92 +// static
    1.93 +void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
    1.94 +  if (width)
    1.95 +    *width = GetSystemMetrics(SM_CXSCREEN);
    1.96 +
    1.97 +  if (height)
    1.98 +    *height = GetSystemMetrics(SM_CYSCREEN);
    1.99 +}
   1.100 +
   1.101 +// static
   1.102 +int SysInfo::DisplayCount() {
   1.103 +  return GetSystemMetrics(SM_CMONITORS);
   1.104 +}
   1.105 +
   1.106 +// static
   1.107 +size_t SysInfo::VMAllocationGranularity() {
   1.108 +  SYSTEM_INFO sysinfo;
   1.109 +  GetSystemInfo(&sysinfo);
   1.110 +
   1.111 +  return sysinfo.dwAllocationGranularity;
   1.112 +}
   1.113 +
   1.114 +// static
   1.115 +void SysInfo::OperatingSystemVersionNumbers(int32_t *major_version,
   1.116 +                                            int32_t *minor_version,
   1.117 +                                            int32_t *bugfix_version) {
   1.118 +  OSVERSIONINFO info = {0};
   1.119 +  info.dwOSVersionInfoSize = sizeof(info);
   1.120 +  GetVersionEx(&info);
   1.121 +  *major_version = info.dwMajorVersion;
   1.122 +  *minor_version = info.dwMinorVersion;
   1.123 +  *bugfix_version = 0;
   1.124 +}
   1.125 +
   1.126 +}  // namespace base

mercurial