Revert 171679
[chromium-blink-merge.git] / base / sys_info_win.cc
blob98d2f7c951bb28605406ce0657793dc91ca711c8
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"
7 #include <windows.h>
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/threading/thread_restrictions.h"
14 #include "base/win/windows_version.h"
16 namespace base {
18 // static
19 int SysInfo::NumberOfProcessors() {
20 return win::OSInfo::GetInstance()->processors();
23 // static
24 int64 SysInfo::AmountOfPhysicalMemory() {
25 MEMORYSTATUSEX memory_info;
26 memory_info.dwLength = sizeof(memory_info);
27 if (!GlobalMemoryStatusEx(&memory_info)) {
28 NOTREACHED();
29 return 0;
32 int64 rv = static_cast<int64>(memory_info.ullTotalPhys);
33 if (rv < 0)
34 rv = kint64max;
35 return rv;
38 // static
39 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
40 MEMORYSTATUSEX memory_info;
41 memory_info.dwLength = sizeof(memory_info);
42 if (!GlobalMemoryStatusEx(&memory_info)) {
43 NOTREACHED();
44 return 0;
47 int64 rv = static_cast<int64>(memory_info.ullAvailPhys);
48 if (rv < 0)
49 rv = kint64max;
50 return rv;
53 // static
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)) {
59 return -1;
61 int64 rv = static_cast<int64>(available.QuadPart);
62 if (rv < 0)
63 rv = kint64max;
64 return rv;
67 // static
68 std::string SysInfo::OperatingSystemName() {
69 return "Windows NT";
72 // static
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);
84 return version;
87 // TODO: Implement OperatingSystemVersionComplete, which would include
88 // patchlevel/service pack number.
89 // See chrome/browser/feedback/feedback_util.h, FeedbackUtil::SetOSVersion.
91 // static
92 std::string SysInfo::OperatingSystemArchitecture() {
93 win::OSInfo::WindowsArchitecture arch =
94 win::OSInfo::GetInstance()->architecture();
95 switch (arch) {
96 case win::OSInfo::X86_ARCHITECTURE:
97 return "x86";
98 case win::OSInfo::X64_ARCHITECTURE:
99 return "x86_64";
100 case win::OSInfo::IA64_ARCHITECTURE:
101 return "ia64";
102 default:
103 return "";
107 // static
108 std::string SysInfo::CPUModelName() {
109 return win::OSInfo::GetInstance()->processor_model_name();
112 // static
113 size_t SysInfo::VMAllocationGranularity() {
114 return win::OSInfo::GetInstance()->allocation_granularity();
117 // static
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;
124 *bugfix_version = 0;
127 } // namespace base