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 <set> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "base/task_runner.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "content/common/content_export.h" |
| 16 #include "content/public/browser/power_data_provider.h" |
| 17 #include "content/public/browser/power_profiler_observer.h" |
| 18 |
| 19 namespace content { |
| 20 |
| 21 // a class used to monitor the power usage and tell profiler the power data. |
| 22 class CONTENT_EXPORT PowerProfilerService { |
| 23 public: |
| 24 static PowerProfilerService* GetInstance(); |
| 25 |
| 26 // Add and remove an observer. |
| 27 void AddObserver(PowerProfilerObserver* observer); |
| 28 void RemoveObserver(PowerProfilerObserver* observer); |
| 29 |
| 30 bool IsAvailable(); |
| 31 |
| 32 private: |
| 33 enum Status { |
| 34 UNINITIALIZED, // Uninitialized. |
| 35 INITIALIZED, // Initialized, not in profiling. |
| 36 PROFILING, // In profiling. |
| 37 }; |
| 38 |
| 39 friend struct DefaultSingletonTraits<PowerProfilerService>; |
| 40 friend class PowerProfilerServiceTest; |
| 41 |
| 42 PowerProfilerService(); |
| 43 virtual ~PowerProfilerService() {} |
| 44 |
| 45 explicit PowerProfilerService(scoped_ptr<PowerDataProvider> provider); |
| 46 |
| 47 void Start(); |
| 48 void Stop(); |
| 49 |
| 50 void InitializeDelays(); |
| 51 void UpdateResolution(); |
| 52 |
| 53 // ProcessData is delegated to thread in WorkerPool. |
| 54 void QueryDataOnTaskRunner(); |
| 55 void QueryData(); |
| 56 |
| 57 // Notify works in UI thread. |
| 58 void Notify(const PowerEvent&); |
| 59 |
| 60 base::RepeatingTimer<PowerProfilerService> query_power_timer_; |
| 61 scoped_refptr<base::TaskRunner> task_runner_; |
| 62 |
| 63 base::TimeDelta delay_; |
| 64 base::TimeDelta delays_[PowerProfilerObserver::TYPE_COUNT]; // kinds of delay. |
| 65 Status status_; |
| 66 ObserverList<PowerProfilerObserver> observers_; |
| 67 |
| 68 scoped_ptr<PowerDataProvider> data_provider_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(PowerProfilerService); |
| 71 }; |
| 72 |
| 73 } // namespace content |
| 74 |
| 75 #endif // CONTENT_PUBLIC_BROWSER_POWER_PROFILER_SERVICE_H_ |
OLD | NEW |