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 d163e4990f83220b75d95d1eb6b2123be08c1a69..4844bc5bfac5133eecd34ae0a501a9881b40941c 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; |
| + |
| + virtual ~CpuInfoProvider(); |
| // Overriden from SystemInfoProvider<CpuInfo>. |
| virtual bool QueryInfo( |
| @@ -26,28 +29,55 @@ 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); |
| + // returned. Can be called from any thread. |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
Allowing this to be called from any thread may mas
Hongbo Min
2012/09/16 14:07:49
Done.
|
| + bool StartSampling(const SamplingCallback& callback); |
| - // Stop the sampling cycle. Return true if it succeeds to stop. |
| + // Stop the sampling cycle. Return true if it succeeds to stop. Can be called |
| + // from any thread. |
| bool 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. Note that the first element is the total aggregated |
| // numbers of all logic processors. |
| - bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times); |
| + virtual bool QueryCpuTimePerProcessor(std::vector<CpuTime>* times); |
| + |
| + // Called when the sampling timer is expired. |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
"expired" doesn't seem right. "fired" perhaps?
Hongbo Min
2012/09/16 14:07:49
Done.
|
| + void DoStartSampling(); |
| + |
| + // Indicates whether the CPU sampling is started. |
| + bool is_sampling_started_; |
| + |
| + // The sampling value returned from the most recent QueryCpuTimePerProcessor |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
This doesn't seem to be true. You set the variable
Hongbo Min
2012/09/16 14:07:49
Use baseline_cpu_time_. Done
|
| + // call. |
| + std::vector<CpuTime> sampling_value_; |
| + |
| + // 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. |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
"file thread" or "FILE thread" are the more common
Hongbo Min
2012/09/16 14:07:49
Done.
|
| + base::RepeatingTimer<CpuInfoProvider>* sampling_timer_; |
| + |
| + // The time interval for sampling. |
|
Mihai Parparita -not on Chrome
2012/09/16 06:23:05
Mention the time units.
Hongbo Min
2012/09/16 14:07:49
Done.
|
| + int sampling_interval_; |
| }; |
| } // namespace extensions |