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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/sys_info.h" | 6 #include "base/sys_info.h" |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <sys/statvfs.h> | 11 #include <sys/statvfs.h> |
12 #include <sys/utsname.h> | 12 #include <sys/utsname.h> |
13 #include <unistd.h> | 13 #include <unistd.h> |
14 | 14 |
15 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
| 16 #include <ApplicationServices/ApplicationServices.h> |
16 #include <mach/mach_host.h> | 17 #include <mach/mach_host.h> |
17 #include <mach/mach_init.h> | 18 #include <mach/mach_init.h> |
18 #endif | 19 #endif |
19 | 20 |
20 #if defined(OS_OPENBSD) | 21 #if defined(OS_OPENBSD) |
21 #include <sys/param.h> | 22 #include <sys/param.h> |
22 #include <sys/sysctl.h> | 23 #include <sys/sysctl.h> |
23 #endif | 24 #endif |
24 | 25 |
25 #include "base/logging.h" | 26 #include "base/logging.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 utsname info; | 136 utsname info; |
136 if (uname(&info) < 0) { | 137 if (uname(&info) < 0) { |
137 NOTREACHED(); | 138 NOTREACHED(); |
138 return ""; | 139 return ""; |
139 } | 140 } |
140 return std::string(info.machine); | 141 return std::string(info.machine); |
141 } | 142 } |
142 | 143 |
143 // static | 144 // static |
144 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { | 145 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 |
145 NOTIMPLEMENTED(); | 154 NOTIMPLEMENTED(); |
| 155 if (width) |
| 156 *width = 0; |
| 157 if (height) |
| 158 *height = 0; |
| 159 #endif |
146 } | 160 } |
147 | 161 |
148 // static | 162 // static |
149 int SysInfo::DisplayCount() { | 163 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 ++display_count; |
| 190 } |
| 191 } |
| 192 |
| 193 return display_count; |
| 194 #else |
| 195 // TODO(port): http://crbug.com/21732 |
150 NOTIMPLEMENTED(); | 196 NOTIMPLEMENTED(); |
151 return 1; | 197 return 1; |
| 198 #endif |
152 } | 199 } |
153 | 200 |
154 // static | 201 // static |
155 size_t SysInfo::VMAllocationGranularity() { | 202 size_t SysInfo::VMAllocationGranularity() { |
156 return getpagesize(); | 203 return getpagesize(); |
157 } | 204 } |
158 | 205 |
159 #if defined(OS_LINUX) | 206 #if defined(OS_LINUX) |
160 // static | 207 // static |
161 size_t SysInfo::MaxSharedMemorySize() { | 208 size_t SysInfo::MaxSharedMemorySize() { |
162 static size_t limit; | 209 static size_t limit; |
163 static bool limit_valid = false; | 210 static bool limit_valid = false; |
164 | 211 |
165 if (!limit_valid) { | 212 if (!limit_valid) { |
166 std::string contents; | 213 std::string contents; |
167 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | 214 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); |
168 limit = strtoul(contents.c_str(), NULL, 0); | 215 limit = strtoul(contents.c_str(), NULL, 0); |
169 limit_valid = true; | 216 limit_valid = true; |
170 } | 217 } |
171 | 218 |
172 return limit; | 219 return limit; |
173 } | 220 } |
174 #endif | 221 #endif |
175 | 222 |
176 } // namespace base | 223 } // namespace base |
OLD | NEW |