OLD | NEW |
---|---|
(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_(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_ != 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; | |
35 source_string_var = StringVar::FromPPVar(device_id); | |
36 if (!source_string_var || source_string_var->value().empty()) | |
37 return PP_ERROR_BADARGUMENT; | |
38 | |
39 open_callback_ = callback; | |
40 | |
41 Call<PpapiPluginMsg_ImageCapture_OpenReply>( | |
42 RENDERER, PpapiHostMsg_ImageCapture_Open(source_string_var->value()), | |
43 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply, | |
44 base::Unretained(this))); | |
45 return PP_OK_COMPLETIONPENDING; | |
46 } | |
47 | |
48 void ImageCaptureResource::Close() { | |
49 if (open_state_ == CLOSED) | |
50 return; | |
51 | |
52 if (TrackedCallback::IsPending(open_callback_)) { | |
53 open_callback_->PostAbort(); | |
54 open_callback_ = NULL; | |
55 } | |
56 | |
Justin Chuang
2015/02/10 17:56:38
Note that it doesn't handle a race condition becau
dmichael (off chromium)
2015/02/10 18:12:32
Oh, thanks for bringing that up. I wasn't thinking
Justin Chuang
2015/02/10 19:02:08
Do you think it's worth the extra code to just for
dmichael (off chromium)
2015/02/10 19:07:47
Yes, I would recommend that. It's our convention f
| |
57 Post(RENDERER, PpapiHostMsg_ImageCapture_Close()); | |
58 | |
59 open_state_ = CLOSED; | |
60 } | |
61 | |
62 int32_t ImageCaptureResource::GetCameraCapabilities( | |
63 PP_Resource* capabilities, | |
64 const scoped_refptr<TrackedCallback>& callback) { | |
65 if (!is_opened()) | |
66 return PP_ERROR_FAILED; | |
67 | |
68 if (camera_capabilities_.get()) { | |
69 *capabilities = camera_capabilities_->GetReference(); | |
70 return PP_OK; | |
71 } | |
72 | |
73 Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>( | |
74 RENDERER, PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes(), | |
75 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply, | |
76 base::Unretained(this), capabilities, callback)); | |
77 return PP_OK_COMPLETIONPENDING; | |
78 } | |
79 | |
80 void ImageCaptureResource::OnPluginMsgOpenReply( | |
81 const ResourceMessageReplyParams& params) { | |
82 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK) | |
83 open_state_ = OPENED; | |
84 | |
85 // The callback may have been aborted by Close(). | |
86 if (TrackedCallback::IsPending(open_callback_)) | |
87 open_callback_->Run(params.result()); | |
88 } | |
89 | |
90 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply( | |
91 PP_Resource* output_capabilities, | |
92 scoped_refptr<TrackedCallback> callback, | |
93 const ResourceMessageReplyParams& params, | |
94 const std::vector<PP_Size>& preview_sizes) { | |
95 int32_t result = params.result(); | |
96 if (result == PP_OK) { | |
97 camera_capabilities_ = | |
98 new CameraCapabilitiesResource(pp_instance(), preview_sizes); | |
99 *output_capabilities = camera_capabilities_->GetReference(); | |
100 } | |
101 callback->Run(result); | |
102 } | |
103 | |
104 } // namespace proxy | |
105 } // namespace ppapi | |
OLD | NEW |