[Smart Lock] Record a detailed UMA metric for each unlock attempt by Smart Lock users.
[chromium-blink-merge.git] / base / sys_info_win.cc
blob9cc0cfa48a3637d48c36978de2c798383e9a194d
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/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"
16 namespace {
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;
26 int64 rv = static_cast<int64>(memory_info.*memory_field);
27 if (rv < 0)
28 rv = kint64max;
29 return rv;
32 } // namespace
34 namespace base {
36 // static
37 int SysInfo::NumberOfProcessors() {
38 return win::OSInfo::GetInstance()->processors();
41 // static
42 int64 SysInfo::AmountOfPhysicalMemory() {
43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys);
46 // static
47 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys);
51 // static
52 int64 SysInfo::AmountOfVirtualMemory() {
53 return 0;
56 // static
57 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
58 base::ThreadRestrictions::AssertIOAllowed();
60 ULARGE_INTEGER available, total, free;
61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
62 return -1;
64 int64 rv = static_cast<int64>(available.QuadPart);
65 if (rv < 0)
66 rv = kint64max;
67 return rv;
70 // static
71 std::string SysInfo::OperatingSystemName() {
72 return "Windows NT";
75 // static
76 std::string SysInfo::OperatingSystemVersion() {
77 win::OSInfo* os_info = win::OSInfo::GetInstance();
78 win::OSInfo::VersionNumber version_number = os_info->version_number();
79 std::string version(StringPrintf("%d.%d", version_number.major,
80 version_number.minor));
81 win::OSInfo::ServicePack service_pack = os_info->service_pack();
82 if (service_pack.major != 0) {
83 version += StringPrintf(" SP%d", service_pack.major);
84 if (service_pack.minor != 0)
85 version += StringPrintf(".%d", service_pack.minor);
87 return version;
90 // TODO: Implement OperatingSystemVersionComplete, which would include
91 // patchlevel/service pack number.
92 // See chrome/browser/feedback/feedback_util.h, FeedbackUtil::SetOSVersion.
94 // static
95 std::string SysInfo::OperatingSystemArchitecture() {
96 win::OSInfo::WindowsArchitecture arch =
97 win::OSInfo::GetInstance()->architecture();
98 switch (arch) {
99 case win::OSInfo::X86_ARCHITECTURE:
100 return "x86";
101 case win::OSInfo::X64_ARCHITECTURE:
102 return "x86_64";
103 case win::OSInfo::IA64_ARCHITECTURE:
104 return "ia64";
105 default:
106 return "";
110 // static
111 std::string SysInfo::CPUModelName() {
112 return win::OSInfo::GetInstance()->processor_model_name();
115 // static
116 size_t SysInfo::VMAllocationGranularity() {
117 return win::OSInfo::GetInstance()->allocation_granularity();
120 // static
121 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
122 int32* minor_version,
123 int32* bugfix_version) {
124 win::OSInfo* os_info = win::OSInfo::GetInstance();
125 *major_version = os_info->version_number().major;
126 *minor_version = os_info->version_number().minor;
127 *bugfix_version = 0;
130 } // namespace base