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

Unified Diff: ppapi/proxy/image_capture_resource.cc

Issue 848863002: PPAPI: implement GetSupportedPreviewSizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update histogram.xml with pepper_hash_for_uma Created 5 years, 10 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: ppapi/proxy/image_capture_resource.cc
diff --git a/ppapi/proxy/image_capture_resource.cc b/ppapi/proxy/image_capture_resource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..05636d56c5bc391749f9a6e8c7af18406df4ad9f
--- /dev/null
+++ b/ppapi/proxy/image_capture_resource.cc
@@ -0,0 +1,119 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/image_capture_resource.h"
+
+#include "ppapi/proxy/camera_capabilities_resource.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/var.h"
+
+namespace ppapi {
+namespace proxy {
+
+ImageCaptureResource::ImageCaptureResource(Connection connection,
+ PP_Instance instance)
+ : PluginResource(connection, instance),
+ open_state_(BEFORE_OPEN) {
+ SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create());
+}
+
+ImageCaptureResource::~ImageCaptureResource() {
+}
+
+int32_t ImageCaptureResource::Open(
+ PP_Var device_id,
+ const scoped_refptr<TrackedCallback>& callback) {
+ if (open_state_ != BEFORE_OPEN)
+ return PP_ERROR_FAILED;
+
+ if (TrackedCallback::IsPending(open_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ scoped_refptr<StringVar> source_string_var;
+ source_string_var = StringVar::FromPPVar(device_id);
dcheng 2015/02/12 21:47:20 Nit: combine declaration and initialization
Justin Chuang 2015/02/16 19:15:24 Done. Thx
+ if (!source_string_var || source_string_var->value().empty())
+ return PP_ERROR_BADARGUMENT;
+
+ open_callback_ = callback;
+
+ Call<PpapiPluginMsg_ImageCapture_OpenReply>(
+ RENDERER, PpapiHostMsg_ImageCapture_Open(source_string_var->value()),
+ base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply,
+ base::Unretained(this)));
dcheng 2015/02/12 21:47:20 Why is it OK to use base::Unretained() here? A rou
Justin Chuang 2015/02/16 19:15:24 Actually I see most code use Unretained(this), vid
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void ImageCaptureResource::Close() {
+ if (open_state_ == CLOSED)
+ return;
+
+ if (TrackedCallback::IsPending(open_callback_)) {
+ open_callback_->PostAbort();
+ open_callback_ = NULL;
dcheng 2015/02/12 21:47:20 Use nullptr instead of NULL.
Justin Chuang 2015/02/16 19:15:24 Done.
+ }
+
+ if (TrackedCallback::IsPending(get_capabilities_callback_)) {
dcheng 2015/02/12 21:47:20 This doesn't seem scalable. Are we going to need t
Justin Chuang 2015/02/16 19:15:24 Hmm... There are only two. For now, I prefer not t
+ get_capabilities_callback_->PostAbort();
+ get_capabilities_callback_ = NULL;
+ }
+
+ Post(RENDERER, PpapiHostMsg_ImageCapture_Close());
+
+ open_state_ = CLOSED;
+}
+
+int32_t ImageCaptureResource::GetCameraCapabilities(
+ PP_Resource* capabilities,
+ const scoped_refptr<TrackedCallback>& callback) {
+ if (!is_opened())
+ return PP_ERROR_FAILED;
+
+ if (TrackedCallback::IsPending(get_capabilities_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ if (camera_capabilities_.get()) {
+ *capabilities = camera_capabilities_->GetReference();
+ return PP_OK;
+ }
+
+ get_capabilities_callback_ = callback;
+ Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>(
+ RENDERER, PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes(),
+ base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply,
+ base::Unretained(this), capabilities));
dcheng 2015/02/12 21:47:20 Ditto--why is base::Unretained() safe here?
Justin Chuang 2015/02/16 19:15:24 Ditto
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void ImageCaptureResource::OnPluginMsgOpenReply(
+ const ResourceMessageReplyParams& params) {
+ if (open_state_ == BEFORE_OPEN && params.result() == PP_OK)
+ open_state_ = OPENED;
+
+ // The callback may have been aborted by Close().
+ if (TrackedCallback::IsPending(open_callback_))
dcheng 2015/02/12 21:47:20 Shouldn't this happen before we update open_state_
Justin Chuang 2015/02/16 19:15:24 No, I think the state should be updated before inv
dcheng 2015/02/16 19:24:22 Let's say I call Open(), and then I call Close() b
Justin Chuang 2015/02/16 19:54:22 It will be CLOSED 1. Close() set it to CLOSED and
dcheng 2015/02/16 20:00:14 As a general pattern, and for consistency, I think
+ open_callback_->Run(params.result());
+}
+
+void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply(
+ PP_Resource* capabilities_output,
+ const ResourceMessageReplyParams& params,
+ const std::vector<PP_Size>& preview_sizes) {
+ if (!TrackedCallback::IsPending(get_capabilities_callback_))
+ return;
+
+ // Return camera capabilities.
+ int32_t result = params.result();
+ scoped_refptr<TrackedCallback> callback;
+ callback.swap(get_capabilities_callback_);
+ if (result == PP_OK) {
+ camera_capabilities_ =
+ new CameraCapabilitiesResource(pp_instance(), preview_sizes);
+ *capabilities_output = camera_capabilities_->GetReference();
+ }
+ callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED);
+}
+
+} // namespace proxy
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698