Fix android webview test shell command line file path for Telemetry
[chromium-blink-merge.git] / base / power_monitor / power_monitor_device_source.h
blob37b065a77c6a16498fc07993a7eb5b1276ad606a
1 // Copyright 2013 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.
5 #ifndef BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_
6 #define BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list_threadsafe.h"
12 #include "base/power_monitor/power_monitor_source.h"
13 #include "base/power_monitor/power_observer.h"
15 #if defined(OS_WIN)
16 #include <windows.h>
18 // Windows HiRes timers drain the battery faster so we need to know the battery
19 // status. This isn't true for other platforms.
20 #define ENABLE_BATTERY_MONITORING 1
21 #else
22 #undef ENABLE_BATTERY_MONITORING
23 #endif // !OS_WIN
25 #if defined(ENABLE_BATTERY_MONITORING)
26 #include "base/timer/timer.h"
27 #endif // defined(ENABLE_BATTERY_MONITORING)
29 #if defined(OS_IOS)
30 #include <objc/runtime.h>
31 #endif // OS_IOS
33 namespace base {
35 // A class used to monitor the power state change and notify the observers about
36 // the change event.
37 class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
38 public:
39 PowerMonitorDeviceSource();
40 virtual ~PowerMonitorDeviceSource();
42 #if defined(OS_MACOSX)
43 // Allocate system resources needed by the PowerMonitor class.
45 // This function must be called before instantiating an instance of the class
46 // and before the Sandbox is initialized.
47 #if !defined(OS_IOS)
48 static void AllocateSystemIOPorts();
49 #else
50 static void AllocateSystemIOPorts() {}
51 #endif // OS_IOS
52 #endif // OS_MACOSX
54 private:
55 #if defined(OS_WIN)
56 // Represents a message-only window for power message handling on Windows.
57 // Only allow PowerMonitor to create it.
58 class PowerMessageWindow {
59 public:
60 PowerMessageWindow();
61 ~PowerMessageWindow();
63 private:
64 static LRESULT CALLBACK WndProcThunk(HWND hwnd,
65 UINT message,
66 WPARAM wparam,
67 LPARAM lparam);
68 // Instance of the module containing the window procedure.
69 HMODULE instance_;
70 // A hidden message-only window.
71 HWND message_hwnd_;
73 #endif // OS_WIN
75 #if defined(OS_MACOSX)
76 void PlatformInit();
77 void PlatformDestroy();
78 #endif
80 // Platform-specific method to check whether the system is currently
81 // running on battery power. Returns true if running on batteries,
82 // false otherwise.
83 virtual bool IsOnBatteryPowerImpl() OVERRIDE;
85 // Checks the battery status and notifies observers if the battery
86 // status has changed.
87 void BatteryCheck();
89 #if defined(OS_IOS)
90 // Holds pointers to system event notification observers.
91 std::vector<id> notification_observers_;
92 #endif
94 #if defined(ENABLE_BATTERY_MONITORING)
95 base::OneShotTimer<PowerMonitorDeviceSource> delayed_battery_check_;
96 #endif
98 #if defined(OS_WIN)
99 PowerMessageWindow power_message_window_;
100 #endif
102 DISALLOW_COPY_AND_ASSIGN(PowerMonitorDeviceSource);
105 } // namespace base
107 #endif // BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_