OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
| 9 #include <limits> |
| 10 |
9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
14 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { | 20 int64_t AmountOfMemory(DWORDLONG MEMORYSTATUSEX::*memory_field) { |
19 MEMORYSTATUSEX memory_info; | 21 MEMORYSTATUSEX memory_info; |
20 memory_info.dwLength = sizeof(memory_info); | 22 memory_info.dwLength = sizeof(memory_info); |
21 if (!GlobalMemoryStatusEx(&memory_info)) { | 23 if (!GlobalMemoryStatusEx(&memory_info)) { |
22 NOTREACHED(); | 24 NOTREACHED(); |
23 return 0; | 25 return 0; |
24 } | 26 } |
25 | 27 |
26 int64 rv = static_cast<int64>(memory_info.*memory_field); | 28 int64_t rv = static_cast<int64_t>(memory_info.*memory_field); |
27 return rv < 0 ? kint64max : rv; | 29 return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; |
28 } | 30 } |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 namespace base { | 34 namespace base { |
33 | 35 |
34 // static | 36 // static |
35 int SysInfo::NumberOfProcessors() { | 37 int SysInfo::NumberOfProcessors() { |
36 return win::OSInfo::GetInstance()->processors(); | 38 return win::OSInfo::GetInstance()->processors(); |
37 } | 39 } |
38 | 40 |
39 // static | 41 // static |
40 int64 SysInfo::AmountOfPhysicalMemory() { | 42 int64_t SysInfo::AmountOfPhysicalMemory() { |
41 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); | 43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); |
42 } | 44 } |
43 | 45 |
44 // static | 46 // static |
45 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 47 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { |
46 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); | 48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); |
47 } | 49 } |
48 | 50 |
49 // static | 51 // static |
50 int64 SysInfo::AmountOfVirtualMemory() { | 52 int64_t SysInfo::AmountOfVirtualMemory() { |
51 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalVirtual); | 53 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalVirtual); |
52 } | 54 } |
53 | 55 |
54 // static | 56 // static |
55 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 57 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
56 ThreadRestrictions::AssertIOAllowed(); | 58 ThreadRestrictions::AssertIOAllowed(); |
57 | 59 |
58 ULARGE_INTEGER available, total, free; | 60 ULARGE_INTEGER available, total, free; |
59 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) | 61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
60 return -1; | 62 return -1; |
61 | 63 |
62 int64 rv = static_cast<int64>(available.QuadPart); | 64 int64_t rv = static_cast<int64_t>(available.QuadPart); |
63 return rv < 0 ? kint64max : rv; | 65 return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; |
64 } | 66 } |
65 | 67 |
66 std::string SysInfo::OperatingSystemName() { | 68 std::string SysInfo::OperatingSystemName() { |
67 return "Windows NT"; | 69 return "Windows NT"; |
68 } | 70 } |
69 | 71 |
70 // static | 72 // static |
71 std::string SysInfo::OperatingSystemVersion() { | 73 std::string SysInfo::OperatingSystemVersion() { |
72 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 74 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
73 win::OSInfo::VersionNumber version_number = os_info->version_number(); | 75 win::OSInfo::VersionNumber version_number = os_info->version_number(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 std::string SysInfo::CPUModelName() { | 108 std::string SysInfo::CPUModelName() { |
107 return win::OSInfo::GetInstance()->processor_model_name(); | 109 return win::OSInfo::GetInstance()->processor_model_name(); |
108 } | 110 } |
109 | 111 |
110 // static | 112 // static |
111 size_t SysInfo::VMAllocationGranularity() { | 113 size_t SysInfo::VMAllocationGranularity() { |
112 return win::OSInfo::GetInstance()->allocation_granularity(); | 114 return win::OSInfo::GetInstance()->allocation_granularity(); |
113 } | 115 } |
114 | 116 |
115 // static | 117 // static |
116 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 118 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version, |
117 int32* minor_version, | 119 int32_t* minor_version, |
118 int32* bugfix_version) { | 120 int32_t* bugfix_version) { |
119 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 121 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
120 *major_version = os_info->version_number().major; | 122 *major_version = os_info->version_number().major; |
121 *minor_version = os_info->version_number().minor; | 123 *minor_version = os_info->version_number().minor; |
122 *bugfix_version = 0; | 124 *bugfix_version = 0; |
123 } | 125 } |
124 | 126 |
125 } // namespace base | 127 } // namespace base |
OLD | NEW |