srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / base / sys_info_win.cc
blobeb1ccbb8df1d2a57af784e6676f141565f3e2f68
1 // Copyright (c) 2011 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/win/windows_version.h"
15 namespace base {
17 // static
18 int SysInfo::NumberOfProcessors() {
19 return win::OSInfo::GetInstance()->processors();
22 // static
23 int64 SysInfo::AmountOfPhysicalMemory() {
24 MEMORYSTATUSEX memory_info;
25 memory_info.dwLength = sizeof(memory_info);
26 if (!GlobalMemoryStatusEx(&memory_info)) {
27 NOTREACHED();
28 return 0;
31 int64 rv = static_cast<int64>(memory_info.ullTotalPhys);
32 if (rv < 0)
33 rv = kint64max;
34 return rv;
37 // static
38 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
39 ULARGE_INTEGER available, total, free;
40 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
41 return -1;
43 int64 rv = static_cast<int64>(available.QuadPart);
44 if (rv < 0)
45 rv = kint64max;
46 return rv;
49 // static
50 std::string SysInfo::OperatingSystemName() {
51 return "Windows NT";
54 // static
55 std::string SysInfo::OperatingSystemVersion() {
56 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);
66 return version;
69 // TODO: Implement OperatingSystemVersionComplete, which would include
70 // patchlevel/service pack number.
71 // See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion.
73 // static
74 std::string SysInfo::CPUArchitecture() {
75 // TODO: Make this vary when we support any other architectures.
76 return "x86";
79 // static
80 size_t SysInfo::VMAllocationGranularity() {
81 return win::OSInfo::GetInstance()->allocation_granularity();
84 // static
85 void 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;
91 *bugfix_version = 0;
94 } // namespace base