Chromium Code Reviews| 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..210f0d07414c1bf3cf2c72e6627d86a2bcf0e3b7 |
| --- /dev/null |
| +++ b/ppapi/proxy/image_capture_resource.cc |
| @@ -0,0 +1,125 @@ |
| +// Copyright 2014 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_globals.h" |
|
dmichael (off chromium)
2015/02/09 22:27:00
unused
Justin Chuang
2015/02/10 16:01:02
Done.
|
| +#include "ppapi/proxy/plugin_resource_tracker.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/proxy/ppb_buffer_proxy.h" |
|
dmichael (off chromium)
2015/02/09 22:27:00
unused
Justin Chuang
2015/02/10 16:01:02
Done.
|
| +#include "ppapi/shared_impl/proxy_lock.h" |
|
dmichael (off chromium)
2015/02/09 22:26:59
unused
Justin Chuang
2015/02/10 16:01:02
Done.
|
| +#include "ppapi/shared_impl/var.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +ImageCaptureResource::ImageCaptureResource(Connection connection, |
| + PP_Instance instance) |
| + : PluginResource(connection, instance), |
| + open_state_(BEFORE_OPEN), |
| + get_capabilities_output_(NULL) { |
| + SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create()); |
| +} |
| + |
| +ImageCaptureResource::~ImageCaptureResource() { |
| +} |
| + |
| +int32_t ImageCaptureResource::Open(PP_Var device_id, |
| + 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); |
| + 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))); |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void ImageCaptureResource::Close() { |
| + if (open_state_ == CLOSED) |
| + return; |
| + |
| + if (TrackedCallback::IsPending(open_callback_)) { |
| + open_callback_->PostAbort(); |
| + open_callback_ = NULL; |
| + } |
| + |
| + if (TrackedCallback::IsPending(get_capabilities_callback_)) { |
| + *get_capabilities_output_ = 0; |
|
dmichael (off chromium)
2015/02/09 22:26:59
nit: Better to just not write the output param if
Justin Chuang
2015/02/10 16:01:02
Removed this line. Thanks
|
| + get_capabilities_callback_->PostAbort(); |
| + get_capabilities_callback_ = NULL; |
| + get_capabilities_output_ = NULL; |
| + } |
| + |
| + Post(RENDERER, PpapiHostMsg_ImageCapture_Close()); |
| + |
| + open_state_ = CLOSED; |
| +} |
| + |
| +int32_t ImageCaptureResource::GetCameraCapabilities( |
| + PP_Resource* capabilities, |
| + scoped_refptr<TrackedCallback> callback) { |
| + if (!IsOpened()) |
| + 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_output_ = capabilities; |
| + get_capabilities_callback_ = callback; |
|
dmichael (off chromium)
2015/02/09 22:26:59
As an alternative, you can simply bind these below
Justin Chuang
2015/02/10 16:01:02
Good point. To do in the next patchset.
Justin Chuang
2015/02/10 17:44:09
Done in Patch Set 18. PTAL.
Note that I still don
|
| + Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>( |
| + RENDERER, PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes(), |
| + base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply, |
| + base::Unretained(this))); |
| + 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_)) |
| + open_callback_->Run(params.result()); |
| +} |
| + |
| +void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply( |
| + 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); |
| + *get_capabilities_output_ = camera_capabilities_->GetReference(); |
| + } |
| + get_capabilities_output_ = NULL; |
| + callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |