| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 int SysInfo::NumberOfProcessors() { | 14 int SysInfo::NumberOfProcessors() { |
| 15 SYSTEM_INFO info; | 15 SYSTEM_INFO info; |
| 16 GetSystemInfo(&info); | 16 GetSystemInfo(&info); |
| 17 return static_cast<int>(info.dwNumberOfProcessors); | 17 return static_cast<int>(info.dwNumberOfProcessors); |
| 18 } | 18 } |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 int64 SysInfo::AmountOfPhysicalMemory() { | 21 int64 SysInfo::AmountOfPhysicalMemory() { |
| 22 MEMORYSTATUSEX memory_info; | 22 MEMORYSTATUSEX memory_info; |
| 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 return static_cast<int64>(memory_info.ullTotalPhys); | 29 int64 rv = static_cast<int64>(memory_info.ullTotalPhys); |
| 30 if (rv < 0) |
| 31 rv = kint64max; |
| 32 return rv; |
| 30 } | 33 } |
| 31 | 34 |
| 32 // static | 35 // static |
| 33 int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { | 36 int64 SysInfo::AmountOfFreeDiskSpace(const std::wstring& path) { |
| 34 ULARGE_INTEGER available, total, free; | 37 ULARGE_INTEGER available, total, free; |
| 35 if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { | 38 if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { |
| 36 return 0; | 39 return -1; |
| 37 } | 40 } |
| 38 return static_cast<int64>(available.QuadPart); | 41 int64 rv = static_cast<int64>(available.QuadPart); |
| 42 if (rv < 0) |
| 43 rv = kint64max; |
| 44 return rv; |
| 39 } | 45 } |
| 40 | 46 |
| 41 } // namespace base | 47 } // namespace base |
| OLD | NEW |