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

Side by Side Diff: base/sys_info_win.cc

Issue 13945012: Implement missing SysInfo methods on OpenBSD (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test sysctl() < 0 instead of == -1 Created 7 years, 8 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_openbsd.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 15
16 namespace base { 16 namespace {
17 17
18 // static 18 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) {
19 int SysInfo::NumberOfProcessors() {
20 return win::OSInfo::GetInstance()->processors();
21 }
22
23 // static
24 int64 SysInfo::AmountOfPhysicalMemory() {
25 MEMORYSTATUSEX memory_info; 19 MEMORYSTATUSEX memory_info;
26 memory_info.dwLength = sizeof(memory_info); 20 memory_info.dwLength = sizeof(memory_info);
27 if (!GlobalMemoryStatusEx(&memory_info)) { 21 if (!GlobalMemoryStatusEx(&memory_info)) {
28 NOTREACHED(); 22 NOTREACHED();
29 return 0; 23 return 0;
30 } 24 }
31 25
32 int64 rv = static_cast<int64>(memory_info.ullTotalPhys); 26 int64 rv = static_cast<int64>(memory_info.*memory_field);
33 if (rv < 0) 27 if (rv < 0)
34 rv = kint64max; 28 rv = kint64max;
35 return rv; 29 return rv;
36 } 30 }
37 31
32 } // namespace
33
34 namespace base {
35
38 // static 36 // static
39 int64 SysInfo::AmountOfAvailablePhysicalMemory() { 37 int SysInfo::NumberOfProcessors() {
40 MEMORYSTATUSEX memory_info; 38 return win::OSInfo::GetInstance()->processors();
41 memory_info.dwLength = sizeof(memory_info);
42 if (!GlobalMemoryStatusEx(&memory_info)) {
43 NOTREACHED();
44 return 0;
45 }
46
47 int64 rv = static_cast<int64>(memory_info.ullAvailPhys);
48 if (rv < 0)
49 rv = kint64max;
50 return rv;
51 } 39 }
52 40
53 // static 41 // static
42 int64 SysInfo::AmountOfPhysicalMemory() {
43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys);
44 }
45
46 // static
47 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys);
49 }
50
51 // static
54 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 52 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
55 base::ThreadRestrictions::AssertIOAllowed(); 53 base::ThreadRestrictions::AssertIOAllowed();
56 54
57 ULARGE_INTEGER available, total, free; 55 ULARGE_INTEGER available, total, free;
58 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { 56 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
59 return -1; 57 return -1;
60 } 58 }
61 int64 rv = static_cast<int64>(available.QuadPart); 59 int64 rv = static_cast<int64>(available.QuadPart);
62 if (rv < 0) 60 if (rv < 0)
63 rv = kint64max; 61 rv = kint64max;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, 116 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
119 int32* minor_version, 117 int32* minor_version,
120 int32* bugfix_version) { 118 int32* bugfix_version) {
121 win::OSInfo* os_info = win::OSInfo::GetInstance(); 119 win::OSInfo* os_info = win::OSInfo::GetInstance();
122 *major_version = os_info->version_number().major; 120 *major_version = os_info->version_number().major;
123 *minor_version = os_info->version_number().minor; 121 *minor_version = os_info->version_number().minor;
124 *bugfix_version = 0; 122 *bugfix_version = 0;
125 } 123 }
126 124
127 } // namespace base 125 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_openbsd.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698