• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/memory/scoped_ptr.h"
12 #include "base/stringprintf.h"
13 #include "base/win/windows_version.h"
14 
15 namespace base {
16 
17 // static
NumberOfProcessors()18 int SysInfo::NumberOfProcessors() {
19   return win::OSInfo::GetInstance()->processors();
20 }
21 
22 // static
AmountOfPhysicalMemory()23 int64 SysInfo::AmountOfPhysicalMemory() {
24   MEMORYSTATUSEX memory_info;
25   memory_info.dwLength = sizeof(memory_info);
26   if (!GlobalMemoryStatusEx(&memory_info)) {
27     NOTREACHED();
28     return 0;
29   }
30 
31   int64 rv = static_cast<int64>(memory_info.ullTotalPhys);
32   if (rv < 0)
33     rv = kint64max;
34   return rv;
35 }
36 
37 // static
AmountOfFreeDiskSpace(const FilePath & path)38 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
39   ULARGE_INTEGER available, total, free;
40   if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
41     return -1;
42   }
43   int64 rv = static_cast<int64>(available.QuadPart);
44   if (rv < 0)
45     rv = kint64max;
46   return rv;
47 }
48 
49 // static
OperatingSystemName()50 std::string SysInfo::OperatingSystemName() {
51   return "Windows NT";
52 }
53 
54 // static
OperatingSystemVersion()55 std::string SysInfo::OperatingSystemVersion() {
56   win::OSInfo* os_info = win::OSInfo::GetInstance();
57   win::OSInfo::VersionNumber version_number = os_info->version_number();
58   std::string version(StringPrintf("%d.%d", version_number.major,
59                                    version_number.minor));
60   win::OSInfo::ServicePack service_pack = os_info->service_pack();
61   if (service_pack.major != 0) {
62     version += StringPrintf(" SP%d", service_pack.major);
63     if (service_pack.minor != 0)
64       version += StringPrintf(".%d", service_pack.minor);
65   }
66   return version;
67 }
68 
69 // TODO: Implement OperatingSystemVersionComplete, which would include
70 // patchlevel/service pack number.
71 // See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion.
72 
73 // static
CPUArchitecture()74 std::string SysInfo::CPUArchitecture() {
75   // TODO: Make this vary when we support any other architectures.
76   return "x86";
77 }
78 
79 // static
GetPrimaryDisplayDimensions(int * width,int * height)80 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
81   if (width)
82     *width = GetSystemMetrics(SM_CXSCREEN);
83 
84   if (height)
85     *height = GetSystemMetrics(SM_CYSCREEN);
86 }
87 
88 // static
DisplayCount()89 int SysInfo::DisplayCount() {
90   return GetSystemMetrics(SM_CMONITORS);
91 }
92 
93 // static
VMAllocationGranularity()94 size_t SysInfo::VMAllocationGranularity() {
95   return win::OSInfo::GetInstance()->allocation_granularity();
96 }
97 
98 // static
OperatingSystemVersionNumbers(int32 * major_version,int32 * minor_version,int32 * bugfix_version)99 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
100                                             int32* minor_version,
101                                             int32* bugfix_version) {
102   win::OSInfo* os_info = win::OSInfo::GetInstance();
103   *major_version = os_info->version_number().major;
104   *minor_version = os_info->version_number().minor;
105   *bugfix_version = 0;
106 }
107 
108 }  // namespace base
109