Add FaviconURLUpdated method to WebStateObserver
[chromium-blink-merge.git] / base / sys_info_ios.mm
blob324bef6b839d9174d9951046f67ad7510c246fe6
1 // Copyright (c) 2012 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 #import <UIKit/UIKit.h>
8 #include <mach/mach.h>
9 #include <sys/sysctl.h>
10 #include <sys/types.h>
12 #include "base/logging.h"
13 #include "base/mac/scoped_mach_port.h"
14 #include "base/mac/scoped_nsautorelease_pool.h"
15 #include "base/strings/sys_string_conversions.h"
17 namespace base {
19 bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) {
20   // Find a case where this is incorrect and dbeam@ will buy you a beer.
21   *has_seek_penalty = false;
22   return true;
25 // static
26 std::string SysInfo::OperatingSystemName() {
27   static dispatch_once_t get_system_name_once;
28   static std::string* system_name;
29   dispatch_once(&get_system_name_once, ^{
30       base::mac::ScopedNSAutoreleasePool pool;
31       system_name = new std::string(
32           SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
33   });
34   // Examples of returned value: 'iPhone OS' on iPad 5.1.1
35   // and iPhone 5.1.1.
36   return *system_name;
39 // static
40 std::string SysInfo::OperatingSystemVersion() {
41   static dispatch_once_t get_system_version_once;
42   static std::string* system_version;
43   dispatch_once(&get_system_version_once, ^{
44       base::mac::ScopedNSAutoreleasePool pool;
45       system_version = new std::string(
46           SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
47   });
48   return *system_version;
51 // static
52 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
53                                             int32* minor_version,
54                                             int32* bugfix_version) {
55   base::mac::ScopedNSAutoreleasePool pool;
56   std::string system_version = OperatingSystemVersion();
57   if (!system_version.empty()) {
58     // Try to parse out the version numbers from the string.
59     int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
60                           minor_version, bugfix_version);
61     if (num_read < 1)
62       *major_version = 0;
63     if (num_read < 2)
64       *minor_version = 0;
65     if (num_read < 3)
66       *bugfix_version = 0;
67   }
70 // static
71 int64 SysInfo::AmountOfPhysicalMemory() {
72   struct host_basic_info hostinfo;
73   mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
74   base::mac::ScopedMachSendRight host(mach_host_self());
75   int result = host_info(host,
76                          HOST_BASIC_INFO,
77                          reinterpret_cast<host_info_t>(&hostinfo),
78                          &count);
79   if (result != KERN_SUCCESS) {
80     NOTREACHED();
81     return 0;
82   }
83   DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
84   return static_cast<int64>(hostinfo.max_mem);
87 // static
88 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
89   base::mac::ScopedMachSendRight host(mach_host_self());
90   vm_statistics_data_t vm_info;
91   mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
92   if (host_statistics(host.get(),
93                       HOST_VM_INFO,
94                       reinterpret_cast<host_info_t>(&vm_info),
95                       &count) != KERN_SUCCESS) {
96     NOTREACHED();
97     return 0;
98   }
100   return static_cast<int64>(
101       vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE;
104 // static
105 std::string SysInfo::CPUModelName() {
106   char name[256];
107   size_t len = arraysize(name);
108   if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
109     return name;
110   return std::string();
113 }  // namespace base