1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/api/system_cpu/cpu_info_provider.h"
7 #include "base/sys_info.h"
11 using core_api::system_cpu::CpuInfo
;
13 // Static member intialization.
14 base::LazyInstance
<scoped_refptr
<CpuInfoProvider
> > CpuInfoProvider::provider_
=
15 LAZY_INSTANCE_INITIALIZER
;
17 CpuInfoProvider::CpuInfoProvider() {
20 CpuInfoProvider::~CpuInfoProvider() {
23 void CpuInfoProvider::InitializeForTesting(
24 scoped_refptr
<CpuInfoProvider
> provider
) {
25 DCHECK(provider
.get() != NULL
);
26 provider_
.Get() = provider
;
29 bool CpuInfoProvider::QueryInfo() {
30 info_
.num_of_processors
= base::SysInfo::NumberOfProcessors();
31 info_
.arch_name
= base::SysInfo::OperatingSystemArchitecture();
32 info_
.model_name
= base::SysInfo::CPUModelName();
33 info_
.features
= GetFeatures();
35 info_
.processors
.clear();
36 // Fill in the correct number of uninitialized ProcessorInfos.
37 for (int i
= 0; i
< info_
.num_of_processors
; ++i
) {
38 info_
.processors
.push_back(linked_ptr
<core_api::system_cpu::ProcessorInfo
>(
39 new core_api::system_cpu::ProcessorInfo()));
41 // Initialize the ProcessorInfos, or return an empty array if that fails.
42 if (!QueryCpuTimePerProcessor(&info_
.processors
))
43 info_
.processors
.clear();
47 std::vector
<std::string
> CpuInfoProvider::GetFeatures() const {
48 std::vector
<std::string
> features
;
49 // These are the feature codes used by /proc/cpuinfo on Linux.
51 features
.push_back("mmx");
53 features
.push_back("sse");
55 features
.push_back("sse2");
57 features
.push_back("sse3");
59 features
.push_back("ssse3");
61 features
.push_back("sse4_1");
63 features
.push_back("sse4_2");
65 features
.push_back("avx");
70 CpuInfoProvider
* CpuInfoProvider::Get() {
71 if (provider_
.Get().get() == NULL
)
72 provider_
.Get() = new CpuInfoProvider();
73 return provider_
.Get().get();
76 } // namespace extensions