Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3222)

Unified Diff: base/cpu.cc

Issue 188443003: Parsing /proc/cpuinfo for model on Android and Aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/cpu.cc
diff --git a/base/cpu.cc b/base/cpu.cc
index 66207a1e0b8b0539b99a72b85435936f847803bb..d3a6a015155cd6c060545714e20723a334e2fc95 100644
--- a/base/cpu.cc
+++ b/base/cpu.cc
@@ -9,6 +9,8 @@
#include <algorithm>
#include "base/basictypes.h"
+#include "base/file_util.h"
cpu_(ooo_6.6-7.5) 2014/04/24 03:36:50 can we put the file_util.h on an #ifdef, in most p
+#include "base/lazy_instance.h"
#include "build/build_config.h"
#if defined(ARCH_CPU_X86_FAMILY)
@@ -84,6 +86,47 @@ uint64 _xgetbv(uint32 xcr) {
#endif // !_MSC_VER
#endif // ARCH_CPU_X86_FAMILY
+#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
+
+std::string ParseCpuInfo() {
+ const char kProcessorPrefix[] = "Processor";
+ std::string contents, cpu_brand;
+ ReadFileToString(FilePath("/proc/cpuinfo"), &contents);
+ DCHECK(!contents.empty());
+ if (!contents.empty()) {
+ std::istringstream iss(contents);
+ std::string line;
+ while (std::getline(iss, line)) {
+ if (line.compare(0, strlen(kProcessorPrefix), kProcessorPrefix) == 0) {
+ size_t pos = line.find(": ");
+ if (pos != std::string::npos) {
+ cpu_brand.assign(line.substr(pos + 2));
+ break;
+ }
+ }
+ }
+ }
+ return cpu_brand;
+}
+
+class LazyCpuInfoValue {
+ public:
+ LazyCpuInfoValue() : value_(ParseCpuInfo()) {}
+ const std::string& value() { return value_; }
+
+ private:
+ const std::string value_;
+ DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue);
+};
+
+base::LazyInstance<LazyCpuInfoValue> g_lazy_cpu_brand =
+ LAZY_INSTANCE_INITIALIZER;
+
+const std::string& CpuBrandInfo() { return g_lazy_cpu_brand.Get().value(); }
+
+#endif // defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) ||
+ // defined(OS_LINUX))
+
} // anonymous namespace
void CPU::Initialize() {
@@ -157,13 +200,8 @@ void CPU::Initialize() {
__cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter);
has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0;
}
-#elif defined(ARCH_CPU_ARM_FAMILY)
- // TODO(piman): Expand this. ARM has a CPUID register, but it's not available
- // in user mode. /proc/cpuinfo has some information, but it's non standard,
- // platform-specific, and not accessible from the sandbox.
- // For some purposes, this first approximation is enough.
- // crbug.com/313454
- cpu_brand_.assign("ARM");
+#elif defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
+ cpu_brand_.assign(CpuBrandInfo());
#endif
}
« no previous file with comments | « no previous file | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698