OLD | NEW |
| (Empty) |
1 // Copyright 2015 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/files/file_path.h" | |
10 #include "base/logging.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/strings/stringprintf.h" | |
13 #include "base/threading/thread_restrictions.h" | |
14 #include "base/win/windows_version.h" | |
15 | |
16 namespace { | |
17 | |
18 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { | |
19 MEMORYSTATUSEX memory_info; | |
20 memory_info.dwLength = sizeof(memory_info); | |
21 if (!GlobalMemoryStatusEx(&memory_info)) { | |
22 NOTREACHED(); | |
23 return 0; | |
24 } | |
25 | |
26 int64 rv = static_cast<int64>(memory_info.*memory_field); | |
27 return rv < 0 ? kint64max : rv; | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 namespace base { | |
33 | |
34 // static | |
35 int SysInfo::NumberOfProcessors() { | |
36 return win::OSInfo::GetInstance()->processors(); | |
37 } | |
38 | |
39 // static | |
40 int64 SysInfo::AmountOfPhysicalMemory() { | |
41 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); | |
42 } | |
43 | |
44 // static | |
45 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | |
46 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); | |
47 } | |
48 | |
49 // static | |
50 int64 SysInfo::AmountOfVirtualMemory() { | |
51 return 0; | |
52 } | |
53 | |
54 // static | |
55 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | |
56 ThreadRestrictions::AssertIOAllowed(); | |
57 | |
58 ULARGE_INTEGER available, total, free; | |
59 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) | |
60 return -1; | |
61 | |
62 int64 rv = static_cast<int64>(available.QuadPart); | |
63 return rv < 0 ? kint64max : rv; | |
64 } | |
65 | |
66 std::string SysInfo::OperatingSystemName() { | |
67 return "Windows NT"; | |
68 } | |
69 | |
70 // static | |
71 std::string SysInfo::OperatingSystemVersion() { | |
72 win::OSInfo* os_info = win::OSInfo::GetInstance(); | |
73 win::OSInfo::VersionNumber version_number = os_info->version_number(); | |
74 std::string version(StringPrintf("%d.%d", version_number.major, | |
75 version_number.minor)); | |
76 win::OSInfo::ServicePack service_pack = os_info->service_pack(); | |
77 if (service_pack.major != 0) { | |
78 version += StringPrintf(" SP%d", service_pack.major); | |
79 if (service_pack.minor != 0) | |
80 version += StringPrintf(".%d", service_pack.minor); | |
81 } | |
82 return version; | |
83 } | |
84 | |
85 // TODO: Implement OperatingSystemVersionComplete, which would include | |
86 // patchlevel/service pack number. | |
87 // See chrome/browser/feedback/feedback_util.h, FeedbackUtil::SetOSVersion. | |
88 | |
89 // static | |
90 std::string SysInfo::OperatingSystemArchitecture() { | |
91 win::OSInfo::WindowsArchitecture arch = | |
92 win::OSInfo::GetInstance()->architecture(); | |
93 switch (arch) { | |
94 case win::OSInfo::X86_ARCHITECTURE: | |
95 return "x86"; | |
96 case win::OSInfo::X64_ARCHITECTURE: | |
97 return "x86_64"; | |
98 case win::OSInfo::IA64_ARCHITECTURE: | |
99 return "ia64"; | |
100 default: | |
101 return ""; | |
102 } | |
103 } | |
104 | |
105 // static | |
106 std::string SysInfo::CPUModelName() { | |
107 return win::OSInfo::GetInstance()->processor_model_name(); | |
108 } | |
109 | |
110 // static | |
111 size_t SysInfo::VMAllocationGranularity() { | |
112 return win::OSInfo::GetInstance()->allocation_granularity(); | |
113 } | |
114 | |
115 // static | |
116 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | |
117 int32* minor_version, | |
118 int32* bugfix_version) { | |
119 win::OSInfo* os_info = win::OSInfo::GetInstance(); | |
120 *major_version = os_info->version_number().major; | |
121 *minor_version = os_info->version_number().minor; | |
122 *bugfix_version = 0; | |
123 } | |
124 | |
125 } // namespace base | |
OLD | NEW |