Chromium Code Reviews| Index: base/sys_info_win.cc |
| diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc |
| index 9cc0cfa48a3637d48c36978de2c798383e9a194d..a65ea6895575bc4175fa496ce1af163848a3617b 100644 |
| --- a/base/sys_info_win.cc |
| +++ b/base/sys_info_win.cc |
| @@ -5,7 +5,9 @@ |
| #include "base/sys_info.h" |
| #include <windows.h> |
| +#include <winioctl.h> |
| +#include "base/files/file.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -24,9 +26,7 @@ int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { |
| } |
| int64 rv = static_cast<int64>(memory_info.*memory_field); |
| - if (rv < 0) |
| - rv = kint64max; |
| - return rv; |
| + return rv < 0 ? kint64max : rv; |
| } |
| } // namespace |
| @@ -55,16 +55,46 @@ int64 SysInfo::AmountOfVirtualMemory() { |
| // static |
| int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
| - base::ThreadRestrictions::AssertIOAllowed(); |
| + ThreadRestrictions::AssertIOAllowed(); |
| ULARGE_INTEGER available, total, free; |
| - if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { |
| + if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
| return -1; |
| - } |
| + |
| int64 rv = static_cast<int64>(available.QuadPart); |
| - if (rv < 0) |
| - rv = kint64max; |
| - return rv; |
| + return rv < 0 ? kint64max : rv; |
| +} |
| + |
| +bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { |
| + ThreadRestrictions::AssertIOAllowed(); |
| + |
| + DCHECK(has_seek_penalty); |
| + |
| + // TODO(dbeam): Vista, XP support. |
| + if (!path.IsAbsolute() || win::GetVersion() < win::VERSION_WIN7) |
|
rvargas (doing something else)
2015/03/13 21:03:09
I have not heard why allowing callers to use relat
Dan Beam
2015/03/13 21:15:51
Done. (changed to DCHECK)
|
| + return false; |
| + |
| + std::vector<FilePath::StringType> components; |
| + native_path.GetComponents(&components); |
| + File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN); |
|
rvargas (doing something else)
2015/03/13 21:03:09
Still requires if (!drive.IsValid())...
Dan Beam
2015/03/13 21:15:51
Done.
|
| + |
| + STORAGE_PROPERTY_QUERY query; |
| + query.QueryType = PropertyStandardQuery; |
| + query.PropertyId = StorageDeviceSeekPenaltyProperty; |
| + |
| + DEVICE_SEEK_PENALTY_DESCRIPTOR result; |
| + |
| + success = DeviceIoControl(drive.GetPlatformFile(), |
| + IOCTL_STORAGE_QUERY_PROPERTY, |
| + &query, sizeof(query), |
| + &result, sizeof(result), |
| + &bytes_returned, |
|
rvargas (doing something else)
2015/03/13 21:03:09
not defined?
Dan Beam
2015/03/13 21:15:51
whoops, Done.
|
| + NULL); |
| + if (success == FALSE || bytes_returned < sizeof(result)) |
| + return false; |
| + |
| + *has_seek_penalty = result.IncursSeekPenalty == TRUE; |
|
rvargas (doing something else)
2015/03/13 21:03:09
Comparing against TRUE is not a good idea (in gene
Dan Beam
2015/03/13 21:15:51
Done.
|
| + return true; |
| } |
| // static |