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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/extensions/api/system_info/system_info_provider.h" | 10 #include "chrome/browser/extensions/api/system_info/system_info_provider.h" |
11 #include "chrome/common/extensions/api/experimental_system_info_cpu.h" | 11 #include "chrome/common/extensions/api/system_info_cpu.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 class CpuInfoProvider | 17 class CpuInfoProvider |
18 : public content::NotificationObserver, | 18 : public content::NotificationObserver, |
19 public SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo> { | 19 public SystemInfoProvider<api::system_info_cpu::CpuInfo> { |
20 public: | 20 public: |
21 typedef base::Callback< | 21 typedef base::Callback< |
22 void(scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo>)> | 22 void(scoped_ptr<api::system_info_cpu::CpuUpdateInfo>)> |
23 SamplingCallback; | 23 SamplingCallback; |
24 | 24 |
25 // Overriden from SystemInfoProvider<CpuInfo>. | 25 // Overriden from SystemInfoProvider<CpuInfo>. |
26 virtual bool QueryInfo( | 26 virtual bool QueryInfo( |
27 api::experimental_system_info_cpu::CpuInfo* info) OVERRIDE; | 27 api::system_info_cpu::CpuInfo* info) OVERRIDE; |
28 | 28 |
29 // Start sampling the CPU usage. The callback gets called when one sampling | 29 // Start sampling the CPU usage. The callback gets called when one sampling |
30 // cycle is completed periodically with the CPU updated usage info for each | 30 // cycle is completed periodically with the CPU updated usage info for each |
31 // processors. It gets called on UI thread, the |callback| gets called on the | 31 // processors. It gets called on UI thread, the |callback| gets called on the |
32 // FILE thread. | 32 // FILE thread. |
33 void StartSampling(const SamplingCallback& callback); | 33 void StartSampling(const SamplingCallback& callback); |
34 | 34 |
35 // Stop the sampling cycle. Called on the FILE thread. | 35 // Stop the sampling cycle. Called on the FILE thread. |
36 void StopSampling(); | 36 void StopSampling(); |
37 | 37 |
38 // Return the single shared instance of CpuInfoProvider. | 38 // Return the single shared instance of CpuInfoProvider. |
39 static CpuInfoProvider* Get(); | 39 static CpuInfoProvider* Get(); |
40 | 40 |
41 private: | 41 private: |
42 friend class SystemInfoProvider<api::experimental_system_info_cpu::CpuInfo>; | 42 friend class SystemInfoProvider<api::system_info_cpu::CpuInfo>; |
43 friend class MockCpuInfoProviderImpl; | 43 friend class MockCpuInfoProviderImpl; |
44 friend class TestCpuInfoProvider; | 44 friend class TestCpuInfoProvider; |
45 | 45 |
46 // The amount of time that CPU spent on performing different kinds of work. | 46 // The amount of time that CPU spent on performing different kinds of work. |
47 // It is used to calculate the usage percent for processors. | 47 // It is used to calculate the usage percent for processors. |
48 struct CpuTime { | 48 struct CpuTime { |
49 CpuTime() : user(0), kernel(0), idle(0) {} | 49 CpuTime() : user(0), kernel(0), idle(0) {} |
50 int64 user; // user mode. | 50 int64 user; // user mode. |
51 int64 kernel; // kernel mode. | 51 int64 kernel; // kernel mode. |
52 int64 idle; // twiddling thumbs. | 52 int64 idle; // twiddling thumbs. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 base::RepeatingTimer<CpuInfoProvider>* sampling_timer_; | 88 base::RepeatingTimer<CpuInfoProvider>* sampling_timer_; |
89 | 89 |
90 // The time interval for sampling, in milliseconds. | 90 // The time interval for sampling, in milliseconds. |
91 int sampling_interval_; | 91 int sampling_interval_; |
92 }; | 92 }; |
93 | 93 |
94 } // namespace extensions | 94 } // namespace extensions |
95 | 95 |
96 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ | 96 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_CPU_CPU_INFO_PROVIDER_H_ |
97 | 97 |
OLD | NEW |