summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 20:14:54 +0000
committerdglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 20:14:54 +0000
commitf4d56d16feb0e39aa9ca39e75425b404aeaf3914 (patch)
treea62bccbe81824787291e9608c3bad1faee8fe037 /base
parent80b94a3918114dbc4adf5c73fe3fcfa5adc6720a (diff)
downloadchromium_src-f4d56d16feb0e39aa9ca39e75425b404aeaf3914.zip
chromium_src-f4d56d16feb0e39aa9ca39e75425b404aeaf3914.tar.gz
chromium_src-f4d56d16feb0e39aa9ca39e75425b404aeaf3914.tar.bz2
Revert 231613 "Enable SysInfo::AmountOfPhysicalMemory to be call..."
> Enable SysInfo::AmountOfPhysicalMemory to be called from within the Linux sandbox. > > Trigger caching of SysInfo::AmountOfPhysicalMemory in PreSandboxInit() to enable > it to be called by the renderer process after the sandbox is sealed. > > BUG=312241 > > Review URL: https://codereview.chromium.org/28833002 TBR=rmcilroy@chromium.org Review URL: https://codereview.chromium.org/51223003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/sys_info.h3
-rw-r--r--base/sys_info_linux.cc101
2 files changed, 36 insertions, 68 deletions
diff --git a/base/sys_info.h b/base/sys_info.h
index aa40cad..ba45bfc 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -75,8 +75,7 @@ class BASE_EXPORT SysInfo {
static size_t VMAllocationGranularity();
#if defined(OS_POSIX) && !defined(OS_MACOSX)
- // Returns the maximum SysV shared memory segment size, or zero if there is no
- // limit.
+ // Returns the maximum SysV shared memory segment size.
static size_t MaxSharedMemorySize();
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index c862145..acc4771 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -7,7 +7,6 @@
#include <limits>
#include "base/file_util.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -23,34 +22,52 @@ int64 AmountOfMemory(int pages_name) {
return static_cast<int64>(pages) * page_size;
}
-size_t MaxSharedMemorySize() {
- std::string contents;
- base::ReadFileToString(base::FilePath("/proc/sys/kernel/shmmax"), &contents);
- DCHECK(!contents.empty());
- if (!contents.empty() && contents[contents.length() - 1] == '\n') {
- contents.erase(contents.length() - 1);
- }
+} // namespace
- int64 limit;
- if (!base::StringToInt64(contents, &limit)) {
- limit = 0;
- }
- if (limit < 0 ||
- static_cast<uint64>(limit) > std::numeric_limits<size_t>::max()) {
- limit = 0;
+namespace base {
+
+// static
+int64 SysInfo::AmountOfPhysicalMemory() {
+ return AmountOfMemory(_SC_PHYS_PAGES);
+}
+
+// static
+int64 SysInfo::AmountOfAvailablePhysicalMemory() {
+ return AmountOfMemory(_SC_AVPHYS_PAGES);
+}
+
+// static
+size_t SysInfo::MaxSharedMemorySize() {
+ static int64 limit;
+ static bool limit_valid = false;
+ if (!limit_valid) {
+ std::string contents;
+ ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
+ DCHECK(!contents.empty());
+ if (!contents.empty() && contents[contents.length() - 1] == '\n') {
+ contents.erase(contents.length() - 1);
+ }
+ if (base::StringToInt64(contents, &limit)) {
+ DCHECK(limit >= 0);
+ DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
+ limit_valid = true;
+ } else {
+ NOTREACHED();
+ return 0;
+ }
}
- DCHECK(limit > 0);
return static_cast<size_t>(limit);
}
-std::string CPUModelName() {
+// static
+std::string SysInfo::CPUModelName() {
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
const char kCpuModelPrefix[] = "Hardware";
#else
const char kCpuModelPrefix[] = "model name";
#endif
std::string contents;
- base::ReadFileToString(base::FilePath("/proc/cpuinfo"), &contents);
+ ReadFileToString(FilePath("/proc/cpuinfo"), &contents);
DCHECK(!contents.empty());
if (!contents.empty()) {
std::istringstream iss(contents);
@@ -65,52 +82,4 @@ std::string CPUModelName() {
return std::string();
}
-class LazySysInfo {
- public:
- LazySysInfo()
- : kPhysicalMemory_(AmountOfMemory(_SC_PHYS_PAGES)),
- kMaxSharedMemorySize_(MaxSharedMemorySize()),
- kCpuModelName_(CPUModelName()) { }
-
- ~LazySysInfo() { }
-
- int64 physical_memory() { return kPhysicalMemory_; }
- size_t max_shared_memory_size() { return kMaxSharedMemorySize_; }
- std::string cpu_model_name() { return kCpuModelName_; }
-
- private:
- const int64 kPhysicalMemory_;
- const size_t kMaxSharedMemorySize_;
- const std::string kCpuModelName_;
-
- DISALLOW_COPY_AND_ASSIGN(LazySysInfo);
-};
-
-base::LazyInstance<LazySysInfo>::Leaky
- g_lazy_sys_info = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-namespace base {
-
-// static
-int64 SysInfo::AmountOfAvailablePhysicalMemory() {
- return AmountOfMemory(_SC_AVPHYS_PAGES);
-}
-
-// static
-int64 SysInfo::AmountOfPhysicalMemory() {
- return g_lazy_sys_info.Get().physical_memory();
-}
-
-// static
-size_t SysInfo::MaxSharedMemorySize() {
- return g_lazy_sys_info.Get().max_shared_memory_size();
-}
-
-// static
-std::string SysInfo::CPUModelName() {
- return g_lazy_sys_info.Get().cpu_model_name();
-}
-
} // namespace base