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

Side by Side 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: fix typo: int32->int32_t 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 unified diff | Download patch
« no previous file with comments | « ppapi/proxy/image_capture_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/image_capture_resource.h"
6
7 #include "ppapi/proxy/camera_capabilities_resource.h"
8 #include "ppapi/proxy/plugin_resource_tracker.h"
9 #include "ppapi/proxy/ppapi_messages.h"
10 #include "ppapi/shared_impl/var.h"
11
12 namespace ppapi {
13 namespace proxy {
14
15 ImageCaptureResource::ImageCaptureResource(Connection connection,
16 PP_Instance instance)
17 : PluginResource(connection, instance),
18 open_state_(OpenState::BEFORE_OPEN) {
19 SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create());
20 }
21
22 ImageCaptureResource::~ImageCaptureResource() {
23 }
24
25 int32_t ImageCaptureResource::Open(
26 PP_Var device_id,
27 const scoped_refptr<TrackedCallback>& callback) {
28 if (open_state_ != OpenState::BEFORE_OPEN)
29 return PP_ERROR_FAILED;
30
31 if (TrackedCallback::IsPending(open_callback_))
32 return PP_ERROR_INPROGRESS;
33
34 scoped_refptr<StringVar> source_string_var(StringVar::FromPPVar(device_id));
35 if (!source_string_var || source_string_var->value().empty())
36 return PP_ERROR_BADARGUMENT;
37
38 open_callback_ = callback;
39
40 Call<PpapiPluginMsg_ImageCapture_OpenReply>(
41 RENDERER, PpapiHostMsg_ImageCapture_Open(source_string_var->value()),
42 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply,
43 base::Unretained(this)));
44 return PP_OK_COMPLETIONPENDING;
45 }
46
47 void ImageCaptureResource::Close() {
48 if (open_state_ == OpenState::CLOSED)
49 return;
50
51 if (TrackedCallback::IsPending(open_callback_)) {
52 open_callback_->PostAbort();
53 open_callback_ = nullptr;
54 }
55
56 if (TrackedCallback::IsPending(get_capabilities_callback_)) {
57 get_capabilities_callback_->PostAbort();
58 get_capabilities_callback_ = nullptr;
59 }
60
61 Post(RENDERER, PpapiHostMsg_ImageCapture_Close());
62
63 open_state_ = OpenState::CLOSED;
64 }
65
66 int32_t ImageCaptureResource::GetCameraCapabilities(
67 PP_Resource* capabilities,
68 const scoped_refptr<TrackedCallback>& callback) {
69 if (!is_opened())
70 return PP_ERROR_FAILED;
71
72 if (TrackedCallback::IsPending(get_capabilities_callback_))
73 return PP_ERROR_INPROGRESS;
74
75 if (camera_capabilities_.get()) {
76 *capabilities = camera_capabilities_->GetReference();
77 return PP_OK;
78 }
79
80 get_capabilities_callback_ = callback;
81 Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>(
82 RENDERER, PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes(),
83 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply,
84 base::Unretained(this), capabilities));
85 return PP_OK_COMPLETIONPENDING;
86 }
87
88 void ImageCaptureResource::OnPluginMsgOpenReply(
89 const ResourceMessageReplyParams& params) {
90 // The callback may have been aborted by Close().
91 if (TrackedCallback::IsPending(open_callback_)) {
92 if (open_state_ == OpenState::BEFORE_OPEN && params.result() == PP_OK)
93 open_state_ = OpenState::OPENED;
94
95 open_callback_->Run(params.result());
96 }
97 }
98
99 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply(
100 PP_Resource* capabilities_output,
101 const ResourceMessageReplyParams& params,
102 const std::vector<PP_Size>& preview_sizes) {
103 if (!TrackedCallback::IsPending(get_capabilities_callback_))
104 return;
105
106 // Return camera capabilities.
107 int32_t result = params.result();
108 scoped_refptr<TrackedCallback> callback;
109 callback.swap(get_capabilities_callback_);
110 if (result == PP_OK) {
111 camera_capabilities_ =
112 new CameraCapabilitiesResource(pp_instance(), preview_sizes);
113 *capabilities_output = camera_capabilities_->GetReference();
114 }
115 callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED);
116 }
117
118 } // namespace proxy
119 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/image_capture_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698