#include "extensions/browser/api/power/power_api.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "content/public/browser/device_service.h"
#include "extensions/browser/api/power/activity_reporter_delegate.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/api/power.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
namespace extensions {
namespace {
const char kWakeLockDescription[] = …;
device::mojom::WakeLockType LevelToWakeLockType(api::power::Level level) { … }
base::LazyInstance<BrowserContextKeyedAPIFactory<PowerAPI>>::DestructorAtExit
g_factory = …;
}
ExtensionFunction::ResponseAction PowerRequestKeepAwakeFunction::Run() { … }
ExtensionFunction::ResponseAction PowerReleaseKeepAwakeFunction::Run() { … }
#if BUILDFLAG(IS_CHROMEOS)
ExtensionFunction::ResponseAction PowerReportActivityFunction::Run() {
std::optional<std::string> error =
extensions::ActivityReporterDelegate::GetDelegate()->ReportActivity();
if (error.has_value()) {
return RespondNow(Error(error.value()));
}
return RespondNow(NoArguments());
}
#endif
PowerAPI* PowerAPI::Get(content::BrowserContext* context) { … }
BrowserContextKeyedAPIFactory<PowerAPI>* PowerAPI::GetFactoryInstance() { … }
void PowerAPI::AddRequest(const ExtensionId& extension_id,
api::power::Level level) { … }
void PowerAPI::RemoveRequest(const ExtensionId& extension_id) { … }
void PowerAPI::SetWakeLockFunctionsForTesting(
ActivateWakeLockFunction activate_function,
CancelWakeLockFunction cancel_function) { … }
void PowerAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
PowerAPI::PowerAPI(content::BrowserContext* context)
: … { … }
PowerAPI::~PowerAPI() = default;
void PowerAPI::UpdateWakeLock() { … }
void PowerAPI::Shutdown() { … }
void PowerAPI::ActivateWakeLock(device::mojom::WakeLockType type) { … }
void PowerAPI::CancelWakeLock() { … }
device::mojom::WakeLock* PowerAPI::GetWakeLock() { … }
}