Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h |
| diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h |
| index a3c8b29b6ad74d4497a09776df291b7781fb84d7..c3c8842179ade4ec396120609d4784b5a53591a1 100644 |
| --- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h |
| +++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| +#include "base/timer.h" |
| #include "chrome/common/extensions/api/experimental_system_info_cpu.h" |
| namespace extensions { |
| @@ -15,9 +16,11 @@ namespace extensions { |
| class CpuInfoProvider |
| : public SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo> { |
| public: |
| - typedef base::Callback<api::experimental_system_info_cpu::CpuUpdateInfo> |
| - QueryCpuTimeCallback; |
| - virtual ~CpuInfoProvider() {} |
| + typedef base::Callback< |
| + void(scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo>)> |
| + SamplingCallback; |
|
benwells
2012/09/21 08:19:50
Sorry, but what is the void here for?
Hongbo Min
2012/09/21 09:00:23
It is the callback signature, right? All SamplingC
benwells
2012/09/25 17:32:13
Yes, you're right.
|
| + |
| + virtual ~CpuInfoProvider(); |
| // Overriden from SystemInfoProvider<CpuInfo>. |
| virtual bool QueryInfo( |
| @@ -25,28 +28,58 @@ class CpuInfoProvider |
| // Start sampling the CPU usage. The callback gets called when one sampling |
| // cycle is completed periodically with the CPU updated usage info for each |
| - // processors. Return true if it succeeds to start, otherwise, false is |
| - // returned. |
| - bool StartSampling(const QueryCpuTimeCallback& callback); |
| + // processors. It gets called on UI thread, the |callback| gets called on the |
| + // FILE thread. |
| + void StartSampling(const SamplingCallback& callback); |
| - // Stop the sampling cycle. Return true if it succeeds to stop. |
| - bool StopSampling(); |
| + // Stop the sampling cycle. Called on the FILE thread. |
| + void StopSampling(); |
| // Return the single shared instance of CpuInfoProvider. |
| static CpuInfoProvider* Get(); |
| private: |
| + friend class SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo>; |
| + friend class MockCpuInfoProviderImpl; |
| + |
| // The amount of time that CPU spent on performing different kinds of work. |
| // It is used to calculate the usage percent for processors. |
| - struct CpuTime { |
| + class CpuTime { |
| + public: |
| + CpuTime() : user(0), kernel(0), idle(0) {} |
| int64 user; // user mode. |
| int64 kernel; // kernel mode. |
| int64 idle; // twiddling thumbs. |
| }; |
| + CpuInfoProvider(); |
| + |
| // Platform specific implementation for querying the CPU time information |
| // for each processor. |
| - bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times); |
| + virtual bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times); |
| + |
| + // Start and stop sampling on the FILE thread. |
| + void StartSamplingOnFileThread(const SamplingCallback& callback); |
| + void StopSamplingOnFileThread(); |
| + |
| + // Called when the sampling timer is triggered. |
| + void DoSample(); |
| + |
| + // Indicates whether the CPU sampling is started. |
| + bool is_sampling_started_; |
| + |
| + // The sampling value returned from the most recent QueryCpuTimePerProcessor |
| + // call. |
| + std::vector<CpuTime> baseline_cpu_time_; |
| + |
| + // The callback which will be called when one sampling cycle is completed. |
| + SamplingCallback callback_; |
| + |
| + // The timer used for polling CPU time periodically. Live on FILE thread. |
|
benwells
2012/09/21 08:19:50
Nit: s/Live/Lives/
Hongbo Min
2012/09/21 09:00:23
Done.
|
| + base::RepeatingTimer<CpuInfoProvider>* sampling_timer_; |
| + |
| + // The time interval for sampling, in milliseconds. |
| + int sampling_interval_; |
| }; |
| } // namespace extensions |