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

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 a compile error 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
OLDNEW
(Empty)
1 // Copyright 2014 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_globals.h"
dmichael (off chromium) 2015/02/09 22:27:00 unused
Justin Chuang 2015/02/10 16:01:02 Done.
9 #include "ppapi/proxy/plugin_resource_tracker.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #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.
12 #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.
13 #include "ppapi/shared_impl/var.h"
14
15 namespace ppapi {
16 namespace proxy {
17
18 ImageCaptureResource::ImageCaptureResource(Connection connection,
19 PP_Instance instance)
20 : PluginResource(connection, instance),
21 open_state_(BEFORE_OPEN),
22 get_capabilities_output_(NULL) {
23 SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create());
24 }
25
26 ImageCaptureResource::~ImageCaptureResource() {
27 }
28
29 int32_t ImageCaptureResource::Open(PP_Var device_id,
30 scoped_refptr<TrackedCallback> callback) {
31 if (open_state_ != BEFORE_OPEN)
32 return PP_ERROR_FAILED;
33
34 if (TrackedCallback::IsPending(open_callback_))
35 return PP_ERROR_INPROGRESS;
36
37 scoped_refptr<StringVar> source_string_var;
38 source_string_var = StringVar::FromPPVar(device_id);
39 if (!source_string_var || source_string_var->value().empty())
40 return PP_ERROR_BADARGUMENT;
41
42 open_callback_ = callback;
43
44 Call<PpapiPluginMsg_ImageCapture_OpenReply>(
45 RENDERER, PpapiHostMsg_ImageCapture_Open(source_string_var->value()),
46 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply,
47 base::Unretained(this)));
48 return PP_OK_COMPLETIONPENDING;
49 }
50
51 void ImageCaptureResource::Close() {
52 if (open_state_ == CLOSED)
53 return;
54
55 if (TrackedCallback::IsPending(open_callback_)) {
56 open_callback_->PostAbort();
57 open_callback_ = NULL;
58 }
59
60 if (TrackedCallback::IsPending(get_capabilities_callback_)) {
61 *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
62 get_capabilities_callback_->PostAbort();
63 get_capabilities_callback_ = NULL;
64 get_capabilities_output_ = NULL;
65 }
66
67 Post(RENDERER, PpapiHostMsg_ImageCapture_Close());
68
69 open_state_ = CLOSED;
70 }
71
72 int32_t ImageCaptureResource::GetCameraCapabilities(
73 PP_Resource* capabilities,
74 scoped_refptr<TrackedCallback> callback) {
75 if (!IsOpened())
76 return PP_ERROR_FAILED;
77
78 if (TrackedCallback::IsPending(get_capabilities_callback_))
79 return PP_ERROR_INPROGRESS;
80
81 if (camera_capabilities_.get()) {
82 *capabilities = camera_capabilities_->GetReference();
83 return PP_OK;
84 }
85
86 get_capabilities_output_ = capabilities;
87 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
88 Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>(
89 RENDERER, PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes(),
90 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply,
91 base::Unretained(this)));
92 return PP_OK_COMPLETIONPENDING;
93 }
94
95 void ImageCaptureResource::OnPluginMsgOpenReply(
96 const ResourceMessageReplyParams& params) {
97 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK)
98 open_state_ = OPENED;
99
100 // The callback may have been aborted by Close().
101 if (TrackedCallback::IsPending(open_callback_))
102 open_callback_->Run(params.result());
103 }
104
105 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply(
106 const ResourceMessageReplyParams& params,
107 const std::vector<PP_Size>& preview_sizes) {
108 if (!TrackedCallback::IsPending(get_capabilities_callback_))
109 return;
110
111 // Return camera capabilities.
112 int32_t result = params.result();
113 scoped_refptr<TrackedCallback> callback;
114 callback.swap(get_capabilities_callback_);
115 if (result == PP_OK) {
116 camera_capabilities_ =
117 new CameraCapabilitiesResource(pp_instance(), preview_sizes);
118 *get_capabilities_output_ = camera_capabilities_->GetReference();
119 }
120 get_capabilities_output_ = NULL;
121 callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED);
122 }
123
124 } // namespace proxy
125 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698