Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2919)

Unified Diff: base/sys_info_win.cc

Issue 2052663003: Move implementation of QuotaManager.getVolumeInfo to base::SysInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add AmountOfTotalDiskSpace() instead of GetDiskSpaceInfo(). Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info_unittest.cc ('k') | storage/browser/quota/quota_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « base/sys_info_unittest.cc ('k') | storage/browser/quota/quota_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698