22970f573b
* refactor: use base::flat_map in ElectronMenuModel * refactor: use base::flat_map in BuildSubmenuFromModel() * refactor: use base::flat_map in GetDialogsMap() * refactor: use base::flat_map in DesktopCapturer * refactor: use base::flat_map, flat_set in ElectronBrowserClient * refactor: use base::flat_map in ProxyingURLLoaderFactory * refactor: use base::flat_map in MapToCommonId() * refactor: use base::flat_map for g_map_id * refactor: use base::flat_map for ViewsDelegate::AppbarAutohideEdgeMap * refactor: use base::flat_map for App::app_metrics_ * refactor: use base::flat_map for PowerSaveBlocker::wake_lock_types_ * refactor: use base::flat_map for NativeImage::hicons_ * refactor: use base::flat_map for MenuViews::menu_runners_ * refactor: use base::flat_map for WebViewManager::web_contents_embedder_map_ * refactor: use base::flat_map for InspectableWebContents::extensions_api_ * refactor: use base::flat_set for libnotify GetServerCapabilities() * refactor: use base::flat_set for InspectableWebContents::loaders_ * refactor: use base::flat_set for ElectronRendererClient::environments_ refactor: use base::flat_set for ElectronRendererClient::injected_frames_ * refactor: use base::flat_set for WebWorkerObserver::environments_
57 lines
1.7 KiB
C++
57 lines
1.7 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 "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"
|
|
|
|
namespace electron::api {
|
|
|
|
class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
|
|
public:
|
|
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
|
|
|
// gin::Wrappable
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) override;
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
// 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_
|