blob: eb1ccbb8df1d2a57af784e6676f141565f3e2f68 [file] [log] [blame]
[email protected]9e790bd2011-01-10 23:48:541// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]2a758d612008-09-17 10:09:392// 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
[email protected]13326bb2009-10-14 00:41:569#include "base/file_path.h"
[email protected]d632798e2008-09-17 13:10:4510#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]f1633932010-08-17 23:05:2812#include "base/stringprintf.h"
[email protected]f481221192011-04-07 22:15:3413#include "base/win/windows_version.h"
[email protected]d632798e2008-09-17 13:10:4514
[email protected]2a758d612008-09-17 10:09:3915namespace base {
16
17// static
18int SysInfo::NumberOfProcessors() {
[email protected]f481221192011-04-07 22:15:3419 return win::OSInfo::GetInstance()->processors();
[email protected]2a758d612008-09-17 10:09:3920}
21
[email protected]d632798e2008-09-17 13:10:4522// static
23int64 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
[email protected]02ee34a2008-09-20 01:16:2331 int64 rv = static_cast<int64>(memory_info.ullTotalPhys);
32 if (rv < 0)
33 rv = kint64max;
34 return rv;
[email protected]d632798e2008-09-17 13:10:4535}
36
[email protected]0e91dd22008-09-18 12:34:2437// static
[email protected]13326bb2009-10-14 00:41:5638int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
[email protected]0e91dd22008-09-18 12:34:2439 ULARGE_INTEGER available, total, free;
[email protected]13326bb2009-10-14 00:41:5640 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
[email protected]02ee34a2008-09-20 01:16:2341 return -1;
[email protected]0e91dd22008-09-18 12:34:2442 }
[email protected]02ee34a2008-09-20 01:16:2343 int64 rv = static_cast<int64>(available.QuadPart);
44 if (rv < 0)
45 rv = kint64max;
46 return rv;
[email protected]0e91dd22008-09-18 12:34:2447}
48
[email protected]05f9b682008-09-29 22:18:0149// static
[email protected]05f9b682008-09-29 22:18:0150std::string SysInfo::OperatingSystemName() {
51 return "Windows NT";
52}
53
54// static
55std::string SysInfo::OperatingSystemVersion() {
[email protected]f481221192011-04-07 22:15:3456 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;
[email protected]05f9b682008-09-29 22:18:0167}
68
69// TODO: Implement OperatingSystemVersionComplete, which would include
[email protected]9e790bd2011-01-10 23:48:5470// patchlevel/service pack number.
71// See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion.
[email protected]05f9b682008-09-29 22:18:0172
73// static
74std::string SysInfo::CPUArchitecture() {
75 // TODO: Make this vary when we support any other architectures.
76 return "x86";
77}
78
79// static
[email protected]037fce02009-01-22 01:42:1580size_t SysInfo::VMAllocationGranularity() {
[email protected]f481221192011-04-07 22:15:3481 return win::OSInfo::GetInstance()->allocation_granularity();
[email protected]037fce02009-01-22 01:42:1582}
83
[email protected]71aa16c2009-02-24 16:37:1384// static
[email protected]f481221192011-04-07 22:15:3485void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
86 int32* minor_version,
87 int32* bugfix_version) {
88 win::OSInfo* os_info = win::OSInfo::GetInstance();
89 *major_version = os_info->version_number().major;
90 *minor_version = os_info->version_number().minor;
[email protected]71aa16c2009-02-24 16:37:1391 *bugfix_version = 0;
92}
93
[email protected]2a758d612008-09-17 10:09:3994} // namespace base