1 // Copyright (c) 2012 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"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/stringprintf.h"
13 #include "base/threading/thread_restrictions.h"
14 #include "base/win/windows_version.h"
19 int SysInfo::NumberOfProcessors() {
20 return win::OSInfo::GetInstance()->processors();
24 int64
SysInfo::AmountOfPhysicalMemory() {
25 MEMORYSTATUSEX memory_info
;
26 memory_info
.dwLength
= sizeof(memory_info
);
27 if (!GlobalMemoryStatusEx(&memory_info
)) {
32 int64 rv
= static_cast<int64
>(memory_info
.ullTotalPhys
);
39 int64
SysInfo::AmountOfAvailablePhysicalMemory() {
40 MEMORYSTATUSEX memory_info
;
41 memory_info
.dwLength
= sizeof(memory_info
);
42 if (!GlobalMemoryStatusEx(&memory_info
)) {
47 int64 rv
= static_cast<int64
>(memory_info
.ullAvailPhys
);
54 int64
SysInfo::AmountOfFreeDiskSpace(const FilePath
& path
) {
55 base::ThreadRestrictions::AssertIOAllowed();
57 ULARGE_INTEGER available
, total
, free
;
58 if (!GetDiskFreeSpaceExW(path
.value().c_str(), &available
, &total
, &free
)) {
61 int64 rv
= static_cast<int64
>(available
.QuadPart
);
68 std::string
SysInfo::OperatingSystemName() {
73 std::string
SysInfo::OperatingSystemVersion() {
74 win::OSInfo
* os_info
= win::OSInfo::GetInstance();
75 win::OSInfo::VersionNumber version_number
= os_info
->version_number();
76 std::string
version(StringPrintf("%d.%d", version_number
.major
,
77 version_number
.minor
));
78 win::OSInfo::ServicePack service_pack
= os_info
->service_pack();
79 if (service_pack
.major
!= 0) {
80 version
+= StringPrintf(" SP%d", service_pack
.major
);
81 if (service_pack
.minor
!= 0)
82 version
+= StringPrintf(".%d", service_pack
.minor
);
87 // TODO: Implement OperatingSystemVersionComplete, which would include
88 // patchlevel/service pack number.
89 // See chrome/browser/feedback/feedback_util.h, FeedbackUtil::SetOSVersion.
92 std::string
SysInfo::OperatingSystemArchitecture() {
93 win::OSInfo::WindowsArchitecture arch
=
94 win::OSInfo::GetInstance()->architecture();
96 case win::OSInfo::X86_ARCHITECTURE
:
98 case win::OSInfo::X64_ARCHITECTURE
:
100 case win::OSInfo::IA64_ARCHITECTURE
:
108 std::string
SysInfo::CPUModelName() {
109 return win::OSInfo::GetInstance()->processor_model_name();
113 size_t SysInfo::VMAllocationGranularity() {
114 return win::OSInfo::GetInstance()->allocation_granularity();
118 void SysInfo::OperatingSystemVersionNumbers(int32
* major_version
,
119 int32
* minor_version
,
120 int32
* bugfix_version
) {
121 win::OSInfo
* os_info
= win::OSInfo::GetInstance();
122 *major_version
= os_info
->version_number().major
;
123 *minor_version
= os_info
->version_number().minor
;