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

Side by Side Diff: ppapi/cpp/array_output.h

Issue 9965080: Change the cpp wrappers of audio input/video capture to use CompletionCallbackWithOutput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More changes in response to Brett's comments. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/cpp/array_output.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_CPP_ARRAY_OUTPUT_H_ 5 #ifndef PPAPI_CPP_ARRAY_OUTPUT_H_
6 #define PPAPI_CPP_ARRAY_OUTPUT_H_ 6 #define PPAPI_CPP_ARRAY_OUTPUT_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "ppapi/c/pp_array_output.h" 10 #include "ppapi/c/pp_array_output.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // writing PP_Vars, do this: 194 // writing PP_Vars, do this:
195 // 195 //
196 // VarArrayOutputAdapterWithStorage adapter; 196 // VarArrayOutputAdapterWithStorage adapter;
197 // ppb_foo->GetVars(adapter.pp_output_array()); 197 // ppb_foo->GetVars(adapter.pp_output_array());
198 // const std::vector<pp::Var>& result = adapter.output(). 198 // const std::vector<pp::Var>& result = adapter.output().
199 // 199 //
200 // This one is non-inline since it's not templatized. 200 // This one is non-inline since it's not templatized.
201 class VarArrayOutputAdapterWithStorage : public ArrayOutputAdapter<PP_Var> { 201 class VarArrayOutputAdapterWithStorage : public ArrayOutputAdapter<PP_Var> {
202 public: 202 public:
203 VarArrayOutputAdapterWithStorage(); 203 VarArrayOutputAdapterWithStorage();
204 virtual ~VarArrayOutputAdapterWithStorage();
204 205
205 // Returns the final array of resource objects, converting the PP_Vars 206 // Returns the final array of resource objects, converting the PP_Vars
206 // written by the browser to pp::Var objects. 207 // written by the browser to pp::Var objects.
207 // 208 //
208 // This function should only be called once or we would end up converting 209 // This function should only be called once or we would end up converting
209 // the array more than once, which would mess up the refcounting. 210 // the array more than once, which would mess up the refcounting.
210 std::vector<Var>& output(); 211 std::vector<Var>& output();
211 212
212 private: 213 private:
213 // The browser will write the PP_Vars into this array. 214 // The browser will write the PP_Vars into this array.
(...skipping 16 matching lines...) Expand all
230 // ppb_foo->GetFiles(adapter.pp_output_array()); 231 // ppb_foo->GetFiles(adapter.pp_output_array());
231 // std::vector<FileRef> result = adapter.output(). 232 // std::vector<FileRef> result = adapter.output().
232 template<typename T> 233 template<typename T>
233 class ResourceArrayOutputAdapterWithStorage 234 class ResourceArrayOutputAdapterWithStorage
234 : public ArrayOutputAdapter<PP_Resource> { 235 : public ArrayOutputAdapter<PP_Resource> {
235 public: 236 public:
236 ResourceArrayOutputAdapterWithStorage() { 237 ResourceArrayOutputAdapterWithStorage() {
237 set_output(&temp_storage_); 238 set_output(&temp_storage_);
238 } 239 }
239 240
241 virtual ~ResourceArrayOutputAdapterWithStorage() {
242 if (!temp_storage_.empty()) {
243 // An easy way to release the resource references held by this object.
244 output();
245 }
246 }
247
240 // Returns the final array of resource objects, converting the PP_Resources 248 // Returns the final array of resource objects, converting the PP_Resources
241 // written by the browser to resource objects. 249 // written by the browser to resource objects.
242 // 250 //
243 // This function should only be called once or we would end up converting 251 // This function should only be called once or we would end up converting
244 // the array more than once, which would mess up the refcounting. 252 // the array more than once, which would mess up the refcounting.
245 std::vector<T>& output() { 253 std::vector<T>& output() {
246 PP_DCHECK(output_storage_.empty()); 254 PP_DCHECK(output_storage_.empty());
247 255
248 ConvertPPResourceArrayToObjects(PASS_REF, temp_storage_, &output_storage_); 256 ConvertPPResourceArrayToObjects(PASS_REF, temp_storage_, &output_storage_);
249 temp_storage_.clear(); 257 temp_storage_.clear();
250 return output_storage_; 258 return output_storage_;
251 } 259 }
252 260
253 private: 261 private:
254 // The browser will write the PP_Resources into this array. 262 // The browser will write the PP_Resources into this array.
255 std::vector<PP_Resource> temp_storage_; 263 std::vector<PP_Resource> temp_storage_;
256 264
257 // When asked for the output, the resources above will be converted to the 265 // When asked for the output, the resources above will be converted to the
258 // C++ resource objects in this array for passing to the calling code. 266 // C++ resource objects in this array for passing to the calling code.
259 std::vector<T> output_storage_; 267 std::vector<T> output_storage_;
260 }; 268 };
261 269
262 } // namespace pp 270 } // namespace pp
263 271
264 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_ 272 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_
OLDNEW
« no previous file with comments | « no previous file | ppapi/cpp/array_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698