diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-18 12:18:14 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-18 12:18:14 +0000 |
commit | fadf97f2f16f6b3ad2756cd07657c4f47172da92 (patch) | |
tree | ba24cf444ef2696e32639d51ef30e9f0d96df330 | |
parent | 1918c4e12cea21c56d5d9e07f3759de6ad9e3dd3 (diff) | |
download | chromium_src-fadf97f2f16f6b3ad2756cd07657c4f47172da92.zip chromium_src-fadf97f2f16f6b3ad2756cd07657c4f47172da92.tar.gz chromium_src-fadf97f2f16f6b3ad2756cd07657c4f47172da92.tar.bz2 |
Add cross platform base::SysInfo::AmountOfPhysicalMemoryMB to replace the Windows only env_util::GetPhysicalMemoryMB.
From Seo Sanghyeon.
Review URL: http://codereview.chromium.org/2962
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2358 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/sys_info.h | 5 | ||||
-rw-r--r-- | chrome/browser/cache_manager_host.cc | 3 | ||||
-rw-r--r-- | chrome/browser/metrics_log.cc | 3 | ||||
-rw-r--r-- | chrome/browser/render_process_host.cc | 3 | ||||
-rw-r--r-- | chrome/common/env_util.cc | 12 | ||||
-rw-r--r-- | chrome/common/env_util.h | 3 |
6 files changed, 11 insertions, 18 deletions
diff --git a/base/sys_info.h b/base/sys_info.h index c82b0d3..01e506c 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -16,6 +16,11 @@ class SysInfo { // Return the number of bytes of physical memory on the current machine. static int64 AmountOfPhysicalMemory(); + + // Return the number of megabytes of physical memory on the current machine. + static int AmountOfPhysicalMemoryMB() { + return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024); + } }; } // namespace base diff --git a/chrome/browser/cache_manager_host.cc b/chrome/browser/cache_manager_host.cc index 0e329d3..13fc171 100644 --- a/chrome/browser/cache_manager_host.cc +++ b/chrome/browser/cache_manager_host.cc @@ -6,6 +6,7 @@ #include "chrome/browser/cache_manager_host.h" +#include "base/sys_info.h" #include "base/time.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/render_process_host.h" @@ -31,7 +32,7 @@ int GetDefaultCacheSize() { int default_cache_size = kDefaultMemoryCacheSize; // Check how much physical memory the OS has - int mem_size_mb = env_util::GetPhysicalMemoryMB(); + int mem_size_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); if (mem_size_mb >= 1000) // If we have a GB of memory, set a larger default. default_cache_size *= 4; else if (mem_size_mb >= 512) // With 512 MB, set a slightly larger default. diff --git a/chrome/browser/metrics_log.cc b/chrome/browser/metrics_log.cc index d72e1ae..8144940 100644 --- a/chrome/browser/metrics_log.cc +++ b/chrome/browser/metrics_log.cc @@ -9,6 +9,7 @@ #include "base/md5.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/sys_info.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/browser_process.h" #include "chrome/common/env_util.h" @@ -462,7 +463,7 @@ void MetricsLog::RecordEnvironment( { OPEN_ELEMENT_FOR_SCOPE("memory"); - WriteIntAttribute("mb", env_util::GetPhysicalMemoryMB()); + WriteIntAttribute("mb", base::SysInfo:AmountOfPhysicalMemoryMB()); } { diff --git a/chrome/browser/render_process_host.cc b/chrome/browser/render_process_host.cc index 90ff2aa..dfa5755 100644 --- a/chrome/browser/render_process_host.cc +++ b/chrome/browser/render_process_host.cc @@ -22,6 +22,7 @@ #include "base/shared_event.h" #include "base/shared_memory.h" #include "base/string_util.h" +#include "base/sys_info.h" #include "base/thread.h" #include "base/win_util.h" #include "chrome/app/result_codes.h" @@ -74,7 +75,7 @@ unsigned int GetMaxRendererProcessCount() { static unsigned int max_count = 0; if (!max_count) { - int memory_tier = env_util::GetPhysicalMemoryMB() / 256; + int memory_tier = base::SysInfo::AmountOfPhysicalMemoryMB() / 256; if (memory_tier >= arraysize(kMaxRenderersByRamTier)) max_count = chrome::kMaxRendererProcessCount; else diff --git a/chrome/common/env_util.cc b/chrome/common/env_util.cc index 43b9bff..3af22a6 100644 --- a/chrome/common/env_util.cc +++ b/chrome/common/env_util.cc @@ -7,8 +7,6 @@ #include "base/basictypes.h" #include "base/logging.h" -static const DWORDLONG kBytesPerMegabyte = 1048576; - namespace env_util { std::string GetOperatingSystemName() { @@ -27,16 +25,6 @@ std::string GetOperatingSystemVersion() { return std::string(result); } -int GetPhysicalMemoryMB() { - MEMORYSTATUSEX status; - status.dwLength = sizeof(status); - if (::GlobalMemoryStatusEx(&status)) - return static_cast<int>(status.ullTotalPhys / kBytesPerMegabyte); - - NOTREACHED() << "GlobalMemoryStatusEx failed."; - return 0; -} - std::string GetCPUArchitecture() { // TODO: Make this vary when we support any other architectures. return "x86"; diff --git a/chrome/common/env_util.h b/chrome/common/env_util.h index 27d82f7..bb37935 100644 --- a/chrome/common/env_util.h +++ b/chrome/common/env_util.h @@ -24,9 +24,6 @@ std::string GetOperatingSystemName(); // Returns the version of the host operating system. std::string GetOperatingSystemVersion(); -// Returns the total amount of physical memory present. -int GetPhysicalMemoryMB(); - // Returns the CPU architecture of the system. std::string GetCPUArchitecture(); |