| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ | 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ |
| 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ | 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/system_info_provider.h" | 7 #include "chrome/browser/extensions/system_info_provider.h" |
| 8 |
| 9 #include <vector> |
| 10 |
| 8 #include "chrome/common/extensions/api/experimental_system_info_cpu.h" | 11 #include "chrome/common/extensions/api/experimental_system_info_cpu.h" |
| 9 | 12 |
| 10 namespace extensions { | 13 namespace extensions { |
| 11 | 14 |
| 12 class CpuInfoProvider | 15 class CpuInfoProvider |
| 13 : public SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo> { | 16 : public SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo> { |
| 14 public: | 17 public: |
| 18 typedef base::Callback<api::experimental_system_info_cpu::CpuUpdateInfo> |
| 19 QueryCpuTimeCallback; |
| 15 virtual ~CpuInfoProvider() {} | 20 virtual ~CpuInfoProvider() {} |
| 16 | 21 |
| 22 // Overriden from SystemInfoProvider<CpuInfo>. |
| 23 virtual bool QueryInfo( |
| 24 api::experimental_system_info_cpu::CpuInfo* info) OVERRIDE; |
| 25 |
| 26 // Start sampling the CPU usage. The callback gets called when one sampling |
| 27 // cycle is completed periodically with the CPU updated usage info for each |
| 28 // processors. Return true if it succeeds to start, otherwise, false is |
| 29 // returned. |
| 30 bool StartSampling(const QueryCpuTimeCallback& callback); |
| 31 |
| 32 // Stop the sampling cycle. Return true if it succeeds to stop. |
| 33 bool StopSampling(); |
| 34 |
| 17 // Return the single shared instance of CpuInfoProvider. | 35 // Return the single shared instance of CpuInfoProvider. |
| 18 static CpuInfoProvider* Get(); | 36 static CpuInfoProvider* Get(); |
| 37 |
| 38 private: |
| 39 // The amount of time that CPU spent on performing different kinds of work. |
| 40 // It is used to calculate the usage percent for processors. |
| 41 struct CpuTime { |
| 42 int64 user; // user mode. |
| 43 int64 kernel; // kernel mode. |
| 44 int64 idle; // twiddling thumbs. |
| 45 }; |
| 46 |
| 47 // Platform specific implementation for querying the CPU time information |
| 48 // for each processor. Note that the first element is the total aggregated |
| 49 // numbers of all logic processors. |
| 50 bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times); |
| 19 }; | 51 }; |
| 20 | 52 |
| 21 } // namespace extensions | 53 } // namespace extensions |
| 22 | 54 |
| 23 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ | 55 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ |
| 24 | 56 |
| OLD | NEW |