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.

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

mercurial