2015-06-21 12:57:42 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|
|
|
|
#define SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|
2015-06-21 12:57:42 +00:00
|
|
|
|
2015-06-22 02:23:58 +00:00
|
|
|
#include <map>
|
2016-07-04 06:08:55 +00:00
|
|
|
#include <memory>
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2019-05-01 20:24:01 +00:00
|
|
|
#include "gin/handle.h"
|
|
|
|
#include "gin/object_template_builder.h"
|
|
|
|
#include "gin/wrappable.h"
|
2019-12-11 00:22:35 +00:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2018-10-24 05:12:58 +00:00
|
|
|
#include "services/device/public/mojom/wake_lock.mojom.h"
|
2015-06-21 12:57:42 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-06-21 12:57:42 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2019-05-01 20:24:01 +00:00
|
|
|
class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
|
2015-06-21 12:57:42 +00:00
|
|
|
public:
|
2019-05-01 20:24:01 +00:00
|
|
|
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
|
|
|
|
|
|
|
// gin::Wrappable
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
2015-06-21 12:57:42 +00:00
|
|
|
|
2019-05-01 20:24:01 +00:00
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2015-06-21 12:57:42 +00:00
|
|
|
protected:
|
2016-04-25 01:17:54 +00:00
|
|
|
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
2015-11-04 10:21:03 +00:00
|
|
|
~PowerSaveBlocker() override;
|
|
|
|
|
2015-06-21 12:57:42 +00:00
|
|
|
private:
|
2015-06-22 02:23:58 +00:00
|
|
|
void UpdatePowerSaveBlocker();
|
2018-04-11 09:00:59 +00:00
|
|
|
int Start(device::mojom::WakeLockType type);
|
2015-06-22 02:23:58 +00:00
|
|
|
bool Stop(int id);
|
|
|
|
bool IsStarted(int id);
|
2015-06-21 12:57:42 +00:00
|
|
|
|
2018-10-24 05:12:58 +00:00
|
|
|
device::mojom::WakeLock* GetWakeLock();
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2018-10-24 05:12:58 +00:00
|
|
|
// Current wake lock level.
|
|
|
|
device::mojom::WakeLockType current_lock_type_;
|
|
|
|
|
|
|
|
// Whether the wake lock is currently active.
|
2021-01-26 18:16:21 +00:00
|
|
|
bool is_wake_lock_active_ = false;
|
2015-06-22 02:23:58 +00:00
|
|
|
|
|
|
|
// Map from id to the corresponding blocker type for each request.
|
2018-04-11 09:00:59 +00:00
|
|
|
using WakeLockTypeMap = std::map<int, device::mojom::WakeLockType>;
|
2018-10-24 05:12:58 +00:00
|
|
|
WakeLockTypeMap wake_lock_types_;
|
|
|
|
|
2019-12-11 00:22:35 +00:00
|
|
|
mojo::Remote<device::mojom::WakeLock> wake_lock_;
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2015-06-21 12:57:42 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2015-06-21 12:57:42 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#endif // SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
|