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 // Interval of reading the power data by provider. |
| 32 static const base::TimeDelta delay_; |
| 33 |
| 34 enum Status { |
| 35 UNINITIALIZED, // Uninitialized. |
| 36 INITIALIZED, // Initialized, not in profiling. |
| 37 PROFILING, // In profiling. |
| 38 }; |
| 39 |
| 40 friend struct DefaultSingletonTraits<PowerProfilerService>; |
| 41 friend class PowerProfilerServiceTest; |
| 42 |
| 43 PowerProfilerService(); |
| 44 virtual ~PowerProfilerService() {} |
| 45 |
| 46 explicit PowerProfilerService(scoped_ptr<PowerDataProvider> provider, |
| 47 scoped_refptr<base::TaskRunner> task_runner); |
| 48 |
| 49 void Start(); |
| 50 void Stop(); |
| 51 |
| 52 // ProcessData is delegated to thread in WorkerPool. |
| 53 void QueryDataOnTaskRunner(); |
| 54 void QueryData(); |
| 55 |
| 56 // Notify works in UI thread. |
| 57 void Notify(const PowerEvent&); |
| 58 |
| 59 base::RepeatingTimer<PowerProfilerService> query_power_timer_; |
| 60 scoped_refptr<base::TaskRunner> task_runner_; |
| 61 |
| 62 Status status_; |
| 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 |