Chromium Code Reviews| 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_PUBLIC_BROWSER_POWER_PROFILER_SERVICE_H_ | |
| 6 #define CONTENT_PUBLIC_BROWSER_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/common/content_export.h" | |
| 14 #include "content/public/browser/power_data_provider.h" | |
| 15 #include "content/public/browser/power_profiler_observer.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 // a class used to monitor the power usage and tell profiler the power data. | |
| 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, // Uninitialized. | |
| 33 INITIALIZED, // Initialized, not in profiling. | |
| 34 PROFILING, // In profiling. | |
| 35 }; | |
| 36 | |
| 37 friend struct DefaultSingletonTraits<PowerProfilerService>; | |
| 38 friend class PowerProfilerServiceTest; | |
| 39 | |
| 40 PowerProfilerService(); | |
| 41 virtual ~PowerProfilerService() {} | |
| 42 | |
| 43 explicit PowerProfilerService(scoped_ptr<PowerDataProvider> provider, | |
| 44 scoped_refptr<base::TaskRunner> task_runner, | |
| 45 base::TimeDelta delay); | |
|
qsr
2014/01/29 14:26:52
const base::TimeDelta&
Pan
2014/01/30 01:05:36
Done.
| |
| 46 | |
| 47 void Start(); | |
| 48 void Stop(); | |
| 49 | |
| 50 void QueryDataOnTaskRunner(); | |
| 51 void QueryData(); | |
| 52 | |
| 53 // Notify works in UI thread. | |
| 54 void Notify(const PowerEvent&); | |
| 55 | |
| 56 base::RepeatingTimer<PowerProfilerService> query_power_timer_; | |
| 57 scoped_refptr<base::TaskRunner> task_runner_; | |
| 58 | |
| 59 Status status_; | |
| 60 | |
| 61 // Interval of reading the power data by provider. | |
| 62 const base::TimeDelta delay_; | |
| 63 ObserverList<PowerProfilerObserver> observers_; | |
| 64 | |
| 65 scoped_ptr<PowerDataProvider> data_provider_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(PowerProfilerService); | |
| 68 }; | |
| 69 | |
| 70 } // namespace content | |
| 71 | |
| 72 #endif // CONTENT_PUBLIC_BROWSER_POWER_PROFILER_SERVICE_H_ | |
| OLD | NEW |