electron/shell/browser/api/electron_api_power_save_blocker.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.7 KiB
C
Raw Normal View History

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.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_
2015-06-21 12:57:42 +00:00
#include "base/containers/flat_map.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
2015-06-21 12:57:42 +00:00
2022-06-29 19:55:47 +00:00
namespace electron::api {
2015-06-21 12:57:42 +00:00
class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
2015-06-21 12:57:42 +00:00
public:
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
const char* GetTypeName() override;
2016-04-25 01:17:54 +00:00
// disable copy
PowerSaveBlocker(const PowerSaveBlocker&) = delete;
PowerSaveBlocker& operator=(const PowerSaveBlocker&) = delete;
2015-06-21 12:57:42 +00:00
protected:
2016-04-25 01:17:54 +00:00
explicit PowerSaveBlocker(v8::Isolate* isolate);
~PowerSaveBlocker() override;
2015-06-21 12:57:42 +00:00
private:
2015-06-22 02:23:58 +00:00
void UpdatePowerSaveBlocker();
int Start(device::mojom::WakeLockType type);
2015-06-22 02:23:58 +00:00
bool Stop(int id);
refactor: prefer base::Contains() over find() + end() (#38443) * refactor: use base::Contains() in KeyWeakMap::Has() * refactor: use base::Contains() in WebRequest::RequestFilter::MatchesType() * refactor: use base::Contains() in BaseWindow::AddBrowserView() * refactor: use base::Contains() in DeepFreeze() * refactor: use base::Contains() in Clipboard::Read() * Revert "refactor: use base::Contains() in BaseWindow::AddBrowserView()" This reverts commit 60152359d3978451ebdd7c8eed602c2fb8a9cafa. * refactor: use base::Contains() in BaseWindow::AddBrowserView() * refactor: use base::Contains() in IsDevToolsFileSystemAdded() * refactor: use base::Contains() in MessagePort::DisentanglePorts() * refactor: use base::Contains() in PowerSaveBlocker::IsStarted() * refactor: use base::Contains() in SpellCheckClient::OnSpellCheckDone() * refactor: use base::Contains() in ShowTaskDialogWstr() * refactor: use base::Contains() in PrintViewManagerElectron::ScriptedPrint() * refactor: use base::Contains() in PrintViewManagerElectron::DidGetPrintedPagesCount() * refactor: use base::Contains() in NativeWindow::AddDraggableRegionProvider() * refactor: use base::Contains() in ElectronBindings::ActivateUVLoop() * refactor: use base::Contains() in NativeWindowViews::IsVisibleOnAllWorkspaces() * refactor: use base::Contains() in HidChooserController::OnDeviceAdded() * refactor: use base::Contains() in ElectronSandboxedRendererClient::WillReleaseScriptContext() * refactor: use base::Contains() in ElectronRendererClient::WillDestroyWorkerContextOnWorkerThread() * refactor: use base::Contains() in GlobalShortcut::OnKeyPressed()
2023-05-30 08:28:43 +00:00
bool IsStarted(int id) const;
2015-06-21 12:57:42 +00:00
device::mojom::WakeLock* GetWakeLock();
2015-06-22 02:23:58 +00:00
// Current wake lock level.
device::mojom::WakeLockType current_lock_type_;
// Whether the wake lock is currently active.
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.
base::flat_map<int, device::mojom::WakeLockType> wake_lock_types_;
mojo::Remote<device::mojom::WakeLock> wake_lock_;
2015-06-21 12:57:42 +00:00
};
2022-06-29 19:55:47 +00:00
} // namespace electron::api
2015-06-21 12:57:42 +00:00
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_