| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/statvfs.h> | 9 #include <sys/statvfs.h> |
| 10 #include <sys/utsname.h> | 10 #include <sys/utsname.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #if defined(OS_MACOSX) | |
| 14 #include <ApplicationServices/ApplicationServices.h> | |
| 15 #include <mach/mach_host.h> | |
| 16 #include <mach/mach_init.h> | |
| 17 #endif | |
| 18 | |
| 19 #if defined(OS_OPENBSD) | 13 #if defined(OS_OPENBSD) |
| 20 #include <sys/param.h> | 14 #include <sys/param.h> |
| 21 #include <sys/sysctl.h> | 15 #include <sys/sysctl.h> |
| 22 #endif | 16 #endif |
| 23 | 17 |
| 24 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 25 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 26 #include "base/logging.h" | 20 #include "base/logging.h" |
| 27 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 28 | 22 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 46 NOTREACHED(); | 40 NOTREACHED(); |
| 47 return 1; | 41 return 1; |
| 48 } | 42 } |
| 49 | 43 |
| 50 return static_cast<int>(res); | 44 return static_cast<int>(res); |
| 51 #endif | 45 #endif |
| 52 } | 46 } |
| 53 | 47 |
| 54 // static | 48 // static |
| 55 int64 SysInfo::AmountOfPhysicalMemory() { | 49 int64 SysInfo::AmountOfPhysicalMemory() { |
| 50 #if defined(OS_FREEBSD) |
| 56 // _SC_PHYS_PAGES is not part of POSIX and not available on OS X or | 51 // _SC_PHYS_PAGES is not part of POSIX and not available on OS X or |
| 57 // FreeBSD | 52 // FreeBSD |
| 58 #if defined(OS_MACOSX) | |
| 59 struct host_basic_info hostinfo; | |
| 60 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; | |
| 61 int result = host_info(mach_host_self(), | |
| 62 HOST_BASIC_INFO, | |
| 63 reinterpret_cast<host_info_t>(&hostinfo), | |
| 64 &count); | |
| 65 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); | |
| 66 if (result != KERN_SUCCESS) { | |
| 67 NOTREACHED(); | |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 71 return static_cast<int64>(hostinfo.max_mem); | |
| 72 #elif defined(OS_FREEBSD) | |
| 73 // TODO(benl): I have no idea how to get this | 53 // TODO(benl): I have no idea how to get this |
| 74 NOTIMPLEMENTED(); | 54 NOTIMPLEMENTED(); |
| 75 return 0; | 55 return 0; |
| 76 #else | 56 #else |
| 77 long pages = sysconf(_SC_PHYS_PAGES); | 57 long pages = sysconf(_SC_PHYS_PAGES); |
| 78 long page_size = sysconf(_SC_PAGE_SIZE); | 58 long page_size = sysconf(_SC_PAGE_SIZE); |
| 79 if (pages == -1 || page_size == -1) { | 59 if (pages == -1 || page_size == -1) { |
| 80 NOTREACHED(); | 60 NOTREACHED(); |
| 81 return 0; | 61 return 0; |
| 82 } | 62 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 utsname info; | 116 utsname info; |
| 137 if (uname(&info) < 0) { | 117 if (uname(&info) < 0) { |
| 138 NOTREACHED(); | 118 NOTREACHED(); |
| 139 return ""; | 119 return ""; |
| 140 } | 120 } |
| 141 return std::string(info.machine); | 121 return std::string(info.machine); |
| 142 } | 122 } |
| 143 | 123 |
| 144 // static | 124 // static |
| 145 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { | 125 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { |
| 146 #if defined(OS_MACOSX) | |
| 147 CGDirectDisplayID main_display = CGMainDisplayID(); | |
| 148 if (width) | |
| 149 *width = CGDisplayPixelsWide(main_display); | |
| 150 if (height) | |
| 151 *height = CGDisplayPixelsHigh(main_display); | |
| 152 #else | |
| 153 // TODO(port): http://crbug.com/21732 | 126 // TODO(port): http://crbug.com/21732 |
| 154 NOTIMPLEMENTED(); | 127 NOTIMPLEMENTED(); |
| 155 if (width) | 128 if (width) |
| 156 *width = 0; | 129 *width = 0; |
| 157 if (height) | 130 if (height) |
| 158 *height = 0; | 131 *height = 0; |
| 159 #endif | |
| 160 } | 132 } |
| 161 | 133 |
| 162 // static | 134 // static |
| 163 int SysInfo::DisplayCount() { | 135 int SysInfo::DisplayCount() { |
| 164 #if defined(OS_MACOSX) | |
| 165 // Don't just return the number of online displays. It includes displays | |
| 166 // that mirror other displays, which are not desired in the count. It's | |
| 167 // tempting to use the count returned by CGGetActiveDisplayList, but active | |
| 168 // displays exclude sleeping displays, and those are desired in the count. | |
| 169 | |
| 170 // It would be ridiculous to have this many displays connected, but | |
| 171 // CGDirectDisplayID is just an integer, so supporting up to this many | |
| 172 // doesn't hurt. | |
| 173 CGDirectDisplayID online_displays[128]; | |
| 174 CGDisplayCount online_display_count = 0; | |
| 175 if (CGGetOnlineDisplayList(arraysize(online_displays), | |
| 176 online_displays, | |
| 177 &online_display_count) != kCGErrorSuccess) { | |
| 178 // 1 is a reasonable assumption. | |
| 179 return 1; | |
| 180 } | |
| 181 | |
| 182 int display_count = 0; | |
| 183 for (CGDisplayCount online_display_index = 0; | |
| 184 online_display_index < online_display_count; | |
| 185 ++online_display_index) { | |
| 186 CGDirectDisplayID online_display = online_displays[online_display_index]; | |
| 187 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { | |
| 188 // If this display doesn't mirror any other, include it in the count. | |
| 189 // The primary display in a mirrored set will be counted, but those that | |
| 190 // mirror it will not be. | |
| 191 ++display_count; | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 return display_count; | |
| 196 #else | |
| 197 // TODO(port): http://crbug.com/21732 | 136 // TODO(port): http://crbug.com/21732 |
| 198 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 199 return 1; | 138 return 1; |
| 200 #endif | |
| 201 } | 139 } |
| 202 | 140 |
| 203 // static | 141 // static |
| 204 size_t SysInfo::VMAllocationGranularity() { | 142 size_t SysInfo::VMAllocationGranularity() { |
| 205 return getpagesize(); | 143 return getpagesize(); |
| 206 } | 144 } |
| 207 | 145 |
| 208 #if defined(OS_LINUX) | 146 #if defined(OS_LINUX) |
| 209 // static | 147 // static |
| 210 size_t SysInfo::MaxSharedMemorySize() { | 148 size_t SysInfo::MaxSharedMemorySize() { |
| 211 static size_t limit; | 149 static size_t limit; |
| 212 static bool limit_valid = false; | 150 static bool limit_valid = false; |
| 213 | 151 |
| 214 if (!limit_valid) { | 152 if (!limit_valid) { |
| 215 std::string contents; | 153 std::string contents; |
| 216 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | 154 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); |
| 217 limit = strtoul(contents.c_str(), NULL, 0); | 155 limit = strtoul(contents.c_str(), NULL, 0); |
| 218 limit_valid = true; | 156 limit_valid = true; |
| 219 } | 157 } |
| 220 | 158 |
| 221 return limit; | 159 return limit; |
| 222 } | 160 } |
| 223 #endif | 161 #endif |
| 224 | 162 |
| 225 } // namespace base | 163 } // namespace base |
| OLD | NEW |