OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include <winioctl.h> |
8 | 9 |
| 10 #include "base/files/file.h" |
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 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 rv = static_cast<int64>(memory_info.*memory_field); |
27 if (rv < 0) | 29 return rv < 0 ? kint64max : rv; |
28 rv = kint64max; | |
29 return rv; | |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 namespace base { | 34 namespace base { |
35 | 35 |
36 // static | 36 // static |
37 int SysInfo::NumberOfProcessors() { | 37 int SysInfo::NumberOfProcessors() { |
38 return win::OSInfo::GetInstance()->processors(); | 38 return win::OSInfo::GetInstance()->processors(); |
39 } | 39 } |
40 | 40 |
41 // static | 41 // static |
42 int64 SysInfo::AmountOfPhysicalMemory() { | 42 int64 SysInfo::AmountOfPhysicalMemory() { |
43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); | 43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); |
44 } | 44 } |
45 | 45 |
46 // static | 46 // static |
47 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 47 int64 SysInfo::AmountOfAvailablePhysicalMemory() { |
48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); | 48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); |
49 } | 49 } |
50 | 50 |
51 // static | 51 // static |
52 int64 SysInfo::AmountOfVirtualMemory() { | 52 int64 SysInfo::AmountOfVirtualMemory() { |
53 return 0; | 53 return 0; |
54 } | 54 } |
55 | 55 |
56 // static | 56 // static |
57 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 57 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
58 base::ThreadRestrictions::AssertIOAllowed(); | 58 ThreadRestrictions::AssertIOAllowed(); |
59 | 59 |
60 ULARGE_INTEGER available, total, free; | 60 ULARGE_INTEGER available, total, free; |
61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { | 61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
62 return -1; | 62 return -1; |
63 } | 63 |
64 int64 rv = static_cast<int64>(available.QuadPart); | 64 int64 rv = static_cast<int64>(available.QuadPart); |
65 if (rv < 0) | 65 return rv < 0 ? kint64max : rv; |
66 rv = kint64max; | 66 } |
67 return rv; | 67 |
| 68 bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { |
| 69 ThreadRestrictions::AssertIOAllowed(); |
| 70 |
| 71 DCHECK(path.IsAbsolute()); |
| 72 DCHECK(has_seek_penalty); |
| 73 |
| 74 // TODO(dbeam): Vista, XP support. |
| 75 if (win::GetVersion() < win::VERSION_WIN7) |
| 76 return false; |
| 77 |
| 78 std::vector<FilePath::StringType> components; |
| 79 path.GetComponents(&components); |
| 80 File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN); |
| 81 if (!drive.IsValid()) |
| 82 return false; |
| 83 |
| 84 STORAGE_PROPERTY_QUERY query; |
| 85 query.QueryType = PropertyStandardQuery; |
| 86 query.PropertyId = StorageDeviceSeekPenaltyProperty; |
| 87 |
| 88 DEVICE_SEEK_PENALTY_DESCRIPTOR result; |
| 89 DWORD bytes_returned; |
| 90 |
| 91 BOOL success = DeviceIoControl(drive.GetPlatformFile(), |
| 92 IOCTL_STORAGE_QUERY_PROPERTY, |
| 93 &query, sizeof(query), |
| 94 &result, sizeof(result), |
| 95 &bytes_returned, |
| 96 NULL); |
| 97 if (success == FALSE || bytes_returned < sizeof(result)) |
| 98 return false; |
| 99 |
| 100 *has_seek_penalty = result.IncursSeekPenalty != FALSE; |
| 101 return true; |
68 } | 102 } |
69 | 103 |
70 // static | 104 // static |
71 std::string SysInfo::OperatingSystemName() { | 105 std::string SysInfo::OperatingSystemName() { |
72 return "Windows NT"; | 106 return "Windows NT"; |
73 } | 107 } |
74 | 108 |
75 // static | 109 // static |
76 std::string SysInfo::OperatingSystemVersion() { | 110 std::string SysInfo::OperatingSystemVersion() { |
77 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 111 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 155 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
122 int32* minor_version, | 156 int32* minor_version, |
123 int32* bugfix_version) { | 157 int32* bugfix_version) { |
124 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 158 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
125 *major_version = os_info->version_number().major; | 159 *major_version = os_info->version_number().major; |
126 *minor_version = os_info->version_number().minor; | 160 *minor_version = os_info->version_number().minor; |
127 *bugfix_version = 0; | 161 *bugfix_version = 0; |
128 } | 162 } |
129 | 163 |
130 } // namespace base | 164 } // namespace base |
OLD | NEW |