Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: extensions/browser/api/system_display/system_display_api.cc

Issue 2282063002: [Extensions] Convert some SyncExtensionFunctions (Closed)
Patch Set: lazyboy's Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/system_display/system_display_api.h ('k') | extensions/browser/api/test/test_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/system_display/system_display_api.cc
diff --git a/extensions/browser/api/system_display/system_display_api.cc b/extensions/browser/api/system_display/system_display_api.cc
index 2b09bad50bcd88c0cb5771da2772fb3a04223ff4..ab613a46b45d79892f90dfaf38d8922f48c20915 100644
--- a/extensions/browser/api/system_display/system_display_api.cc
+++ b/extensions/browser/api/system_display/system_display_api.cc
@@ -17,163 +17,125 @@
namespace extensions {
-namespace system_display = api::system_display;
+namespace display = api::system_display;
const char SystemDisplayFunction::kCrosOnlyError[] =
"Function available only on ChromeOS.";
const char SystemDisplayFunction::kKioskOnlyError[] =
"Only kiosk enabled extensions are allowed to use this function.";
-bool SystemDisplayFunction::CheckValidExtension() {
- if (!extension())
+bool SystemDisplayFunction::PreRunValidation(std::string* error) {
+ if (!UIThreadExtensionFunction::PreRunValidation(error))
+ return false;
+
+#if !defined(OS_CHROMEOS)
+ *error = kCrosOnlyError;
+ return false;
+#else
lazyboy 2016/08/29 18:03:05 nit: no need for #else block, just #endif is fine.
Devlin 2016/08/29 20:22:25 KioskModeInfo is currently only included on CrOS (
lazyboy 2016/08/29 21:31:46 Ah, just noticed those runs. Acknowledged.
+ if (!ShouldRestrictToKioskAndWebUI())
+ return true;
+
+ if (source_context_type() == Feature::WEBUI_CONTEXT)
lazyboy 2016/08/29 18:03:05 Got it, thanks!
return true;
-#if defined(OS_CHROMEOS)
if (KioskModeInfo::IsKioskEnabled(extension()))
return true;
-#endif
- SetError(kKioskOnlyError);
+ *error = kKioskOnlyError;
return false;
+#endif
}
-bool SystemDisplayGetInfoFunction::RunSync() {
+bool SystemDisplayFunction::ShouldRestrictToKioskAndWebUI() {
+ return true;
+}
+
+ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() {
DisplayInfoProvider::DisplayUnitInfoList all_displays_info =
DisplayInfoProvider::Get()->GetAllDisplaysInfo();
- results_ = system_display::GetInfo::Results::Create(all_displays_info);
- return true;
+ return RespondNow(
+ ArgumentList(display::GetInfo::Results::Create(all_displays_info)));
}
-bool SystemDisplayGetDisplayLayoutFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
+ExtensionFunction::ResponseAction SystemDisplayGetDisplayLayoutFunction::Run() {
DisplayInfoProvider::DisplayLayoutList display_layout =
DisplayInfoProvider::Get()->GetDisplayLayout();
- results_ = system_display::GetDisplayLayout::Results::Create(display_layout);
- return true;
-#endif
+ return RespondNow(
+ ArgumentList(display::GetDisplayLayout::Results::Create(display_layout)));
}
-bool SystemDisplaySetDisplayPropertiesFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
+bool SystemDisplayGetDisplayLayoutFunction::ShouldRestrictToKioskAndWebUI() {
return false;
-#else
- if (!CheckValidExtension())
- return false;
+}
+
+ExtensionFunction::ResponseAction
+SystemDisplaySetDisplayPropertiesFunction::Run() {
std::string error;
- std::unique_ptr<system_display::SetDisplayProperties::Params> params(
- system_display::SetDisplayProperties::Params::Create(*args_));
+ std::unique_ptr<display::SetDisplayProperties::Params> params(
+ display::SetDisplayProperties::Params::Create(*args_));
bool result =
DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error);
if (!result)
- SetError(error);
- return result;
-#endif
+ return RespondNow(Error(error));
+ return RespondNow(NoArguments());
}
-bool SystemDisplaySetDisplayLayoutFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::SetDisplayLayout::Params> params(
- system_display::SetDisplayLayout::Params::Create(*args_));
- if (!DisplayInfoProvider::Get()->SetDisplayLayout(params->layouts)) {
- SetError("Unable to set display layout");
- return false;
- }
- return true;
-#endif
+ExtensionFunction::ResponseAction SystemDisplaySetDisplayLayoutFunction::Run() {
+ std::unique_ptr<display::SetDisplayLayout::Params> params(
+ display::SetDisplayLayout::Params::Create(*args_));
+ if (!DisplayInfoProvider::Get()->SetDisplayLayout(params->layouts))
+ return RespondNow(Error("Unable to set display layout"));
+ return RespondNow(NoArguments());
}
-bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::EnableUnifiedDesktop::Params> params(
- system_display::EnableUnifiedDesktop::Params::Create(*args_));
+ExtensionFunction::ResponseAction
+SystemDisplayEnableUnifiedDesktopFunction::Run() {
+ std::unique_ptr<display::EnableUnifiedDesktop::Params> params(
+ display::EnableUnifiedDesktop::Params::Create(*args_));
DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled);
- return true;
-#endif
+ return RespondNow(NoArguments());
}
-bool SystemDisplayOverscanCalibrationStartFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::OverscanCalibrationStart::Params> params(
- system_display::OverscanCalibrationStart::Params::Create(*args_));
- if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) {
- SetError("Invalid display ID: " + params->id);
- return false;
- }
- return true;
-#endif
+ExtensionFunction::ResponseAction
+SystemDisplayOverscanCalibrationStartFunction::Run() {
+ std::unique_ptr<display::OverscanCalibrationStart::Params> params(
+ display::OverscanCalibrationStart::Params::Create(*args_));
+ if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id))
+ return RespondNow(Error("Invalid display ID: " + params->id));
+ return RespondNow(NoArguments());
}
-bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::OverscanCalibrationAdjust::Params> params(
- system_display::OverscanCalibrationAdjust::Params::Create(*args_));
- if (!params) {
- SetError("Invalid parameters");
- return false;
- }
+ExtensionFunction::ResponseAction
+SystemDisplayOverscanCalibrationAdjustFunction::Run() {
+ std::unique_ptr<display::OverscanCalibrationAdjust::Params> params(
+ display::OverscanCalibrationAdjust::Params::Create(*args_));
+ if (!params)
+ return RespondNow(Error("Invalid parameters"));
if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id,
params->delta)) {
- SetError("Calibration not started for display ID: " + params->id);
- return false;
+ return RespondNow(
+ Error("Calibration not started for display ID: " + params->id));
}
- return true;
-#endif
+ return RespondNow(NoArguments());
}
-bool SystemDisplayOverscanCalibrationResetFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::OverscanCalibrationReset::Params> params(
- system_display::OverscanCalibrationReset::Params::Create(*args_));
- if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) {
- SetError("Calibration not started for display ID: " + params->id);
- return false;
- }
- return true;
-#endif
+ExtensionFunction::ResponseAction
+SystemDisplayOverscanCalibrationResetFunction::Run() {
+ std::unique_ptr<display::OverscanCalibrationReset::Params> params(
+ display::OverscanCalibrationReset::Params::Create(*args_));
+ if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id))
+ return RespondNow(
+ Error("Calibration not started for display ID: " + params->id));
+ return RespondNow(NoArguments());
}
-bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() {
-#if !defined(OS_CHROMEOS)
- SetError(kCrosOnlyError);
- return false;
-#else
- if (!CheckValidExtension())
- return false;
- std::unique_ptr<system_display::OverscanCalibrationComplete::Params> params(
- system_display::OverscanCalibrationComplete::Params::Create(*args_));
+ExtensionFunction::ResponseAction
+SystemDisplayOverscanCalibrationCompleteFunction::Run() {
+ std::unique_ptr<display::OverscanCalibrationComplete::Params> params(
+ display::OverscanCalibrationComplete::Params::Create(*args_));
if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) {
- SetError("Calibration not started for display ID: " + params->id);
- return false;
+ return RespondNow(
+ Error("Calibration not started for display ID: " + params->id));
}
- return true;
-#endif
+ return RespondNow(NoArguments());
}
} // namespace extensions
« no previous file with comments | « extensions/browser/api/system_display/system_display_api.h ('k') | extensions/browser/api/test/test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698