OLD | NEW |
1 // Copyright (c) 2012 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 #include <winioctl.h> | |
9 | 8 |
10 #include "base/files/file.h" | |
11 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 10 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
14 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
16 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { | 18 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 ThreadRestrictions::AssertIOAllowed(); | 56 ThreadRestrictions::AssertIOAllowed(); |
59 | 57 |
60 ULARGE_INTEGER available, total, free; | 58 ULARGE_INTEGER available, total, free; |
61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) | 59 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
62 return -1; | 60 return -1; |
63 | 61 |
64 int64 rv = static_cast<int64>(available.QuadPart); | 62 int64 rv = static_cast<int64>(available.QuadPart); |
65 return rv < 0 ? kint64max : rv; | 63 return rv < 0 ? kint64max : rv; |
66 } | 64 } |
67 | 65 |
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 | |
81 File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN); | |
82 if (!drive.IsValid()) | |
83 return false; | |
84 | |
85 STORAGE_PROPERTY_QUERY query = {}; | |
86 query.QueryType = PropertyStandardQuery; | |
87 query.PropertyId = StorageDeviceSeekPenaltyProperty; | |
88 | |
89 DEVICE_SEEK_PENALTY_DESCRIPTOR result; | |
90 DWORD bytes_returned; | |
91 | |
92 BOOL success = DeviceIoControl(drive.GetPlatformFile(), | |
93 IOCTL_STORAGE_QUERY_PROPERTY, | |
94 &query, sizeof(query), | |
95 &result, sizeof(result), | |
96 &bytes_returned, | |
97 NULL); | |
98 if (success == FALSE || bytes_returned < sizeof(result)) | |
99 return false; | |
100 | |
101 *has_seek_penalty = result.IncursSeekPenalty != FALSE; | |
102 return true; | |
103 } | |
104 | |
105 // static | |
106 std::string SysInfo::OperatingSystemName() { | 66 std::string SysInfo::OperatingSystemName() { |
107 return "Windows NT"; | 67 return "Windows NT"; |
108 } | 68 } |
109 | 69 |
110 // static | 70 // static |
111 std::string SysInfo::OperatingSystemVersion() { | 71 std::string SysInfo::OperatingSystemVersion() { |
112 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 72 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
113 win::OSInfo::VersionNumber version_number = os_info->version_number(); | 73 win::OSInfo::VersionNumber version_number = os_info->version_number(); |
114 std::string version(StringPrintf("%d.%d", version_number.major, | 74 std::string version(StringPrintf("%d.%d", version_number.major, |
115 version_number.minor)); | 75 version_number.minor)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 116 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
157 int32* minor_version, | 117 int32* minor_version, |
158 int32* bugfix_version) { | 118 int32* bugfix_version) { |
159 win::OSInfo* os_info = win::OSInfo::GetInstance(); | 119 win::OSInfo* os_info = win::OSInfo::GetInstance(); |
160 *major_version = os_info->version_number().major; | 120 *major_version = os_info->version_number().major; |
161 *minor_version = os_info->version_number().minor; | 121 *minor_version = os_info->version_number().minor; |
162 *bugfix_version = 0; | 122 *bugfix_version = 0; |
163 } | 123 } |
164 | 124 |
165 } // namespace base | 125 } // namespace base |
OLD | NEW |