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

Unified Diff: extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc

Issue 1281263003: Change webcamPrivate.set/get/reset to async APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
Index: extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc
diff --git a/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc b/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc
index 5f024b07929c03fdc5e1c1bfa9cbaae71902521c..b75289218b11357bdb1690ede3ed07bbf6d3f0f8 100644
--- a/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc
+++ b/extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc
@@ -21,8 +21,13 @@ class BrowserContext;
} // namespace content
namespace {
+
const char kPathInUse[] = "Path in use";
const char kUnknownWebcam[] = "Unknown webcam id";
+const char kGetWebcamPTZError[] = "Can't get web camera pan/tilt/zoom.";
+const char kSetWebcamPTZError[] = "Can't set web camera pan/tilt/zoom.";
+const char kResetWebcamError[] = "Can't reset web camera.";
+
} // namespace
namespace extensions {
@@ -224,7 +229,7 @@ WebcamPrivateSetFunction::WebcamPrivateSetFunction() {
WebcamPrivateSetFunction::~WebcamPrivateSetFunction() {
}
-bool WebcamPrivateSetFunction::RunSync() {
+bool WebcamPrivateSetFunction::RunAsync() {
scoped_ptr<webcam_private::Set::Params> params(
webcam_private::Set::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
@@ -237,7 +242,9 @@ bool WebcamPrivateSetFunction::RunSync() {
}
if (params->config.pan) {
- webcam->SetPan(*(params->config.pan));
+ webcam->SetPan(
+ *(params->config.pan),
+ base::Bind(&WebcamPrivateSetFunction::OnSetWebcamParameters, this));
}
if (params->config.pan_direction) {
@@ -256,11 +263,15 @@ bool WebcamPrivateSetFunction::RunSync() {
direction = Webcam::PAN_LEFT;
break;
}
- webcam->SetPanDirection(direction);
+ webcam->SetPanDirection(
+ direction,
+ base::Bind(&WebcamPrivateSetFunction::OnSetWebcamParameters, this));
}
if (params->config.tilt) {
- webcam->SetTilt(*(params->config.tilt));
+ webcam->SetTilt(
+ *(params->config.tilt),
+ base::Bind(&WebcamPrivateSetFunction::OnSetWebcamParameters, this));
}
if (params->config.tilt_direction) {
@@ -279,24 +290,32 @@ bool WebcamPrivateSetFunction::RunSync() {
direction = Webcam::TILT_DOWN;
break;
}
- webcam->SetTiltDirection(direction);
+ webcam->SetTiltDirection(
+ direction,
+ base::Bind(&WebcamPrivateSetFunction::OnSetWebcamParameters, this));
}
if (params->config.zoom) {
- webcam->SetZoom(*(params->config.zoom));
+ webcam->SetZoom(
+ *(params->config.zoom),
+ base::Bind(&WebcamPrivateSetFunction::OnSetWebcamParameters, this));
}
-
return true;
}
+void WebcamPrivateSetFunction::OnSetWebcamParameters(bool success) {
+ if (!success)
+ SetError(kSetWebcamPTZError);
+}
+
WebcamPrivateGetFunction::WebcamPrivateGetFunction() {
}
WebcamPrivateGetFunction::~WebcamPrivateGetFunction() {
}
-bool WebcamPrivateGetFunction::RunSync() {
+bool WebcamPrivateGetFunction::RunAsync() {
scoped_ptr<webcam_private::Get::Params> params(
webcam_private::Get::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
@@ -308,32 +327,43 @@ bool WebcamPrivateGetFunction::RunSync() {
return false;
}
- webcam_private::WebcamConfiguration result;
-
- int pan;
- if (webcam->GetPan(&pan))
- result.pan.reset(new double(pan));
-
- int tilt;
- if (webcam->GetTilt(&tilt))
- result.tilt.reset(new double(tilt));
-
- int zoom;
- if (webcam->GetZoom(&zoom))
- result.zoom.reset(new double(zoom));
-
- SetResult(result.ToValue().release());
+ switch (params->type) {
+ case webcam_private::INQUIRE_TYPE_PAN:
+ webcam->GetPan(
+ base::Bind(&WebcamPrivateGetFunction::OnGetWebcamParameters, this));
+ break;
+ case webcam_private::INQUIRE_TYPE_TILT:
+ webcam->GetTilt(
+ base::Bind(&WebcamPrivateGetFunction::OnGetWebcamParameters, this));
+ break;
+ case webcam_private::INQUIRE_TYPE_ZOOM:
+ webcam->GetZoom(
+ base::Bind(&WebcamPrivateGetFunction::OnGetWebcamParameters, this));
+ break;
+ default:
+ break;
+ }
return true;
}
+void WebcamPrivateGetFunction::OnGetWebcamParameters(bool success, int value) {
+ if (success) {
+ SetResult(new base::FundamentalValue(value));
+ SendResponse(true);
+ } else {
+ SetError(kGetWebcamPTZError);
+ SendResponse(false);
+ }
+}
+
WebcamPrivateResetFunction::WebcamPrivateResetFunction() {
}
WebcamPrivateResetFunction::~WebcamPrivateResetFunction() {
}
-bool WebcamPrivateResetFunction::RunSync() {
+bool WebcamPrivateResetFunction::RunAsync() {
scoped_ptr<webcam_private::Reset::Params> params(
webcam_private::Reset::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
@@ -345,11 +375,17 @@ bool WebcamPrivateResetFunction::RunSync() {
return false;
}
- webcam->Reset(params->config.pan, params->config.tilt, params->config.zoom);
+ webcam->Reset(params->config.pan, params->config.tilt, params->config.zoom,
+ base::Bind(&WebcamPrivateResetFunction::OnResetWebcam, this));
return true;
}
+void WebcamPrivateResetFunction::OnResetWebcam(bool success) {
+ if (!success)
+ SetError(kResetWebcamError);
+}
+
static base::LazyInstance<BrowserContextKeyedAPIFactory<WebcamPrivateAPI>>
g_factory = LAZY_INSTANCE_INITIALIZER;

Powered by Google App Engine
This is Rietveld 408576698