| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 int64 SysInfo::AmountOfAvailablePhysicalMemory() { | 35 int64 SysInfo::AmountOfAvailablePhysicalMemory() { |
| 36 return AmountOfMemory(_SC_AVPHYS_PAGES); | 36 return AmountOfMemory(_SC_AVPHYS_PAGES); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 size_t SysInfo::MaxSharedMemorySize() { | 40 size_t SysInfo::MaxSharedMemorySize() { |
| 41 static int64 limit; | 41 static int64 limit; |
| 42 static bool limit_valid = false; | 42 static bool limit_valid = false; |
| 43 if (!limit_valid) { | 43 if (!limit_valid) { |
| 44 std::string contents; | 44 std::string contents; |
| 45 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); | 45 ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); |
| 46 DCHECK(!contents.empty()); | 46 DCHECK(!contents.empty()); |
| 47 if (!contents.empty() && contents[contents.length() - 1] == '\n') { | 47 if (!contents.empty() && contents[contents.length() - 1] == '\n') { |
| 48 contents.erase(contents.length() - 1); | 48 contents.erase(contents.length() - 1); |
| 49 } | 49 } |
| 50 if (base::StringToInt64(contents, &limit)) { | 50 if (base::StringToInt64(contents, &limit)) { |
| 51 DCHECK(limit >= 0); | 51 DCHECK(limit >= 0); |
| 52 DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max()); | 52 DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max()); |
| 53 limit_valid = true; | 53 limit_valid = true; |
| 54 } else { | 54 } else { |
| 55 NOTREACHED(); | 55 NOTREACHED(); |
| 56 return 0; | 56 return 0; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 return static_cast<size_t>(limit); | 59 return static_cast<size_t>(limit); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // static | 62 // static |
| 63 std::string SysInfo::CPUModelName() { | 63 std::string SysInfo::CPUModelName() { |
| 64 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 64 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 65 const char kCpuModelPrefix[] = "Hardware"; | 65 const char kCpuModelPrefix[] = "Hardware"; |
| 66 #else | 66 #else |
| 67 const char kCpuModelPrefix[] = "model name"; | 67 const char kCpuModelPrefix[] = "model name"; |
| 68 #endif | 68 #endif |
| 69 std::string contents; | 69 std::string contents; |
| 70 file_util::ReadFileToString(FilePath("/proc/cpuinfo"), &contents); | 70 ReadFileToString(FilePath("/proc/cpuinfo"), &contents); |
| 71 DCHECK(!contents.empty()); | 71 DCHECK(!contents.empty()); |
| 72 if (!contents.empty()) { | 72 if (!contents.empty()) { |
| 73 std::istringstream iss(contents); | 73 std::istringstream iss(contents); |
| 74 std::string line; | 74 std::string line; |
| 75 while (std::getline(iss, line)) { | 75 while (std::getline(iss, line)) { |
| 76 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { | 76 if (line.compare(0, strlen(kCpuModelPrefix), kCpuModelPrefix) == 0) { |
| 77 size_t pos = line.find(": "); | 77 size_t pos = line.find(": "); |
| 78 return line.substr(pos + 2); | 78 return line.substr(pos + 2); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 return std::string(); | 82 return std::string(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace base | 85 } // namespace base |
| OLD | NEW |