Dirty rects always contain full tiles with delegated rendering.
[chromium-blink-merge.git] / base / sys_info_posix.cc
blob07d08b72bbcb51fd8e550ab79409c55c6dff9af4
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/param.h>
10 #include <sys/utsname.h>
11 #include <unistd.h>
13 #include "base/basictypes.h"
14 #include "base/file_util.h"
15 #include "base/lazy_instance.h"
16 #include "base/logging.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/sys_info_internal.h"
19 #include "base/threading/thread_restrictions.h"
21 #if defined(OS_ANDROID)
22 #include <sys/vfs.h>
23 #define statvfs statfs // Android uses a statvfs-like statfs struct and call.
24 #else
25 #include <sys/statvfs.h>
26 #endif
28 namespace {
30 #if !defined(OS_OPENBSD)
31 int NumberOfProcessors() {
32 // It seems that sysconf returns the number of "logical" processors on both
33 // Mac and Linux. So we get the number of "online logical" processors.
34 long res = sysconf(_SC_NPROCESSORS_ONLN);
35 if (res == -1) {
36 NOTREACHED();
37 return 1;
40 return static_cast<int>(res);
43 base::LazyInstance<
44 base::internal::LazySysInfoValue<int, NumberOfProcessors> >::Leaky
45 g_lazy_number_of_processors = LAZY_INSTANCE_INITIALIZER;
46 #endif
48 } // namespace
50 namespace base {
52 #if !defined(OS_OPENBSD)
53 int SysInfo::NumberOfProcessors() {
54 return g_lazy_number_of_processors.Get().value();
56 #endif
58 // static
59 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
60 base::ThreadRestrictions::AssertIOAllowed();
62 struct statvfs stats;
63 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
64 return -1;
65 return static_cast<int64>(stats.f_bavail) * stats.f_frsize;
68 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
69 // static
70 std::string SysInfo::OperatingSystemName() {
71 struct utsname info;
72 if (uname(&info) < 0) {
73 NOTREACHED();
74 return std::string();
76 return std::string(info.sysname);
78 #endif
80 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
81 // static
82 std::string SysInfo::OperatingSystemVersion() {
83 struct utsname info;
84 if (uname(&info) < 0) {
85 NOTREACHED();
86 return std::string();
88 return std::string(info.release);
90 #endif
92 // static
93 std::string SysInfo::OperatingSystemArchitecture() {
94 struct utsname info;
95 if (uname(&info) < 0) {
96 NOTREACHED();
97 return std::string();
99 std::string arch(info.machine);
100 if (arch == "i386" || arch == "i486" || arch == "i586" || arch == "i686") {
101 arch = "x86";
102 } else if (arch == "amd64") {
103 arch = "x86_64";
105 return arch;
108 // static
109 size_t SysInfo::VMAllocationGranularity() {
110 return getpagesize();
113 } // namespace base