This source file includes following definitions.
- cpu_info
- InitializeForTesting
- QueryInfo
- GetFeatures
- Get
#include "chrome/browser/extensions/api/system_cpu/cpu_info_provider.h"
#include "base/sys_info.h"
namespace extensions {
using api::system_cpu::CpuInfo;
base::LazyInstance<scoped_refptr<CpuInfoProvider> >
CpuInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER;
CpuInfoProvider::CpuInfoProvider() {}
CpuInfoProvider::~CpuInfoProvider() {}
const CpuInfo& CpuInfoProvider::cpu_info() const {
return info_;
}
void CpuInfoProvider::InitializeForTesting(
scoped_refptr<CpuInfoProvider> provider) {
DCHECK(provider.get() != NULL);
provider_.Get() = provider;
}
bool CpuInfoProvider::QueryInfo() {
info_.num_of_processors = base::SysInfo::NumberOfProcessors();
info_.arch_name = base::SysInfo::OperatingSystemArchitecture();
info_.model_name = base::SysInfo::CPUModelName();
info_.features = GetFeatures();
info_.processors.clear();
for (int i = 0; i < info_.num_of_processors; ++i) {
info_.processors.push_back(linked_ptr<api::system_cpu::ProcessorInfo>(
new api::system_cpu::ProcessorInfo()));
}
if (!QueryCpuTimePerProcessor(&info_.processors))
info_.processors.clear();
return true;
}
std::vector<std::string> CpuInfoProvider::GetFeatures() const {
std::vector<std::string> features;
if (cpu_.has_mmx()) features.push_back("mmx");
if (cpu_.has_sse()) features.push_back("sse");
if (cpu_.has_sse2()) features.push_back("sse2");
if (cpu_.has_sse3()) features.push_back("sse3");
if (cpu_.has_ssse3()) features.push_back("ssse3");
if (cpu_.has_sse41()) features.push_back("sse4_1");
if (cpu_.has_sse42()) features.push_back("sse4_2");
if (cpu_.has_avx()) features.push_back("avx");
return features;
}
CpuInfoProvider* CpuInfoProvider::Get() {
if (provider_.Get().get() == NULL)
provider_.Get() = new CpuInfoProvider();
return provider_.Get();
}
}