blob: 1e2c885fa45436735d1d193b11f2e79d8d740ba4 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/base_export.h"
#include "base/macros.h"
#include "base/power_monitor/power_monitor_source.h"
#include "base/power_monitor/power_observer.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#endif // !OS_WIN
#if defined(OS_IOS)
#include <objc/runtime.h>
#endif // OS_IOS
namespace base {
// A class used to monitor the power state change and notify the observers about
// the change event.
class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
~PowerMonitorDeviceSource() override;
#if defined(OS_MACOSX)
// Allocate system resources needed by the PowerMonitor class.
// This function must be called before instantiating an instance of the class
// and before the Sandbox is initialized.
#if !defined(OS_IOS)
static void AllocateSystemIOPorts();
static void AllocateSystemIOPorts() {}
#endif // OS_IOS
#endif // OS_MACOSX
#if defined(OS_CHROMEOS)
// On Chrome OS, Chrome receives power-related events from powerd, the system
// power daemon, via D-Bus signals received on the UI thread. base can't
// directly depend on that code, so this class instead exposes static methods
// so that events can be passed in.
static void SetPowerSource(bool on_battery);
static void HandleSystemSuspending();
static void HandleSystemResumed();
#if defined(OS_WIN)
// Represents a message-only window for power message handling on Windows.
// Only allow PowerMonitor to create it.
class PowerMessageWindow {
static LRESULT CALLBACK WndProcThunk(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam);
// Instance of the module containing the window procedure.
HMODULE instance_;
// A hidden message-only window.
HWND message_hwnd_;
#endif // OS_WIN
#if defined(OS_MACOSX)
void PlatformInit();
void PlatformDestroy();
// Platform-specific method to check whether the system is currently
// running on battery power. Returns true if running on batteries,
// false otherwise.
bool IsOnBatteryPowerImpl() override;
#if defined(OS_IOS)
// Holds pointers to system event notification observers.
std::vector<id> notification_observers_;
#if defined(OS_WIN)
PowerMessageWindow power_message_window_;
} // namespace base