| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 #ifndef PPAPI_CPP_DEV_DIRECTORY_ENTRY_DEV_H_ | |
| 6 #define PPAPI_CPP_DEV_DIRECTORY_ENTRY_DEV_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "ppapi/c/dev/ppb_directory_reader_dev.h" | |
| 11 #include "ppapi/c/pp_array_output.h" | |
| 12 #include "ppapi/cpp/array_output.h" | |
| 13 #include "ppapi/cpp/file_ref.h" | |
| 14 #include "ppapi/cpp/pass_ref.h" | |
| 15 #include "ppapi/cpp/output_traits.h" | |
| 16 | |
| 17 namespace pp { | |
| 18 | |
| 19 class DirectoryEntry_Dev { | |
| 20 public: | |
| 21 DirectoryEntry_Dev(); | |
| 22 DirectoryEntry_Dev(PassRef, const PP_DirectoryEntry_Dev& data); | |
| 23 DirectoryEntry_Dev(const DirectoryEntry_Dev& other); | |
| 24 | |
| 25 ~DirectoryEntry_Dev(); | |
| 26 | |
| 27 DirectoryEntry_Dev& operator=(const DirectoryEntry_Dev& other); | |
| 28 | |
| 29 // Returns true if the DirectoryEntry is invalid or uninitialized. | |
| 30 bool is_null() const { return !data_.file_ref; } | |
| 31 | |
| 32 // Returns the FileRef held by this DirectoryEntry. | |
| 33 FileRef file_ref() const { return FileRef(data_.file_ref); } | |
| 34 | |
| 35 // Returns the type of the file referenced by this DirectoryEntry. | |
| 36 PP_FileType file_type() const { return data_.file_type; } | |
| 37 | |
| 38 private: | |
| 39 PP_DirectoryEntry_Dev data_; | |
| 40 }; | |
| 41 | |
| 42 namespace internal { | |
| 43 | |
| 44 class DirectoryEntryArrayOutputAdapterWithStorage | |
| 45 : public ArrayOutputAdapter<PP_DirectoryEntry_Dev> { | |
| 46 public: | |
| 47 DirectoryEntryArrayOutputAdapterWithStorage(); | |
| 48 virtual ~DirectoryEntryArrayOutputAdapterWithStorage(); | |
| 49 | |
| 50 // Returns the final array of resource objects, converting the | |
| 51 // PP_DirectoryEntry_Dev written by the browser to pp::DirectoryEntry_Dev | |
| 52 // objects. | |
| 53 // | |
| 54 // This function should only be called once or we would end up converting | |
| 55 // the array more than once, which would mess up the refcounting. | |
| 56 std::vector<DirectoryEntry_Dev>& output(); | |
| 57 | |
| 58 private: | |
| 59 // The browser will write the PP_DirectoryEntry_Devs into this array. | |
| 60 std::vector<PP_DirectoryEntry_Dev> temp_storage_; | |
| 61 | |
| 62 // When asked for the output, the PP_DirectoryEntry_Devs above will be | |
| 63 // converted to the pp::DirectoryEntry_Devs in this array for passing to the | |
| 64 // calling code. | |
| 65 std::vector<DirectoryEntry_Dev> output_storage_; | |
| 66 }; | |
| 67 | |
| 68 // A specialization of CallbackOutputTraits to provide the callback system the | |
| 69 // information on how to handle vectors of pp::DirectoryEntry_Dev. This converts | |
| 70 // PP_DirectoryEntry_Dev to pp::DirectoryEntry_Dev when passing to the plugin. | |
| 71 template <> | |
| 72 struct CallbackOutputTraits< std::vector<DirectoryEntry_Dev> > { | |
| 73 typedef PP_ArrayOutput APIArgType; | |
| 74 typedef DirectoryEntryArrayOutputAdapterWithStorage StorageType; | |
| 75 | |
| 76 static inline APIArgType StorageToAPIArg(StorageType& t) { | |
| 77 return t.pp_array_output(); | |
| 78 } | |
| 79 | |
| 80 static inline std::vector<DirectoryEntry_Dev>& StorageToPluginArg( | |
| 81 StorageType& t) { | |
| 82 return t.output(); | |
| 83 } | |
| 84 }; | |
| 85 | |
| 86 } // namespace internal | |
| 87 } // namespace pp | |
| 88 | |
| 89 #endif // PPAPI_CPP_DEV_DIRECTORY_ENTRY_DEV_H_ | |
| OLD | NEW |