| OLD | NEW |
| 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/dev/ppb_directory_reader_dev.h" | |
| 11 #include "ppapi/c/pp_array_output.h" | 10 #include "ppapi/c/pp_array_output.h" |
| 12 #include "ppapi/c/pp_resource.h" | 11 #include "ppapi/c/pp_resource.h" |
| 13 #include "ppapi/cpp/dev/directory_entry_dev.h" | 12 #include "ppapi/cpp/directory_entry.h" |
| 14 #include "ppapi/cpp/logging.h" | 13 #include "ppapi/cpp/logging.h" |
| 15 #include "ppapi/cpp/pass_ref.h" | 14 #include "ppapi/cpp/pass_ref.h" |
| 16 #include "ppapi/cpp/var.h" | 15 #include "ppapi/cpp/var.h" |
| 17 | 16 |
| 18 namespace pp { | 17 namespace pp { |
| 19 | 18 |
| 20 // Converts the given array of PP_Resources into an array of the requested | 19 // Converts the given array of PP_Resources into an array of the requested |
| 21 // C++ resource types, passing ownership of a reference in the process. | 20 // C++ resource types, passing ownership of a reference in the process. |
| 22 // | 21 // |
| 23 // This is used to convert output arrays of resources that the browser has | 22 // This is used to convert output arrays of resources that the browser has |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 private: | 262 private: |
| 264 // The browser will write the PP_Resources into this array. | 263 // The browser will write the PP_Resources into this array. |
| 265 std::vector<PP_Resource> temp_storage_; | 264 std::vector<PP_Resource> temp_storage_; |
| 266 | 265 |
| 267 // When asked for the output, the resources above will be converted to the | 266 // When asked for the output, the resources above will be converted to the |
| 268 // C++ resource objects in this array for passing to the calling code. | 267 // C++ resource objects in this array for passing to the calling code. |
| 269 std::vector<T> output_storage_; | 268 std::vector<T> output_storage_; |
| 270 }; | 269 }; |
| 271 | 270 |
| 272 class DirectoryEntryArrayOutputAdapterWithStorage | 271 class DirectoryEntryArrayOutputAdapterWithStorage |
| 273 : public ArrayOutputAdapter<PP_DirectoryEntry_Dev> { | 272 : public ArrayOutputAdapter<PP_DirectoryEntry> { |
| 274 public: | 273 public: |
| 275 DirectoryEntryArrayOutputAdapterWithStorage() { | 274 DirectoryEntryArrayOutputAdapterWithStorage() { |
| 276 set_output(&temp_storage_); | 275 set_output(&temp_storage_); |
| 277 }; | 276 }; |
| 278 | 277 |
| 279 virtual ~DirectoryEntryArrayOutputAdapterWithStorage() { | 278 virtual ~DirectoryEntryArrayOutputAdapterWithStorage() { |
| 280 if (!temp_storage_.empty()) { | 279 if (!temp_storage_.empty()) { |
| 281 // An easy way to release the resource references held by |temp_storage_|. | 280 // An easy way to release the resource references held by |temp_storage_|. |
| 282 // A destructor for PP_DirectoryEntry_Dev will release them. | 281 // A destructor for PP_DirectoryEntry will release them. |
| 283 output(); | 282 output(); |
| 284 } | 283 } |
| 285 }; | 284 }; |
| 286 | 285 |
| 287 // Returns the final array of resource objects, converting the | 286 // Returns the final array of resource objects, converting the |
| 288 // PP_DirectoryEntry_Dev written by the browser to pp::DirectoryEntry_Dev | 287 // PP_DirectoryEntry written by the browser to pp::DirectoryEntry |
| 289 // objects. | 288 // objects. |
| 290 // | 289 // |
| 291 // This function should only be called once or we would end up converting | 290 // This function should only be called once or we would end up converting |
| 292 // the array more than once, which would mess up the refcounting. | 291 // the array more than once, which would mess up the refcounting. |
| 293 std::vector<pp::DirectoryEntry_Dev>& output() { | 292 std::vector<pp::DirectoryEntry>& output() { |
| 294 PP_DCHECK(output_storage_.empty()); | 293 PP_DCHECK(output_storage_.empty()); |
| 295 typedef std::vector<PP_DirectoryEntry_Dev> Entries; | 294 typedef std::vector<PP_DirectoryEntry> Entries; |
| 296 for (Entries::iterator it = temp_storage_.begin(); | 295 for (Entries::iterator it = temp_storage_.begin(); |
| 297 it != temp_storage_.end(); ++it) | 296 it != temp_storage_.end(); ++it) |
| 298 output_storage_.push_back(DirectoryEntry_Dev(PASS_REF, *it)); | 297 output_storage_.push_back(DirectoryEntry(PASS_REF, *it)); |
| 299 temp_storage_.clear(); | 298 temp_storage_.clear(); |
| 300 return output_storage_; | 299 return output_storage_; |
| 301 } | 300 } |
| 302 | 301 |
| 303 private: | 302 private: |
| 304 // The browser will write the PP_DirectoryEntry_Devs into this array. | 303 // The browser will write the PP_DirectoryEntrys into this array. |
| 305 std::vector<PP_DirectoryEntry_Dev> temp_storage_; | 304 std::vector<PP_DirectoryEntry> temp_storage_; |
| 306 | 305 |
| 307 // When asked for the output, the PP_DirectoryEntry_Devs above will be | 306 // When asked for the output, the PP_DirectoryEntrys above will be |
| 308 // converted to the pp::DirectoryEntry_Devs in this array for passing to the | 307 // converted to the pp::DirectoryEntrys in this array for passing to the |
| 309 // calling code. | 308 // calling code. |
| 310 std::vector<pp::DirectoryEntry_Dev> output_storage_; | 309 std::vector<pp::DirectoryEntry> output_storage_; |
| 311 }; | 310 }; |
| 312 | 311 |
| 313 } // namespace pp | 312 } // namespace pp |
| 314 | 313 |
| 315 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_ | 314 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_ |
| OLD | NEW |