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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 12 matching lines...) Expand all
23 memory_info.dwLength = sizeof(memory_info); 23 memory_info.dwLength = sizeof(memory_info);
24 if (!GlobalMemoryStatusEx(&memory_info)) { 24 if (!GlobalMemoryStatusEx(&memory_info)) {
25 NOTREACHED(); 25 NOTREACHED();
26 return 0; 26 return 0;
27 } 27 }
28 28
29 int64_t rv = static_cast<int64_t>(memory_info.*memory_field); 29 int64_t rv = static_cast<int64_t>(memory_info.*memory_field);
30 return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; 30 return rv < 0 ? std::numeric_limits<int64_t>::max() : rv;
31 } 31 }
32 32
33 bool GetDiskSpaceInfo(const base::FilePath& path,
34 int64_t* available_bytes,
35 int64_t* total_bytes) {
36 ULARGE_INTEGER available, total, free;
Lei Zhang 2016/06/10 17:43:11 One variable per line here too, but don't worry ab
37 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free))
38 return false;
39
40 if (available_bytes) {
41 *available_bytes = static_cast<int64_t>(available.QuadPart);
42 if (*available_bytes < 0)
43 *available_bytes = std::numeric_limits<int64_t>::max();
44 }
45 if (total_bytes) {
46 *total_bytes = static_cast<int64_t>(total.QuadPart);
47 if (*total_bytes < 0)
48 *total_bytes = std::numeric_limits<int64_t>::max();
49 }
50 return true;
51 }
52
33 } // namespace 53 } // namespace
34 54
35 namespace base { 55 namespace base {
36 56
37 // static 57 // static
38 int SysInfo::NumberOfProcessors() { 58 int SysInfo::NumberOfProcessors() {
39 return win::OSInfo::GetInstance()->processors(); 59 return win::OSInfo::GetInstance()->processors();
40 } 60 }
41 61
42 // static 62 // static
43 int64_t SysInfo::AmountOfPhysicalMemory() { 63 int64_t SysInfo::AmountOfPhysicalMemory() {
44 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); 64 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys);
45 } 65 }
46 66
47 // static 67 // static
48 int64_t SysInfo::AmountOfAvailablePhysicalMemory() { 68 int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
49 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); 69 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys);
50 } 70 }
51 71
52 // static 72 // static
53 int64_t SysInfo::AmountOfVirtualMemory() { 73 int64_t SysInfo::AmountOfVirtualMemory() {
54 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalVirtual); 74 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalVirtual);
55 } 75 }
56 76
57 // static 77 // static
58 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 78 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
59 ThreadRestrictions::AssertIOAllowed(); 79 ThreadRestrictions::AssertIOAllowed();
60 80
61 ULARGE_INTEGER available, total, free; 81 int64_t available;
62 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) 82 if (!GetDiskSpaceInfo(path, &available, nullptr))
63 return -1; 83 return -1;
84 return available;
85 }
64 86
65 int64_t rv = static_cast<int64_t>(available.QuadPart); 87 // static
66 return rv < 0 ? std::numeric_limits<int64_t>::max() : rv; 88 int64_t SysInfo::AmountOfTotalDiskSpace(const FilePath& path) {
89 ThreadRestrictions::AssertIOAllowed();
90
91 int64_t total;
92 if (!GetDiskSpaceInfo(path, nullptr, &total))
93 return -1;
94 return total;
67 } 95 }
68 96
69 std::string SysInfo::OperatingSystemName() { 97 std::string SysInfo::OperatingSystemName() {
70 return "Windows NT"; 98 return "Windows NT";
71 } 99 }
72 100
73 // static 101 // static
74 std::string SysInfo::OperatingSystemVersion() { 102 std::string SysInfo::OperatingSystemVersion() {
75 win::OSInfo* os_info = win::OSInfo::GetInstance(); 103 win::OSInfo* os_info = win::OSInfo::GetInstance();
76 win::OSInfo::VersionNumber version_number = os_info->version_number(); 104 win::OSInfo::VersionNumber version_number = os_info->version_number();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version, 148 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
121 int32_t* minor_version, 149 int32_t* minor_version,
122 int32_t* bugfix_version) { 150 int32_t* bugfix_version) {
123 win::OSInfo* os_info = win::OSInfo::GetInstance(); 151 win::OSInfo* os_info = win::OSInfo::GetInstance();
124 *major_version = os_info->version_number().major; 152 *major_version = os_info->version_number().major;
125 *minor_version = os_info->version_number().minor; 153 *minor_version = os_info->version_number().minor;
126 *bugfix_version = 0; 154 *bugfix_version = 0;
127 } 155 }
128 156
129 } // namespace base 157 } // namespace base
OLDNEW
« 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