
* chore: move gin::DeprecatedWrappable to gin_helper This is in preparation for migrating to gin::Wrappable based on cppgc #47922 The upstream class will be deleted soon via roller PR but the cppgc migration should happen outside the roll, this change retains the current functionality by copying the implementation into //electron/shell/common/gin_helper. The class can be deleted once the cppgc migration is complete. * chore: fix lint:cpp
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
// Copyright (c) 2015 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|
|
|
|
#include "base/containers/flat_map.h"
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
|
#include "services/device/public/mojom/wake_lock.mojom.h"
|
|
#include "shell/common/gin_helper/wrappable.h"
|
|
|
|
namespace gin {
|
|
class ObjectTemplateBuilder;
|
|
|
|
template <typename T>
|
|
class Handle;
|
|
} // namespace gin
|
|
|
|
namespace electron::api {
|
|
|
|
class PowerSaveBlocker final
|
|
: public gin_helper::DeprecatedWrappable<PowerSaveBlocker> {
|
|
public:
|
|
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
|
|
|
// gin_helper::Wrappable
|
|
static gin::DeprecatedWrapperInfo kWrapperInfo;
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) override;
|
|
const char* GetTypeName() override;
|
|
|
|
// disable copy
|
|
PowerSaveBlocker(const PowerSaveBlocker&) = delete;
|
|
PowerSaveBlocker& operator=(const PowerSaveBlocker&) = delete;
|
|
|
|
protected:
|
|
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
|
~PowerSaveBlocker() override;
|
|
|
|
private:
|
|
void UpdatePowerSaveBlocker();
|
|
int Start(device::mojom::WakeLockType type);
|
|
bool Stop(int id);
|
|
bool IsStarted(int id) const;
|
|
|
|
device::mojom::WakeLock* GetWakeLock();
|
|
|
|
// Current wake lock level.
|
|
device::mojom::WakeLockType current_lock_type_;
|
|
|
|
// Whether the wake lock is currently active.
|
|
bool is_wake_lock_active_ = false;
|
|
|
|
// Map from id to the corresponding blocker type for each request.
|
|
base::flat_map<int, device::mojom::WakeLockType> wake_lock_types_;
|
|
|
|
mojo::Remote<device::mojom::WakeLock> wake_lock_;
|
|
};
|
|
|
|
} // namespace electron::api
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|