Chromium Code Reviews| 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 #include "base/scoped_ptr.h" | |
| 11 #include "base/string_util.h" | |
| 10 | 12 |
| 11 namespace base { | 13 namespace base { |
| 12 | 14 |
| 13 // static | 15 // static |
| 14 int SysInfo::NumberOfProcessors() { | 16 int SysInfo::NumberOfProcessors() { |
| 15 SYSTEM_INFO info; | 17 SYSTEM_INFO info; |
| 16 GetSystemInfo(&info); | 18 GetSystemInfo(&info); |
| 17 return static_cast<int>(info.dwNumberOfProcessors); | 19 return static_cast<int>(info.dwNumberOfProcessors); |
| 18 } | 20 } |
| 19 | 21 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 37 ULARGE_INTEGER available, total, free; | 39 ULARGE_INTEGER available, total, free; |
| 38 if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { | 40 if (!GetDiskFreeSpaceExW(path.c_str(), &available, &total, &free)) { |
| 39 return -1; | 41 return -1; |
| 40 } | 42 } |
| 41 int64 rv = static_cast<int64>(available.QuadPart); | 43 int64 rv = static_cast<int64>(available.QuadPart); |
| 42 if (rv < 0) | 44 if (rv < 0) |
| 43 rv = kint64max; | 45 rv = kint64max; |
| 44 return rv; | 46 return rv; |
| 45 } | 47 } |
| 46 | 48 |
| 49 // static | |
| 50 bool SysInfo::HasEnvironmentVariable(const char* var) { | |
| 51 std::wstring wide_var = ASCIIToWide(std::string(var)); | |
| 52 return GetEnvironmentVariable(wide_var.c_str(), NULL, 0) != 0; | |
| 53 } | |
| 54 | |
| 55 // static | |
| 56 std::wstring SysInfo::GetEnvironmentVariable(const char* var) { | |
|
Mark Mentovai
2008/09/29 22:20:05
There's a problem here. On Windows, the platform
| |
| 57 std::wstring wide_var = ASCIIToWide(std::string(var)); | |
| 58 DWORD value_length = GetEnvironmentVariable(wide_var.c_str(), NULL, 0); | |
| 59 if (value_length == 0) { | |
| 60 return L""; | |
| 61 } | |
| 62 scoped_array<wchar_t> value(new wchar_t[value_length]); | |
| 63 GetEnvironmentVariable(wide_var.c_str(), value.get(), value_length); | |
| 64 return std::wstring(value); | |
|
Mark Mentovai
2008/09/29 22:20:05
Changed this to value.get().
| |
| 65 } | |
| 66 | |
| 67 // static | |
| 68 std::string SysInfo::OperatingSystemName() { | |
| 69 return "Windows NT"; | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 std::string SysInfo::OperatingSystemVersion() { | |
| 74 OSVERSIONINFO info = {0}; | |
| 75 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
| 76 GetVersionEx(&info); | |
| 77 | |
| 78 return StringPrintf("%lu.%lu", info.dwMajorVersion, info.dwMinorVersion); | |
| 79 } | |
| 80 | |
| 81 // TODO: Implement OperatingSystemVersionComplete, which would include | |
| 82 // patchlevel/service pack number. See chrome/browser/views/bug_report_view.cc, | |
| 83 // BugReportView::SetOSVersion. | |
| 84 | |
| 85 // static | |
| 86 std::string SysInfo::CPUArchitecture() { | |
| 87 // TODO: Make this vary when we support any other architectures. | |
| 88 return "x86"; | |
| 89 } | |
| 90 | |
| 91 // static | |
| 92 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { | |
| 93 if (width) | |
| 94 *width = GetSystemMetrics(SM_CXSCREEN); | |
| 95 | |
| 96 if (height) | |
| 97 *height = GetSystemMetrics(SM_CYSCREEN); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 int SysInfo::DisplayCount() { | |
| 102 return GetSystemMetrics(SM_CMONITORS); | |
| 103 } | |
| 104 | |
| 47 } // namespace base | 105 } // namespace base |
| OLD | NEW |