Index: base/sys_info_win.cc |
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc |
index d2c7bcddc148d1693946fbb26086f676f85b1423..232852f410f5d19ad430b57d1c30e79cff865257 100644 |
--- a/base/sys_info_win.cc |
+++ b/base/sys_info_win.cc |
@@ -30,6 +30,26 @@ int64_t AmountOfMemory(DWORDLONG MEMORYSTATUSEX::*memory_field) { |
return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; |
} |
+bool GetDiskSpaceInfo(const base::FilePath& path, |
+ int64_t* available_bytes, |
+ int64_t* total_bytes) { |
+ ULARGE_INTEGER available, total, free; |
Lei Zhang
2016/06/10 17:43:11
One variable per line here too, but don't worry ab
|
+ if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
+ return false; |
+ |
+ if (available_bytes) { |
+ *available_bytes = static_cast<int64_t>(available.QuadPart); |
+ if (*available_bytes < 0) |
+ *available_bytes = std::numeric_limits<int64_t>::max(); |
+ } |
+ if (total_bytes) { |
+ *total_bytes = static_cast<int64_t>(total.QuadPart); |
+ if (*total_bytes < 0) |
+ *total_bytes = std::numeric_limits<int64_t>::max(); |
+ } |
+ return true; |
+} |
+ |
} // namespace |
namespace base { |
@@ -58,12 +78,20 @@ int64_t SysInfo::AmountOfVirtualMemory() { |
int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
ThreadRestrictions::AssertIOAllowed(); |
- ULARGE_INTEGER available, total, free; |
- if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
+ int64_t available; |
+ if (!GetDiskSpaceInfo(path, &available, nullptr)) |
return -1; |
+ return available; |
+} |
- int64_t rv = static_cast<int64_t>(available.QuadPart); |
- return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; |
+// static |
+int64_t SysInfo::AmountOfTotalDiskSpace(const FilePath& path) { |
+ ThreadRestrictions::AssertIOAllowed(); |
+ |
+ int64_t total; |
+ if (!GetDiskSpaceInfo(path, nullptr, &total)) |
+ return -1; |
+ return total; |
} |
std::string SysInfo::OperatingSystemName() { |