|
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. |
|
4 |
|
5 #include "base/sys_info.h" |
|
6 |
|
7 #include <windows.h> |
|
8 |
|
9 #include "base/logging.h" |
|
10 #include "base/scoped_ptr.h" |
|
11 #include "base/string_util.h" |
|
12 |
|
13 namespace base { |
|
14 |
|
15 // static |
|
16 int SysInfo::NumberOfProcessors() { |
|
17 SYSTEM_INFO info; |
|
18 GetSystemInfo(&info); |
|
19 return static_cast<int>(info.dwNumberOfProcessors); |
|
20 } |
|
21 |
|
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 } |
|
30 |
|
31 int64_t rv = static_cast<int64_t>(memory_info.ullTotalPhys); |
|
32 if (rv < 0) |
|
33 rv = kint64max; |
|
34 return rv; |
|
35 } |
|
36 |
|
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 } |
|
48 |
|
49 // static |
|
50 bool SysInfo::HasEnvVar(const wchar_t* var) { |
|
51 return GetEnvironmentVariable(var, NULL, 0) != 0; |
|
52 } |
|
53 |
|
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 } |
|
64 |
|
65 // static |
|
66 std::string SysInfo::OperatingSystemName() { |
|
67 return "Windows NT"; |
|
68 } |
|
69 |
|
70 // static |
|
71 std::string SysInfo::OperatingSystemVersion() { |
|
72 OSVERSIONINFO info = {0}; |
|
73 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
|
74 GetVersionEx(&info); |
|
75 |
|
76 return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion); |
|
77 } |
|
78 |
|
79 // TODO: Implement OperatingSystemVersionComplete, which would include |
|
80 // patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc, |
|
81 // BugReportView::SetOSVersion. |
|
82 |
|
83 // static |
|
84 std::string SysInfo::CPUArchitecture() { |
|
85 // TODO: Make this vary when we support any other architectures. |
|
86 return "x86"; |
|
87 } |
|
88 |
|
89 // static |
|
90 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { |
|
91 if (width) |
|
92 *width = GetSystemMetrics(SM_CXSCREEN); |
|
93 |
|
94 if (height) |
|
95 *height = GetSystemMetrics(SM_CYSCREEN); |
|
96 } |
|
97 |
|
98 // static |
|
99 int SysInfo::DisplayCount() { |
|
100 return GetSystemMetrics(SM_CMONITORS); |
|
101 } |
|
102 |
|
103 // static |
|
104 size_t SysInfo::VMAllocationGranularity() { |
|
105 SYSTEM_INFO sysinfo; |
|
106 GetSystemInfo(&sysinfo); |
|
107 |
|
108 return sysinfo.dwAllocationGranularity; |
|
109 } |
|
110 |
|
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 } |
|
122 |
|
123 } // namespace base |