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. 4 5 #ifndef EXTENSIONS_BROWSER_API_SYSTEM_CPU_CPU_INFO_PROVIDER_H_ 6 #define EXTENSIONS_BROWSER_API_SYSTEM_CPU_CPU_INFO_PROVIDER_H_ 7 8 #include <vector> 9 10 #include "base/cpu.h" 11 #include "base/lazy_instance.h" 12 #include "extensions/browser/api/system_info/system_info_provider.h" 13 #include "extensions/common/api/system_cpu.h" 14 15 namespace extensions { 16 17 class CpuInfoProvider : public SystemInfoProvider { 18 public: 19 // Return the single shared instance of CpuInfoProvider. 20 static CpuInfoProvider* Get(); 21 22 const core_api::system_cpu::CpuInfo& cpu_info() const { return info_; } 23 24 static void InitializeForTesting(scoped_refptr<CpuInfoProvider> provider); 25 26 private: 27 friend class MockCpuInfoProviderImpl; 28 29 CpuInfoProvider(); 30 virtual ~CpuInfoProvider(); 31 32 // Platform specific implementation for querying the CPU time information 33 // for each processor. 34 virtual bool QueryCpuTimePerProcessor( 35 std::vector<linked_ptr<core_api::system_cpu::ProcessorInfo> >* infos); 36 37 // Overriden from SystemInfoProvider. 38 virtual bool QueryInfo() OVERRIDE; 39 40 // Creates a list of codenames for currently active features. 41 std::vector<std::string> GetFeatures() const; 42 43 // The last information filled up by QueryInfo and is accessed on multiple 44 // threads, but the whole class is being guarded by SystemInfoProvider base 45 // class. 46 // 47 // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is 48 // false and on the sequenced worker pool while |is_waiting_for_completion_| 49 // is true. 50 core_api::system_cpu::CpuInfo info_; 51 52 static base::LazyInstance<scoped_refptr<CpuInfoProvider> > provider_; 53 base::CPU cpu_; 54 55 DISALLOW_COPY_AND_ASSIGN(CpuInfoProvider); 56 }; 57 58 } // namespace extensions 59 60 #endif // EXTENSIONS_BROWSER_API_SYSTEM_CPU_CPU_INFO_PROVIDER_H_ 61