OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ | |
6 #define CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/singleton.h" | |
10 #include "base/observer_list.h" | |
11 #include "base/task_runner.h" | |
12 #include "base/timer/timer.h" | |
13 #include "content/browser/power_profiler/power_data_provider.h" | |
14 #include "content/browser/power_profiler/power_profiler_observer.h" | |
15 #include "content/common/content_export.h" | |
16 | |
17 namespace content { | |
18 | |
19 // A class used to query power information and notify the observers. | |
20 class CONTENT_EXPORT PowerProfilerService { | |
21 public: | |
22 static PowerProfilerService* GetInstance(); | |
23 | |
24 // Add and remove an observer. | |
25 void AddObserver(PowerProfilerObserver* observer); | |
26 void RemoveObserver(PowerProfilerObserver* observer); | |
27 | |
28 bool IsAvailable(); | |
29 | |
30 private: | |
31 enum Status { | |
32 UNINITIALIZED, | |
33 INITIALIZED, // Initialized, profiling has not started. | |
34 PROFILING | |
35 }; | |
36 | |
37 friend struct DefaultSingletonTraits<PowerProfilerService>; | |
38 friend class PowerProfilerServiceTest; | |
39 | |
40 PowerProfilerService(); | |
41 virtual ~PowerProfilerService(); | |
42 | |
43 PowerProfilerService(scoped_ptr<PowerDataProvider> provider, | |
44 scoped_refptr<base::TaskRunner> task_runner, | |
45 const base::TimeDelta& sample_period); | |
46 | |
47 void Start(); | |
48 void Stop(); | |
49 | |
50 // Query power data from PowerDataProvider, executes on the WorkerPool thread. | |
51 void QueryDataOnTaskRunner(); | |
52 | |
53 // Initiate the query on the UI thread, the task is delegated to | |
54 // QueryDataOnTaskRunner. | |
55 void QueryData(); | |
56 | |
57 // Executes on the UI thread. | |
58 void Notify(const PowerEventVector&); | |
59 | |
60 base::RepeatingTimer<PowerProfilerService> query_power_timer_; | |
61 scoped_refptr<base::TaskRunner> task_runner_; | |
62 | |
63 Status status_; | |
64 | |
65 // Sampling period of power data measurement. | |
66 const base::TimeDelta sample_period_; | |
67 ObserverList<PowerProfilerObserver> observers_; | |
68 | |
69 scoped_ptr<PowerDataProvider> data_provider_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(PowerProfilerService); | |
72 }; | |
73 | |
74 } // namespace content | |
75 | |
76 #endif // CONTENT_BROWSER_POWER_PROFILER_POWER_PROFILER_SERVICE_H_ | |
OLD | NEW |