OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/system_cpu/cpu_info_provider.h" | 5 #include "extensions/browser/api/system_cpu/cpu_info_provider.h" |
6 | 6 |
7 #include "base/sys_info.h" | 7 #include "base/sys_info.h" |
8 | 8 |
9 namespace extensions { | 9 namespace extensions { |
10 | 10 |
11 using api::system_cpu::CpuInfo; | 11 using core_api::system_cpu::CpuInfo; |
12 | 12 |
13 // Static member intialization. | 13 // Static member intialization. |
14 base::LazyInstance<scoped_refptr<CpuInfoProvider> > | 14 base::LazyInstance<scoped_refptr<CpuInfoProvider> > |
15 CpuInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | 15 CpuInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
16 | 16 |
17 CpuInfoProvider::CpuInfoProvider() {} | 17 CpuInfoProvider::CpuInfoProvider() {} |
18 | 18 |
19 CpuInfoProvider::~CpuInfoProvider() {} | 19 CpuInfoProvider::~CpuInfoProvider() {} |
20 | 20 |
21 const CpuInfo& CpuInfoProvider::cpu_info() const { | 21 const CpuInfo& CpuInfoProvider::cpu_info() const { |
22 return info_; | 22 return info_; |
23 } | 23 } |
24 | 24 |
25 void CpuInfoProvider::InitializeForTesting( | 25 void CpuInfoProvider::InitializeForTesting( |
26 scoped_refptr<CpuInfoProvider> provider) { | 26 scoped_refptr<CpuInfoProvider> provider) { |
27 DCHECK(provider.get() != NULL); | 27 DCHECK(provider.get() != NULL); |
28 provider_.Get() = provider; | 28 provider_.Get() = provider; |
29 } | 29 } |
30 | 30 |
31 bool CpuInfoProvider::QueryInfo() { | 31 bool CpuInfoProvider::QueryInfo() { |
32 info_.num_of_processors = base::SysInfo::NumberOfProcessors(); | 32 info_.num_of_processors = base::SysInfo::NumberOfProcessors(); |
33 info_.arch_name = base::SysInfo::OperatingSystemArchitecture(); | 33 info_.arch_name = base::SysInfo::OperatingSystemArchitecture(); |
34 info_.model_name = base::SysInfo::CPUModelName(); | 34 info_.model_name = base::SysInfo::CPUModelName(); |
35 info_.features = GetFeatures(); | 35 info_.features = GetFeatures(); |
36 | 36 |
37 info_.processors.clear(); | 37 info_.processors.clear(); |
38 // Fill in the correct number of uninitialized ProcessorInfos. | 38 // Fill in the correct number of uninitialized ProcessorInfos. |
39 for (int i = 0; i < info_.num_of_processors; ++i) { | 39 for (int i = 0; i < info_.num_of_processors; ++i) { |
40 info_.processors.push_back(linked_ptr<api::system_cpu::ProcessorInfo>( | 40 info_.processors.push_back(linked_ptr<core_api::system_cpu::ProcessorInfo>( |
41 new api::system_cpu::ProcessorInfo())); | 41 new core_api::system_cpu::ProcessorInfo())); |
42 } | 42 } |
43 // Initialize the ProcessorInfos, or return an empty array if that fails. | 43 // Initialize the ProcessorInfos, or return an empty array if that fails. |
44 if (!QueryCpuTimePerProcessor(&info_.processors)) | 44 if (!QueryCpuTimePerProcessor(&info_.processors)) |
45 info_.processors.clear(); | 45 info_.processors.clear(); |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 std::vector<std::string> CpuInfoProvider::GetFeatures() const { | 49 std::vector<std::string> CpuInfoProvider::GetFeatures() const { |
50 std::vector<std::string> features; | 50 std::vector<std::string> features; |
51 // These are the feature codes used by /proc/cpuinfo on Linux. | 51 // These are the feature codes used by /proc/cpuinfo on Linux. |
52 if (cpu_.has_mmx()) features.push_back("mmx"); | 52 if (cpu_.has_mmx()) features.push_back("mmx"); |
53 if (cpu_.has_sse()) features.push_back("sse"); | 53 if (cpu_.has_sse()) features.push_back("sse"); |
54 if (cpu_.has_sse2()) features.push_back("sse2"); | 54 if (cpu_.has_sse2()) features.push_back("sse2"); |
55 if (cpu_.has_sse3()) features.push_back("sse3"); | 55 if (cpu_.has_sse3()) features.push_back("sse3"); |
56 if (cpu_.has_ssse3()) features.push_back("ssse3"); | 56 if (cpu_.has_ssse3()) features.push_back("ssse3"); |
57 if (cpu_.has_sse41()) features.push_back("sse4_1"); | 57 if (cpu_.has_sse41()) features.push_back("sse4_1"); |
58 if (cpu_.has_sse42()) features.push_back("sse4_2"); | 58 if (cpu_.has_sse42()) features.push_back("sse4_2"); |
59 if (cpu_.has_avx()) features.push_back("avx"); | 59 if (cpu_.has_avx()) features.push_back("avx"); |
60 return features; | 60 return features; |
61 } | 61 } |
62 | 62 |
63 // static | 63 // static |
64 CpuInfoProvider* CpuInfoProvider::Get() { | 64 CpuInfoProvider* CpuInfoProvider::Get() { |
65 if (provider_.Get().get() == NULL) | 65 if (provider_.Get().get() == NULL) |
66 provider_.Get() = new CpuInfoProvider(); | 66 provider_.Get() = new CpuInfoProvider(); |
67 return provider_.Get(); | 67 return provider_.Get(); |
68 } | 68 } |
69 | 69 |
70 } // namespace extensions | 70 } // namespace extensions |
OLD | NEW |