[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/sys_info.h" |
| 6 | |
| 7 | #include <windows.h> |
| 8 | |
[email protected] | 13326bb | 2009-10-14 00:41:56 | [diff] [blame] | 9 | #include "base/file_path.h" |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | f163393 | 2010-08-17 23:05:28 | [diff] [blame] | 12 | #include "base/stringprintf.h" |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 13 | #include "base/win/windows_version.h" |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 14 | |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 15 | namespace base { |
| 16 | |
| 17 | // static |
| 18 | int SysInfo::NumberOfProcessors() { |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 19 | return win::OSInfo::GetInstance()->processors(); |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 22 | // static |
| 23 | int64 SysInfo::AmountOfPhysicalMemory() { |
| 24 | MEMORYSTATUSEX memory_info; |
| 25 | memory_info.dwLength = sizeof(memory_info); |
| 26 | if (!GlobalMemoryStatusEx(&memory_info)) { |
| 27 | NOTREACHED(); |
| 28 | return 0; |
| 29 | } |
| 30 | |
[email protected] | 02ee34a | 2008-09-20 01:16:23 | [diff] [blame] | 31 | int64 rv = static_cast<int64>(memory_info.ullTotalPhys); |
| 32 | if (rv < 0) |
| 33 | rv = kint64max; |
| 34 | return rv; |
[email protected] | d632798e | 2008-09-17 13:10:45 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 37 | // static |
[email protected] | 13326bb | 2009-10-14 00:41:56 | [diff] [blame] | 38 | int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 39 | ULARGE_INTEGER available, total, free; |
[email protected] | 13326bb | 2009-10-14 00:41:56 | [diff] [blame] | 40 | if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { |
[email protected] | 02ee34a | 2008-09-20 01:16:23 | [diff] [blame] | 41 | return -1; |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 42 | } |
[email protected] | 02ee34a | 2008-09-20 01:16:23 | [diff] [blame] | 43 | int64 rv = static_cast<int64>(available.QuadPart); |
| 44 | if (rv < 0) |
| 45 | rv = kint64max; |
| 46 | return rv; |
[email protected] | 0e91dd2 | 2008-09-18 12:34:24 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 49 | // static |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 50 | std::string SysInfo::OperatingSystemName() { |
| 51 | return "Windows NT"; |
| 52 | } |
| 53 | |
| 54 | // static |
| 55 | std::string SysInfo::OperatingSystemVersion() { |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 56 | win::OSInfo* os_info = win::OSInfo::GetInstance(); |
| 57 | win::OSInfo::VersionNumber version_number = os_info->version_number(); |
| 58 | std::string version(StringPrintf("%d.%d", version_number.major, |
| 59 | version_number.minor)); |
| 60 | win::OSInfo::ServicePack service_pack = os_info->service_pack(); |
| 61 | if (service_pack.major != 0) { |
| 62 | version += StringPrintf(" SP%d", service_pack.major); |
| 63 | if (service_pack.minor != 0) |
| 64 | version += StringPrintf(".%d", service_pack.minor); |
| 65 | } |
| 66 | return version; |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // TODO: Implement OperatingSystemVersionComplete, which would include |
[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 70 | // patchlevel/service pack number. |
| 71 | // See chrome/browser/ui/views/bug_report_view.cc, BugReportView::SetOSVersion. |
[email protected] | 05f9b68 | 2008-09-29 22:18:01 | [diff] [blame] | 72 | |
| 73 | // static |
| 74 | std::string SysInfo::CPUArchitecture() { |
| 75 | // TODO: Make this vary when we support any other architectures. |
| 76 | return "x86"; |
| 77 | } |
| 78 | |
| 79 | // static |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 80 | size_t SysInfo::VMAllocationGranularity() { |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 81 | return win::OSInfo::GetInstance()->allocation_granularity(); |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 84 | // static |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 85 | void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
| 86 | int32* minor_version, |
| 87 | int32* bugfix_version) { |
| 88 | win::OSInfo* os_info = win::OSInfo::GetInstance(); |
| 89 | *major_version = os_info->version_number().major; |
| 90 | *minor_version = os_info->version_number().minor; |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 91 | *bugfix_version = 0; |
| 92 | } |
| 93 | |
[email protected] | 2a758d61 | 2008-09-17 10:09:39 | [diff] [blame] | 94 | } // namespace base |