sys_info_win.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
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/stringprintf.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 base::StringPrintf("%lu.%lu",
62                            info.dwMajorVersion, info.dwMinorVersion);
63}
64
65// TODO: Implement OperatingSystemVersionComplete, which would include
66// patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc,
67// BugReportView::SetOSVersion.
68
69// static
70std::string SysInfo::CPUArchitecture() {
71  // TODO: Make this vary when we support any other architectures.
72  return "x86";
73}
74
75// static
76void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
77  if (width)
78    *width = GetSystemMetrics(SM_CXSCREEN);
79
80  if (height)
81    *height = GetSystemMetrics(SM_CYSCREEN);
82}
83
84// static
85int SysInfo::DisplayCount() {
86  return GetSystemMetrics(SM_CMONITORS);
87}
88
89// static
90size_t SysInfo::VMAllocationGranularity() {
91  SYSTEM_INFO sysinfo;
92  GetSystemInfo(&sysinfo);
93
94  return sysinfo.dwAllocationGranularity;
95}
96
97// static
98void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
99                                            int32 *minor_version,
100                                            int32 *bugfix_version) {
101  OSVERSIONINFO info = {0};
102  info.dwOSVersionInfoSize = sizeof(info);
103  GetVersionEx(&info);
104  *major_version = info.dwMajorVersion;
105  *minor_version = info.dwMinorVersion;
106  *bugfix_version = 0;
107}
108
109}  // namespace base
110